From 78664df0f790178eea85f62016270a1560e8cd25 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Wed, 9 Apr 2008 08:21:51 +0000 Subject: [PATCH] MDL-14129, create a new debug.php, and fix print_error() call --- admin/auth_config.php | 2 +- admin/block.php | 6 +++--- admin/blocks.php | 8 ++++---- admin/delete.php | 2 +- admin/filters.php | 8 ++++---- admin/index.php | 37 ++++++++++++++++--------------------- admin/langdoc.php | 6 +++--- lang/en_utf8/debug.php | 19 +++++++++++++++++++ lang/en_utf8/error.php | 5 +++++ 9 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 lang/en_utf8/debug.php diff --git a/admin/auth_config.php b/admin/auth_config.php index 3165e5fcc52..597305e9907 100644 --- a/admin/auth_config.php +++ b/admin/auth_config.php @@ -34,7 +34,7 @@ if ($frm = data_submitted() and confirm_sesskey()) { $plugin = "auth/$auth"; $name = $matches[1]; if (!set_config($name, $value, $plugin)) { - print_error("Problem saving config $name as $value for plugin $plugin"); + print_error("cannotsaveconfig", 'error', '', array($name, $value, $plugin)); } } } diff --git a/admin/block.php b/admin/block.php index ffe68d0d77b..ccc58915db3 100644 --- a/admin/block.php +++ b/admin/block.php @@ -9,14 +9,14 @@ $blockid = required_param('block', PARAM_INT); if(!$blockrecord = blocks_get_record($blockid)) { - print_error('This block does not exist'); + print_error('blockdoesnotexist', 'error'); } admin_externalpage_setup('blocksetting'.$blockrecord->name); $block = block_instance($blockrecord->name); if($block === false) { - print_error('Problem in instantiating block object'); + print_error('blockcannotinistantiate', 'error'); } // Define the data we're going to silently include in the instance config form here, @@ -34,7 +34,7 @@ print_error('confirmsesskeybad', 'error'); } if(!$block->has_config()) { - print_error('This block does not support global configuration'); + print_error('blockcannotconfig', 'error'); } $remove = array_keys($hiddendata); foreach($remove as $item) { diff --git a/admin/blocks.php b/admin/blocks.php index 05131c396ed..d585b9f9779 100644 --- a/admin/blocks.php +++ b/admin/blocks.php @@ -33,7 +33,7 @@ if (!empty($hide) && confirm_sesskey()) { if (!$block = get_record('block', 'id', $hide)) { - print_error("Block doesn't exist!"); + print_error('blockdoesnotexist', 'error'); } set_field('block', 'visible', '0', 'id', $block->id); // Hide block admin_get_root(true, false); // settings not required - only pages @@ -41,7 +41,7 @@ if (!empty($show) && confirm_sesskey() ) { if (!$block = get_record('block', 'id', $show)) { - print_error("Block doesn't exist!"); + print_error('blockdoesnotexist', 'error'); } set_field('block', 'visible', '1', 'id', $block->id); // Show block admin_get_root(true, false); // settings not required - only pages @@ -49,7 +49,7 @@ if (!empty($multiple) && confirm_sesskey()) { if (!$block = blocks_get_record($multiple)) { - print_error("Block doesn't exist!"); + print_error('blockdoesnotexist', 'error'); } $block->multiple = !$block->multiple; update_record('block', $block); @@ -61,7 +61,7 @@ print_heading($strmanageblocks); if (!$block = blocks_get_record($delete)) { - print_error("Block doesn't exist!"); + print_error('blockdoesnotexist', 'error'); } if (!block_is_compatible($block->name)) { diff --git a/admin/delete.php b/admin/delete.php index bc70d504813..afc7ea9933e 100644 --- a/admin/delete.php +++ b/admin/delete.php @@ -37,7 +37,7 @@ } if (!confirm_sesskey()) { - print_error('This script was called wrongly'); + print_error('wrongcall', 'error'); } /// OK, here goes ... diff --git a/admin/filters.php b/admin/filters.php index acfad110568..06ce1c88f59 100644 --- a/admin/filters.php +++ b/admin/filters.php @@ -52,8 +52,8 @@ case 'show': // check filterpath is valid - if (!array_key_exists($filterpath, $installedfilters)) { - print_error("Filter $filterpath is not currently installed", '', $url); + if (!array_key_exists($filterpath, $installedfilters)) + print_error('filternotinstalled', 'error', $url, $filterpath); } elseif (array_search($filterpath,$activefilters)) { // filterpath is already active - doubleclick?? } else { @@ -67,7 +67,7 @@ $key=array_search($filterpath, $activefilters); // check filterpath is valid if ($key===false) { - print_error("Filter $filterpath is not currently active", '', $url); + print_error("filternotactive", 'error', $url, $filterpath ); } elseif ($key>=(count($activefilters)-1)) { // cannot be moved any further down - doubleclick?? } else { @@ -82,7 +82,7 @@ $key=array_search($filterpath, $activefilters); // check filterpath is valid if ($key===false) { - print_error("Filter $filterpath is not currently active", '', $url); + print_error("filternotactive", 'error', $url, $filterpath ); } elseif ($key<1) { //cannot be moved any further up - doubleclick?? } else { diff --git a/admin/index.php b/admin/index.php index 4cea1b6b7cd..051d1d40daa 100644 --- a/admin/index.php +++ b/admin/index.php @@ -50,29 +50,29 @@ $documentationlink = 'Installation docs'; if (ini_get_bool('session.auto_start')) { - print_error("The PHP server variable 'session.auto_start' should be Off - $documentationlink"); + print_error('phpvaroff', 'debug', '', array('session.auto_start', $documentationlink)); } if (ini_get_bool('magic_quotes_runtime')) { - print_error("The PHP server variable 'magic_quotes_runtime' should be Off - $documentationlink"); + print_error('phpvaroff', 'debug', '', array('magic_quotes_runtime', $documentationlink)); } if (!ini_get_bool('file_uploads')) { - print_error("The PHP server variable 'file_uploads' is not turned On - $documentationlink"); + print_error('phpvaron', 'debug', '', array('file_uploads', $documentationlink)); } if (empty($CFG->prefix) && $CFG->dbfamily != 'mysql') { //Enforce prefixes for everybody but mysql - print_error('$CFG->prefix can\'t be empty for your target DB (' . $CFG->dbtype . ')'); + print_error('prefixcannotbeempty', 'debug', '', array($CFG->prefix, $CFG->dbtype)); } if ($CFG->dbfamily == 'oracle' && strlen($CFG->prefix) > 2) { //Max prefix length for Oracle is 2cc - print_error('$CFG->prefix maximum allowed length for Oracle DBs is 2cc.'); + print_error('prefixlimit', 'debug', '', $CFG->prefix); } /// Check that config.php has been edited if ($CFG->wwwroot == "http://example.com/moodle") { - print_error("Moodle has not been configured yet. You need to edit config.php first."); + print_error('configmoodle', 'debug'); } @@ -80,12 +80,7 @@ $dirroot = dirname(realpath("../index.php")); if (!empty($dirroot) and $dirroot != $CFG->dirroot) { - print_error("Please fix your settings in config.php: -

