diff --git a/lib/setup.php b/lib/setup.php
index <HASH>..<HASH> 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -36,6 +36,7 @@
  *  - $CFG->dataroot - Path to moodle data files directory on server's filesystem.
  *  - $CFG->dirroot  - Path to moodle's library folder on server's filesystem.
  *  - $CFG->libdir   - Path to moodle's library folder on server's filesystem.
+ *  - $CFG->tempdir  - Path to moodle's temp file directory on server's filesystem.
  *
  * @global object $CFG
  * @name $CFG
@@ -96,6 +97,11 @@ if (!isset($CFG->admin)) {   // Just in case it isn't defined in config.php
 // Set up some paths.
 $CFG->libdir = $CFG->dirroot .'/lib';
 
+// Allow overriding of tempdir but be backwards compatible with dataroot/temp
+if (!isset($CFG->tempdir)) {
+    $CFG->tempdir = "$CFG->dataroot/temp";
+}
+
 // The current directory in PHP version 4.3.0 and above isn't necessarily the
 // directory of the script when run from the command line. The require_once()
 // would fail, so we'll have to chdir()
MDL-<I> Added $CFG->tempdir setting