From 73fa96d5d22cdb4b04e6c811d9adc6b4c3bbc923 Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 11 Jan 2009 16:42:19 +0000 Subject: [PATCH] MDL-17854 removed PHP4isms from adminlib and friends --- lib/adminlib.php | 691 +++++++++++++++++++++++------------------------ 1 file changed, 333 insertions(+), 358 deletions(-) diff --git a/lib/adminlib.php b/lib/adminlib.php index 78e351dd55..26fab9c256 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -1,4 +1,4 @@ -loadXMLStructure(); - $structure =& $xmldb_file->getStructure(); + $structure = $xmldb_file->getStructure(); if ($loaded and $tables = $structure->getTables()) { foreach($tables as $table) { @@ -1144,7 +1144,7 @@ function is_dataroot_insecure($fetchtest=false) { * @author Vincenzo K. Marcovecchio * @package admin */ -class part_of_admin_tree { +interface part_of_admin_tree { /** * Finds a named part_of_admin_tree. @@ -1161,10 +1161,7 @@ class part_of_admin_tree { * @param string $name The internal name of the part_of_admin_tree we're searching for. * @return mixed An object reference or a NULL reference. */ - function &locate($name) { - trigger_error('Admin class does not implement method locate()', E_USER_WARNING); - return; - } + public function locate($name); /** * Removes named part_of_admin_tree. @@ -1172,20 +1169,14 @@ class part_of_admin_tree { * @param string $name The internal name of the part_of_admin_tree we want to remove. * @return bool success. */ - function prune($name) { - trigger_error('Admin class does not implement method prune()', E_USER_WARNING); - return; - } + public function prune($name); /** * Search using query * @param strin query * @return mixed array-object structure of found settings and pages */ - function search($query) { - trigger_error('Admin class does not implement method search()', E_USER_WARNING); - return; - } + public function search($query); /** * Verifies current user's access to this part_of_admin_tree. @@ -1199,20 +1190,14 @@ class part_of_admin_tree { * * @return bool True if the user has access, false if she doesn't. */ - function check_access() { - trigger_error('Admin class does not implement method check_access()', E_USER_WARNING); - return; - } + public function check_access(); /** * Mostly usefull for removing of some parts of the tree in admin tree block. * * @return True is hidden from normal list view */ - function is_hidden() { - trigger_error('Admin class does not implement method is_hidden()', E_USER_WARNING); - return; - } + public function is_hidden(); } /** @@ -1226,7 +1211,7 @@ class part_of_admin_tree { * @author Vincenzo K. Marcovecchio * @package admin */ -class parentable_part_of_admin_tree extends part_of_admin_tree { +interface parentable_part_of_admin_tree extends part_of_admin_tree { /** * Adds a part_of_admin_tree object to the admin tree. @@ -1237,13 +1222,10 @@ class parentable_part_of_admin_tree extends part_of_admin_tree { * also parentable_part_of_admin_tree's. * * @param string $destinationname The internal name of the new parent for $something. - * @param part_of_admin_tree &$something The object to be added. + * @param part_of_admin_tree $something The object to be added. * @return bool True on success, false on failure. */ - function add($destinationname, $something) { - trigger_error('Admin class does not implement method add()', E_USER_WARNING); - return; - } + public function add($destinationname, $something); } @@ -1255,33 +1237,33 @@ class parentable_part_of_admin_tree extends part_of_admin_tree { * @author Vincenzo K. Marcovecchio * @package admin */ -class admin_category extends parentable_part_of_admin_tree { +class admin_category implements parentable_part_of_admin_tree { /** * @var mixed An array of part_of_admin_tree objects that are this object's children */ - var $children; + public $children; /** * @var string An internal name for this category. Must be unique amongst ALL part_of_admin_tree objects */ - var $name; + public $name; /** * @var string The displayed name for this category. Usually obtained through get_string() */ - var $visiblename; + public $visiblename; /** * @var bool Should this category be hidden in admin tree block? */ - var $hidden; + public $hidden; /** * paths */ - var $path; - var $visiblepath; + public $path; + public $visiblepath; /** * Constructor for an empty admin category @@ -1290,7 +1272,7 @@ class admin_category extends parentable_part_of_admin_tree { * @param string $visiblename The displayed named for this category. Usually obtained through get_string() * @param bool $hidden hide category in admin tree block */ - function admin_category($name, $visiblename, $hidden=false) { + public function __construct($name, $visiblename, $hidden=false) { $this->children = array(); $this->name = $name; $this->visiblename = $visiblename; @@ -1304,7 +1286,7 @@ class admin_category extends parentable_part_of_admin_tree { * @param bool $findpath initialize path and visiblepath arrays * @return mixed A reference to the object with internal name $name if found, otherwise a reference to NULL. */ - function &locate($name, $findpath=false) { + public function locate($name, $findpath=false) { if ($this->name == $name) { if ($findpath) { $this->visiblepath[] = $this->visiblename; @@ -1315,7 +1297,7 @@ class admin_category extends parentable_part_of_admin_tree { $return = NULL; foreach($this->children as $childid=>$unused) { - if ($return =& $this->children[$childid]->locate($name, $findpath)) { + if ($return = $this->children[$childid]->locate($name, $findpath)) { break; } } @@ -1333,7 +1315,7 @@ class admin_category extends parentable_part_of_admin_tree { * @param strin query * @return mixed array-object structure of found settings and pages */ - function search($query) { + public function search($query) { $result = array(); foreach ($this->children as $child) { $subsearch = $child->search($query); @@ -1352,7 +1334,7 @@ class admin_category extends parentable_part_of_admin_tree { * @param string $name The internal name of the object we want to remove. * @return bool success */ - function prune($name) { + public function prune($name) { if ($this->name == $name) { return false; //can not remove itself @@ -1378,15 +1360,15 @@ class admin_category extends parentable_part_of_admin_tree { * @param mixed $something A part_of_admin_tree or setting instanceto be added. * @return bool True if successfully added, false if $something can not be added. */ - function add($parentname, $something) { - $parent =& $this->locate($parentname); + public function add($parentname, $something) { + $parent = $this->locate($parentname); if (is_null($parent)) { debugging('parent does not exist!'); return false; } - if (is_a($something, 'part_of_admin_tree')) { - if (!is_a($parent, 'parentable_part_of_admin_tree')) { + if ($something instanceof part_of_admin_tree) { + if (!($parent instanceof parentable_part_of_admin_tree)) { debugging('error - parts of tree can be inserted only into parentable parts'); return false; } @@ -1405,7 +1387,7 @@ class admin_category extends parentable_part_of_admin_tree { * * @return bool True if the user has access to atleast one child in this category, false otherwise. */ - function check_access() { + public function check_access() { foreach ($this->children as $child) { if ($child->check_access()) { return true; @@ -1419,7 +1401,7 @@ class admin_category extends parentable_part_of_admin_tree { * * @return bool True if hidden */ - function is_hidden() { + public function is_hidden() { return $this->hidden; } } @@ -1428,24 +1410,32 @@ class admin_root extends admin_category { /** * list of errors */ - var $errors; + public $errors; /** * search query */ - var $search; + public $search; /** * full tree flag - true means all settings required, false onlypages required */ - var $fulltree; + public $fulltree; + public $loaded; - function admin_root() { - parent::admin_category('root', get_string('administration'), false); + public function __construct($fulltree) { + parent::__construct('root', get_string('administration'), false); $this->errors = array(); $this->search = ''; - $this->fulltree = true; + $this->fulltree = $fulltree; + $this->loaded = false; + } + + public function purge_children($requirefulltree) { + $this->children = array(); + $this->fulltree = ($requirefulltree || $this->fulltree); + $this->loaded = false; } } @@ -1457,43 +1447,43 @@ class admin_root extends admin_category { * @author Vincenzo K. Marcovecchio * @package admin */ -class admin_externalpage extends part_of_admin_tree { +class admin_externalpage implements part_of_admin_tree { /** * @var string An internal name for this external page. Must be unique amongst ALL part_of_admin_tree objects */ - var $name; + public $name; /** * @var string The displayed name for this external page. Usually obtained through get_string(). */ - var $visiblename; + public $visiblename; /** * @var string The external URL that we should link to when someone requests this external page. */ - var $url; + public $url; /** * @var string The role capability/permission a user must have to access this external page. */ - var $req_capability; + public $req_capability; /** * @var object The context in which capability/permission should be checked, default is site context. */ - var $context; + public $context; /** * @var bool hidden in admin tree block. */ - var $hidden; + public $hidden; /** * visible path */ - var $path; - var $visiblepath; + public $path; + public $visiblepath; /** * Constructor for adding an external page into the admin tree. @@ -1506,7 +1496,7 @@ class admin_externalpage extends part_of_admin_tree { * @param context $context The context the page relates to. Not sure what happens * if you specify something other than system or front page. Defaults to system. */ - function admin_externalpage($name, $visiblename, $url, $req_capability='moodle/site:config', $hidden=false, $context=NULL) { + public function __construct($name, $visiblename, $url, $req_capability='moodle/site:config', $hidden=false, $context=NULL) { $this->name = $name; $this->visiblename = $visiblename; $this->url = $url; @@ -1525,7 +1515,7 @@ class admin_externalpage extends part_of_admin_tree { * @param string $name The internal name of the object we want. * @return mixed A reference to the object with internal name $name if found, otherwise a reference to NULL. */ - function &locate($name, $findpath=false) { + public function locate($name, $findpath=false) { if ($this->name == $name) { if ($findpath) { $this->visiblepath = array($this->visiblename); @@ -1538,7 +1528,7 @@ class admin_externalpage extends part_of_admin_tree { } } - function prune($name) { + public function prune($name) { return false; } @@ -1547,7 +1537,7 @@ class admin_externalpage extends part_of_admin_tree { * @param strin query * @return mixed array-object structure of found settings and pages */ - function search($query) { + public function search($query) { $textlib = textlib_get_instance(); $found = false; @@ -1570,7 +1560,7 @@ class admin_externalpage extends part_of_admin_tree { * Determines if the current user has access to this external page based on $this->req_capability. * @return bool True if user has access, false otherwise. */ - function check_access() { + public function check_access() { global $CFG; if (empty($CFG->rolesactive)) { return true; // no access check before site is fully set up @@ -1589,7 +1579,7 @@ class admin_externalpage extends part_of_admin_tree { * * @return bool True if hidden */ - function is_hidden() { + public function is_hidden() { return $this->hidden; } @@ -1601,45 +1591,45 @@ class admin_externalpage extends part_of_admin_tree { * @author Vincenzo K. Marcovecchio * @package admin */ -class admin_settingpage extends part_of_admin_tree { +class admin_settingpage implements part_of_admin_tree { /** * @var string An internal name for this external page. Must be unique amongst ALL part_of_admin_tree objects */ - var $name; + public $name; /** * @var string The displayed name for this external page. Usually obtained through get_string(). */ - var $visiblename; + public $visiblename; /** * @var mixed An array of admin_setting objects that are part of this setting page. */ - var $settings; + public $settings; /** * @var string The role capability/permission a user must have to access this external page. */ - var $req_capability; + public $req_capability; /** * @var object The context in which capability/permission should be checked, default is site context. */ - var $context; + public $context; /** * @var bool hidden in admin tree block. */ - var $hidden; + public $hidden; /** * paths */ - var $path; - var $visiblepath; + public $path; + public $visiblepath; // see admin_externalpage - function admin_settingpage($name, $visiblename, $req_capability='moodle/site:config', $hidden=false, $context=NULL) { + public function __construct($name, $visiblename, $req_capability='moodle/site:config', $hidden=false, $context=NULL) { $this->settings = new object(); $this->name = $name; $this->visiblename = $visiblename; @@ -1653,7 +1643,7 @@ class admin_settingpage extends part_of_admin_tree { } // see admin_category - function &locate($name, $findpath=false) { + public function locate($name, $findpath=false) { if ($this->name == $name) { if ($findpath) { $this->visiblepath = array($this->visiblename); @@ -1666,7 +1656,7 @@ class admin_settingpage extends part_of_admin_tree { } } - function search($query) { + public function search($query) { $found = array(); foreach ($this->settings as $setting) { @@ -1700,7 +1690,7 @@ class admin_settingpage extends part_of_admin_tree { } } - function prune($name) { + public function prune($name) { return false; } @@ -1710,8 +1700,8 @@ class admin_settingpage extends part_of_admin_tree { * @param object $setting is the admin_setting object you want to add * @return true if successful, false if not */ - function add($setting) { - if (!is_a($setting, 'admin_setting')) { + public function add($setting) { + if (!($setting instanceof admin_setting)) { debugging('error - not a setting instance'); return false; } @@ -1721,7 +1711,7 @@ class admin_settingpage extends part_of_admin_tree { } // see admin_externalpage - function check_access() { + public function check_access() { global $CFG; if (empty($CFG->rolesactive)) { return true; // no access check before site is fully set up @@ -1739,8 +1729,8 @@ class admin_settingpage extends part_of_admin_tree { * outputs this page as html in a table (suitable for inclusion in an admin pagetype) * returns a string of the html */ - function output_html() { - $adminroot =& admin_get_root(); + public function output_html() { + $adminroot = admin_get_root(); $return = '
'."\n".'
'."\n"; foreach($this->settings as $setting) { $fullname = $setting->get_full_name(); @@ -1761,7 +1751,7 @@ class admin_settingpage extends part_of_admin_tree { * * @return bool True if hidden */ - function is_hidden() { + public function is_hidden() { return $this->hidden; } @@ -1774,12 +1764,12 @@ class admin_settingpage extends part_of_admin_tree { */ class admin_setting { - var $name; - var $visiblename; - var $description; - var $defaultsetting; - var $updatedcallback; - var $plugin; // null means main config table + public $name; + public $visiblename; + public $description; + public $defaultsetting; + public $updatedcallback; + public $plugin; // null means main config table /** * Constructor @@ -1788,7 +1778,7 @@ class admin_setting { * @param string $description localised long description * @param mixed $defaultsetting string or array depending on implementation */ - function admin_setting($name, $visiblename, $description, $defaultsetting) { + public function __construct($name, $visiblename, $description, $defaultsetting) { $this->parse_setting_name($name); $this->visiblename = $visiblename; $this->description = $description; @@ -1820,15 +1810,15 @@ class admin_setting { } } - function get_full_name() { + public function get_full_name() { return 's_'.$this->plugin.'_'.$this->name; } - function get_id() { + public function get_id() { return 'id_s_'.$this->plugin.'_'.$this->name; } - function config_read($name) { + public function config_read($name) { global $CFG; if (!empty($this->plugin)) { $value = get_config($this->plugin, $name); @@ -1843,7 +1833,7 @@ class admin_setting { } } - function config_write($name, $value) { + public function config_write($name, $value) { return (boolean)set_config($name, $value, $this->plugin); } @@ -1851,7 +1841,7 @@ class admin_setting { * Returns current value of this setting * @return mixed array or string depending on instance, NULL means not set yet */ - function get_setting() { + public function get_setting() { // has to be overridden return NULL; } @@ -1860,7 +1850,7 @@ class admin_setting { * Returns default setting if exists * @return mixed array or string depending on instance; NULL means no default, user must supply */ - function get_defaultsetting() { + public function get_defaultsetting() { return $this->defaultsetting; } @@ -1869,7 +1859,7 @@ class admin_setting { * @param mixed string or array, must not be NULL * @return '' if ok, string error message otherwise */ - function write_setting($data) { + public function write_setting($data) { // should be overridden return ''; } @@ -1879,7 +1869,7 @@ class admin_setting { * @param mixed data array or string depending on setting * @return string */ - function output_html($data, $query='') { + public function output_html($data, $query='') { // should be overridden return; } @@ -1887,7 +1877,7 @@ class admin_setting { /** * function called if setting updated - cleanup, cache reset, etc. */ - function set_updatedcallback($functionname) { + public function set_updatedcallback($functionname) { $this->updatedcallback = $functionname; } @@ -1896,7 +1886,7 @@ class admin_setting { * @param string $query * @return bool */ - function is_related($query) { + public function is_related($query) { if (strpos(strtolower($this->name), $query) !== false) { return true; } @@ -1937,24 +1927,24 @@ class admin_setting_heading extends admin_setting { * @param string $heading heading * @param string $information text in box */ - function admin_setting_heading($name, $heading, $information) { - parent::admin_setting($name, $heading, $information, ''); + public function __construct($name, $heading, $information) { + parent::__construct($name, $heading, $information, ''); } - function get_setting() { + public function get_setting() { return true; } - function get_defaultsetting() { + public function get_defaultsetting() { return true; } - function write_setting($data) { + public function write_setting($data) { // do not write any setting return ''; } - function output_html($data, $query='') { + public function output_html($data, $query='') { $return = ''; if ($this->visiblename != '') { $return .= print_heading(''.highlightfast($query, $this->visiblename).'', '', 3, 'main', true); @@ -1971,8 +1961,8 @@ class admin_setting_heading extends admin_setting { */ class admin_setting_configtext extends admin_setting { - var $paramtype; - var $size; + public $paramtype; + public $size; /** * config text contructor @@ -1983,21 +1973,21 @@ class admin_setting_configtext extends admin_setting { * @param mixed $paramtype int means PARAM_XXX type, string is a allowed format in regex * @param int $size default field size */ - function admin_setting_configtext($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $size=null) { + public function __construct($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $size=null) { $this->paramtype = $paramtype; if (!is_null($size)) { $this->size = $size; } else { $this->size = ($paramtype == PARAM_INT) ? 5 : 30; } - parent::admin_setting($name, $visiblename, $description, $defaultsetting); + parent::__construct($name, $visiblename, $description, $defaultsetting); } - function get_setting() { + public function get_setting() { return $this->config_read($this->name); } - function write_setting($data) { + public function write_setting($data) { if ($this->paramtype === PARAM_INT and $data === '') { // do not complain if '' used instead of 0 $data = 0; @@ -2015,7 +2005,7 @@ class admin_setting_configtext extends admin_setting { * @param string data * @return mixed true if ok string if error found */ - function validate($data) { + public function validate($data) { if (is_string($this->paramtype)) { if (preg_match($this->paramtype, $data)) { return true; @@ -2036,7 +2026,7 @@ class admin_setting_configtext extends admin_setting { } } - function output_html($data, $query='') { + public function output_html($data, $query='') { $default = $this->get_defaultsetting(); return format_admin_setting($this, $this->visiblename, @@ -2049,16 +2039,16 @@ class admin_setting_configtext extends admin_setting { * General text area without html editor. */ class admin_setting_configtextarea extends admin_setting_configtext { - var $rows; - var $cols; + public $rows; + public $cols; - function admin_setting_configtextarea($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $cols='60', $rows='8') { + public function __construct($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW, $cols='60', $rows='8') { $this->rows = $rows; $this->cols = $cols; - parent::admin_setting_configtext($name, $visiblename, $description, $defaultsetting, $paramtype); + parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype); } - function output_html($data, $query='') { + public function output_html($data, $query='') { $default = $this->get_defaultsetting(); $defaultinfo = $default; @@ -2083,11 +2073,11 @@ class admin_setting_configpasswordunmask extends admin_setting_configtext { * @param string $description long localised info * @param string $defaultsetting default password */ - function admin_setting_configpasswordunmask($name, $visiblename, $description, $defaultsetting) { - parent::admin_setting_configtext($name, $visiblename, $description, $defaultsetting, PARAM_RAW, 30); + public function __construct($name, $visiblename, $description, $defaultsetting) { + parent::__construct($name, $visiblename, $description, $defaultsetting, PARAM_RAW, 30); } - function output_html($data, $query='') { + public function output_html($data, $query='') { $id = $this->get_id(); $unmask = get_string('unmaskpassword', 'form'); $unmaskjs = '