You have: -

\$CFG->dirroot = \"".addslashes($CFG->dirroot)."\"; -

but it should be: -

\$CFG->dirroot = \"".addslashes($dirroot)."\";", - "./"); + print_error('fixsetting', 'debug', '', array(addslashes($CFG->dirroot), addslashes($dirroot))); } /// Set some necessary variables during set-up to avoid PHP warnings later on this page @@ -104,7 +99,7 @@ } if (!$version or !$release) { - print_error('Main version.php was not readable or specified'); // without version, stop + print_error('withoutversion', 'debug'); // without version, stop } /// Check if the main tables have been installed yet or not. @@ -186,7 +181,7 @@ } else if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) { $status = modify_database("$CFG->libdir/db/$CFG->dbtype.sql"); //Old method } else { - print_error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle or install.xml is not present. See the lib/db directory."); + print_error('dbnotsupport', 'debug', '', $CFG->dbtype); } // all new installs are in unicode - keep for backwards compatibility and 1.8 upgrade checks @@ -223,7 +218,7 @@ notify($strdatabasesuccess, "green"); require_once $CFG->dirroot.'/mnet/lib.php'; } else { - print_error("Error: Main databases NOT set up successfully"); + print_error('dbnotsetup', 'debug'); } print_continue('index.php'); print_footer('none'); @@ -367,7 +362,7 @@ moodle_install_roles(); set_config('rolesactive', 1); } else if (!update_capabilities()) { - print_error('Had trouble upgrading the core capabilities for the Roles System'); + print_error('cannotupgradecapabilities', 'debug'); } // update core events events_update_definition(); @@ -383,7 +378,7 @@ print_footer('none'); exit; } else { - print_error('Upgrade failed! (Could not update version in config table)'); + print_error('cannotupdateversion', 'debug'); } /// Main upgrade not success } else { @@ -401,7 +396,7 @@ } } else { if (!set_config("version", $version)) { - print_error("A problem occurred inserting current version into databases"); + print_error('cannotupdateversion', 'debug'); } } @@ -409,7 +404,7 @@ if ($release <> $CFG->release) { // Update the release version if (!set_config("release", $release)) { - print_error("ERROR: Could not update release version in database!!"); + print_error("cannotupdaterelease", 'debug'); } } @@ -495,7 +490,7 @@ $newsite->timemodified = time(); if (!$newid = insert_record('course', $newsite)) { - print_error("Serious Error! Could not set up the site!"); + print_error('cannotsetupsite', 'error'); } // make sure course context exists get_context_instance(CONTEXT_COURSE, $newid); @@ -508,7 +503,7 @@ $cat->name = get_string('miscellaneous'); $cat->depth = 1; if (!$catid = insert_record('course_categories', $cat)) { - print_error("Serious Error! Could not set up a default course category!"); + print_error('cannotsetupcategory', 'error'); } // make sure category context exists get_context_instance(CONTEXT_COURSECAT, $catid); diff --git a/admin/langdoc.php b/admin/langdoc.php index b456ac1961a..a645ea8fb91 100755 --- a/admin/langdoc.php +++ b/admin/langdoc.php @@ -51,7 +51,7 @@ if (langdoc_save_file($langdir, $currentfile, $_POST['filedata'])) { notify(get_string("changessaved")." ($langdir/$currentfile)", "green"); } else { - print_error("Could not save the file '$currentfile'!", '', "langdoc.php?currentfile=$currentfile&sesskey=$USER->sesskey"); + print_error("cannotsavefile", 'error', "langdoc.php?currentfile=$currentfile&sesskey=$USER->sesskey", $currentfile); } } } @@ -63,7 +63,7 @@ // Get all files from /docs directory if (! $files = get_directory_list("$CFG->dirroot/lang/en_utf8/docs", "CVS")) { - print_error("Could not find English language docs files!"); + print_error('cannotfinddocs', 'error', '', 'English'); } $options = array(); @@ -83,7 +83,7 @@ // Get all files from /help directory if (! $files = get_directory_list("$CFG->dirroot/lang/en_utf8/help", "CVS")) { - print_error("Could not find English language help files!"); + print_error("cannotfindhelp", "error", "", "English"); } foreach ($files as $filekey => $file) { // check all the help files. diff --git a/lang/en_utf8/debug.php b/lang/en_utf8/debug.php new file mode 100644 index 00000000000..35ea066847a --- /dev/null +++ b/lang/en_utf8/debug.php @@ -0,0 +1,19 @@ +You have:

\$CFG->dirroot = \"$a[0]\";

but it should be:

\$CFG->dirroot = \"$a[1]\"

'; +$string['phpvaroff'] = 'The PHP server variable \'$a[0]\' should be Off - $a[1]'; +$string['phpvaron'] = 'The PHP server variable \'$a[0]\' is not turned On - $a[1]'; +$string['prefixcannotbeempty'] = 'Table prefix \"$a[0]\" cannot be empty for your target DB ($a[1])'; +$string['prefixlimit'] = 'Table prefix \"$a\" maximum allowed length for Oracle DBs is 2cc.'; +$string['withoutversion'] = 'Main version.php was not readable or specified'; + +?> diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index 280e756dedc..2a63508a2ac 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -22,6 +22,8 @@ $string['cannotfindhelp'] = 'Cannot find \"$a\" language help files'; $string['cannotsavefile'] = 'Cannot save the file \"$a\".'; $string['cannotsavemd5file'] = 'Cannot save md5 file.'; $string['cannotsavezipfile'] = 'Cannot save ZIP file.'; +$string['cannotsetupcategory'] = 'Serious Error! Could not set up a default course category!'; +$string['cannotsetupsite'] = 'Serious Error! Could not set up the site!'; $string['cannotunzipfile'] = 'Cannot unzip file.'; $string['cannotviewprofile'] = 'You can not view the profile of this user.'; $string['cantunenrollfrommetacourse'] = 'You can not unenrol from this meta course.'; @@ -47,6 +49,8 @@ $string['errorreadingfile'] = 'Error reading file \"$a\"'; $string['errorunzippingfiles'] = 'Error unzipping files'; $string['fieldrequired'] = '\"$a\" is a required field'; $string['filenotfound'] = 'Sorry, the requested file could not be found'; +$string['filternotinstalled'] = 'Filter $a is not currently installed'; +$string['filternotactive'] = 'Filter $a is not currently active'; $string['forumblockingtoomanyposts'] = 'You have exceeded the posting threshold set for this forum.'; $string['groupalready'] = 'User already belongs to group $a'; $string['groupexistforcourse'] = 'Group \"$a\" already exists for this course'; @@ -127,6 +131,7 @@ $string['usernotrenamedoff'] = 'User not renamed - renaming not allowed.'; $string['usernotupdatedadmin'] = 'Can not update admin accounts.'; $string['usernotupdatederror'] = 'User not updated - error.'; $string['usernotupdatednotexists'] = 'User not updated - does not exist.'; +$string['wrongcall'] = 'This script is called wrongly'; $string['wrongdestpath'] = 'Wrong destination path.'; $string['wrongsourcebase'] = 'Wrong source URL base.'; $string['wrongzipfilename'] = 'Wrong ZIP filename.';