Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Load all plugins into the admin tree.
  19   *
  20  * Please note that is file is always loaded last - it means that you can inject entries into other categories too.
  21  *
  22  * @package    core
  23  * @copyright  2007 Petr Skoda {@link http://skodak.org}
  24  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25  */
  26  
  27  if ($hassiteconfig) {
  28      /* @var admin_root $ADMIN */
  29      $ADMIN->locate('modules')->set_sorting(true);
  30  
  31      $ADMIN->add('modules', new admin_page_pluginsoverview());
  32  
  33      // activity modules
  34      $ADMIN->add('modules', new admin_category('modsettings', new lang_string('activitymodules')));
  35  
  36      $ADMIN->add('modsettings', new admin_page_managemods());
  37  
  38      $temp = new admin_settingpage('managemodulescommon', new lang_string('commonactivitysettings', 'admin'));
  39      $temp->add(new admin_setting_configcheckbox('requiremodintro',
  40          get_string('requiremodintro', 'admin'), get_string('requiremodintro_desc', 'admin'), 0));
  41      $ADMIN->add('modsettings', $temp);
  42  
  43      $plugins = core_plugin_manager::instance()->get_plugins_of_type('mod');
  44      core_collator::asort_objects_by_property($plugins, 'displayname');
  45      foreach ($plugins as $plugin) {
  46          /** @var \core\plugininfo\mod $plugin */
  47          $plugin->load_settings($ADMIN, 'modsettings', $hassiteconfig);
  48      }
  49  
  50      // course formats
  51      $ADMIN->add('modules', new admin_category('formatsettings', new lang_string('courseformats')));
  52      $temp = new admin_settingpage('manageformats', new lang_string('manageformats', 'core_admin'));
  53      $temp->add(new admin_setting_manageformats());
  54      $ADMIN->add('formatsettings', $temp);
  55      $plugins = core_plugin_manager::instance()->get_plugins_of_type('format');
  56      core_collator::asort_objects_by_property($plugins, 'displayname');
  57      foreach ($plugins as $plugin) {
  58          /** @var \core\plugininfo\format $plugin */
  59          $plugin->load_settings($ADMIN, 'formatsettings', $hassiteconfig);
  60      }
  61  
  62      // Custom fields.
  63      $ADMIN->add('modules', new admin_category('customfieldsettings', new lang_string('customfields', 'core_customfield')));
  64      $temp = new admin_settingpage('managecustomfields', new lang_string('managecustomfields', 'core_admin'));
  65      $temp->add(new admin_setting_managecustomfields());
  66      $ADMIN->add('customfieldsettings', $temp);
  67      $plugins = core_plugin_manager::instance()->get_plugins_of_type('customfield');
  68      core_collator::asort_objects_by_property($plugins, 'displayname');
  69      foreach ($plugins as $plugin) {
  70          /** @var \core\plugininfo\customfield $plugin */
  71          $plugin->load_settings($ADMIN, 'customfieldsettings', $hassiteconfig);
  72      }
  73  
  74      // blocks
  75      $ADMIN->add('modules', new admin_category('blocksettings', new lang_string('blocks')));
  76      $ADMIN->add('blocksettings', new admin_page_manageblocks());
  77      $plugins = core_plugin_manager::instance()->get_plugins_of_type('block');
  78      core_collator::asort_objects_by_property($plugins, 'displayname');
  79      foreach ($plugins as $plugin) {
  80          /** @var \core\plugininfo\block $plugin */
  81          $plugin->load_settings($ADMIN, 'blocksettings', $hassiteconfig);
  82      }
  83  
  84      // authentication plugins
  85      $ADMIN->add('modules', new admin_category('authsettings', new lang_string('authentication', 'admin')));
  86  
  87      $temp = new admin_settingpage('manageauths', new lang_string('authsettings', 'admin'));
  88      $temp->add(new admin_setting_manageauths());
  89      $temp->add(new admin_setting_heading('manageauthscommonheading', new lang_string('commonsettings', 'admin'), ''));
  90      $temp->add(new admin_setting_special_registerauth());
  91      $temp->add(new admin_setting_configcheckbox('authloginviaemail', new lang_string('authloginviaemail', 'core_auth'), new lang_string('authloginviaemail_desc', 'core_auth'), 0));
  92      $temp->add(new admin_setting_configcheckbox('allowaccountssameemail',
  93                      new lang_string('allowaccountssameemail', 'core_auth'),
  94                      new lang_string('allowaccountssameemail_desc', 'core_auth'), 0));
  95      $temp->add(new admin_setting_configcheckbox('authpreventaccountcreation', new lang_string('authpreventaccountcreation', 'admin'), new lang_string('authpreventaccountcreation_help', 'admin'), 0));
  96      $temp->add(new admin_setting_configcheckbox('loginpageautofocus', new lang_string('loginpageautofocus', 'admin'), new lang_string('loginpageautofocus_help', 'admin'), 0));
  97      $temp->add(new admin_setting_configselect('guestloginbutton', new lang_string('guestloginbutton', 'auth'),
  98                                                new lang_string('showguestlogin', 'auth'), '1', array('0'=>new lang_string('hide'), '1'=>new lang_string('show'))));
  99      $options = array(0 => get_string('no'), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 10 => 10, 20 => 20, 50 => 50);
 100      $temp->add(new admin_setting_configselect('limitconcurrentlogins',
 101          new lang_string('limitconcurrentlogins', 'core_auth'),
 102          new lang_string('limitconcurrentlogins_desc', 'core_auth'), 0, $options));
 103      $temp->add(new admin_setting_configtext('alternateloginurl', new lang_string('alternateloginurl', 'auth'),
 104                                              new lang_string('alternatelogin', 'auth', htmlspecialchars(get_login_url(), ENT_COMPAT)), ''));
 105      $temp->add(new admin_setting_configtext('forgottenpasswordurl', new lang_string('forgottenpasswordurl', 'auth'),
 106                                              new lang_string('forgottenpassword', 'auth'), '', PARAM_URL));
 107      $temp->add(new admin_setting_confightmleditor('auth_instructions', new lang_string('instructions', 'auth'),
 108                                                  new lang_string('authinstructions', 'auth'), ''));
 109      $setting = new admin_setting_configtext('allowemailaddresses', new lang_string('allowemailaddresses', 'admin'),
 110          new lang_string('configallowemailaddresses', 'admin'), '', PARAM_NOTAGS);
 111      $setting->set_force_ltr(true);
 112      $temp->add($setting);
 113      $setting = new admin_setting_configtext('denyemailaddresses', new lang_string('denyemailaddresses', 'admin'),
 114          new lang_string('configdenyemailaddresses', 'admin'), '', PARAM_NOTAGS);
 115      $setting->set_force_ltr(true);
 116      $temp->add($setting);
 117      $temp->add(new admin_setting_configcheckbox('verifychangedemail', new lang_string('verifychangedemail', 'admin'), new lang_string('configverifychangedemail', 'admin'), 1));
 118  
 119      $setting = new admin_setting_configtext('recaptchapublickey', new lang_string('recaptchapublickey', 'admin'), new lang_string('configrecaptchapublickey', 'admin'), '', PARAM_NOTAGS);
 120      $setting->set_force_ltr(true);
 121      $temp->add($setting);
 122      $setting = new admin_setting_configtext('recaptchaprivatekey', new lang_string('recaptchaprivatekey', 'admin'), new lang_string('configrecaptchaprivatekey', 'admin'), '', PARAM_NOTAGS);
 123      $setting->set_force_ltr(true);
 124      $temp->add($setting);
 125      $ADMIN->add('authsettings', $temp);
 126  
 127      $temp = new admin_externalpage('authtestsettings', get_string('testsettings', 'core_auth'), new moodle_url("/auth/test_settings.php"), 'moodle/site:config', true);
 128      $ADMIN->add('authsettings', $temp);
 129  
 130      $plugins = core_plugin_manager::instance()->get_plugins_of_type('auth');
 131      core_collator::asort_objects_by_property($plugins, 'displayname');
 132      foreach ($plugins as $plugin) {
 133          /** @var \core\plugininfo\auth $plugin */
 134          $plugin->load_settings($ADMIN, 'authsettings', $hassiteconfig);
 135      }
 136  
 137      // Enrolment plugins
 138      $ADMIN->add('modules', new admin_category('enrolments', new lang_string('enrolments', 'enrol')));
 139      $temp = new admin_settingpage('manageenrols', new lang_string('manageenrols', 'enrol'));
 140      $temp->add(new admin_setting_manageenrols());
 141      $ADMIN->add('enrolments', $temp);
 142  
 143      $temp = new admin_externalpage('enroltestsettings', get_string('testsettings', 'core_enrol'), new moodle_url("/enrol/test_settings.php"), 'moodle/site:config', true);
 144      $ADMIN->add('enrolments', $temp);
 145  
 146      $plugins = core_plugin_manager::instance()->get_plugins_of_type('enrol');
 147      core_collator::asort_objects_by_property($plugins, 'displayname');
 148      foreach ($plugins as $plugin) {
 149          /** @var \core\plugininfo\enrol $plugin */
 150          $plugin->load_settings($ADMIN, 'enrolments', $hassiteconfig);
 151      }
 152  
 153  
 154  /// Editor plugins
 155      $ADMIN->add('modules', new admin_category('editorsettings', new lang_string('editors', 'editor')));
 156      $temp = new admin_settingpage('manageeditors', new lang_string('editorsettings', 'editor'));
 157      $temp->add(new admin_setting_manageeditors());
 158      $ADMIN->add('editorsettings', $temp);
 159      $plugins = core_plugin_manager::instance()->get_plugins_of_type('editor');
 160      core_collator::asort_objects_by_property($plugins, 'displayname');
 161      foreach ($plugins as $plugin) {
 162          /** @var \core\plugininfo\editor $plugin */
 163          $plugin->load_settings($ADMIN, 'editorsettings', $hassiteconfig);
 164      }
 165  
 166      // Antivirus plugins.
 167      $ADMIN->add('modules', new admin_category('antivirussettings', new lang_string('antiviruses', 'antivirus')));
 168      $temp = new admin_settingpage('manageantiviruses', new lang_string('antivirussettings', 'antivirus'));
 169      $temp->add(new admin_setting_manageantiviruses());
 170  
 171      // Common settings.
 172      $temp->add(new admin_setting_heading('antiviruscommonsettings', new lang_string('antiviruscommonsettings', 'antivirus'), ''));
 173  
 174      // Alert email.
 175      $temp->add(
 176          new admin_setting_configtext(
 177              'antivirus/notifyemail',
 178              new lang_string('notifyemail', 'antivirus'),
 179              new lang_string('notifyemail_help', 'antivirus'),
 180              '',
 181              PARAM_EMAIL
 182          )
 183      );
 184  
 185      // Notify level.
 186      $temp->add(new admin_setting_configselect('antivirus/notifylevel',
 187          get_string('notifylevel', 'antivirus'), '', core\antivirus\scanner::SCAN_RESULT_ERROR, [
 188              core\antivirus\scanner::SCAN_RESULT_ERROR => get_string('notifylevelerror', 'antivirus'),
 189              core\antivirus\scanner::SCAN_RESULT_FOUND => get_string('notifylevelfound', 'antivirus')
 190          ]),
 191      );
 192  
 193      // Threshold for check displayed on the /report/status/index.php page.
 194      $url = new moodle_url('/report/status/index.php');
 195      $link = html_writer::link($url, get_string('pluginname', 'report_status'));
 196      $temp->add(
 197          new admin_setting_configduration(
 198              'antivirus/threshold',
 199              new lang_string('threshold', 'antivirus'),
 200              get_string('threshold_desc', 'antivirus', $link),
 201              20 * MINSECS
 202          )
 203      );
 204  
 205      // Enable quarantine.
 206      $temp->add(
 207          new admin_setting_configcheckbox(
 208              'antivirus/enablequarantine',
 209              new lang_string('enablequarantine', 'antivirus'),
 210              new lang_string('enablequarantine_help', 'antivirus',
 211              \core\antivirus\quarantine::DEFAULT_QUARANTINE_FOLDER),
 212              0
 213          )
 214      );
 215  
 216      // Quarantine time.
 217      $temp->add(
 218          new admin_setting_configduration(
 219              'antivirus/quarantinetime',
 220              new lang_string('quarantinetime', 'antivirus'),
 221              new lang_string('quarantinetime_desc', 'antivirus'),
 222              \core\antivirus\quarantine::DEFAULT_QUARANTINE_TIME
 223          )
 224      );
 225  
 226      $ADMIN->add('antivirussettings', $temp);
 227      $plugins = core_plugin_manager::instance()->get_plugins_of_type('antivirus');
 228      core_collator::asort_objects_by_property($plugins, 'displayname');
 229      foreach ($plugins as $plugin) {
 230          /* @var \core\plugininfo\antivirus $plugin */
 231          $plugin->load_settings($ADMIN, 'antivirussettings', $hassiteconfig);
 232      }
 233  
 234      // Machine learning backend plugins.
 235      $ADMIN->add('modules', new admin_category('mlbackendsettings', new lang_string('mlbackendsettings', 'admin')));
 236      $plugins = core_plugin_manager::instance()->get_plugins_of_type('mlbackend');
 237      foreach ($plugins as $plugin) {
 238          $plugin->load_settings($ADMIN, 'mlbackendsettings', $hassiteconfig);
 239      }
 240  
 241  /// Filter plugins
 242      $ADMIN->add('modules', new admin_category('filtersettings', new lang_string('managefilters')));
 243  
 244      $ADMIN->add('filtersettings', new admin_page_managefilters());
 245  
 246      // "filtersettings" settingpage
 247      $temp = new admin_settingpage('commonfiltersettings', new lang_string('commonfiltersettings', 'admin'));
 248      if ($ADMIN->fulltree) {
 249          $items = array();
 250          $items[] = new admin_setting_configselect('filteruploadedfiles', new lang_string('filteruploadedfiles', 'admin'), new lang_string('configfilteruploadedfiles', 'admin'), 0,
 251                  array('0' => new lang_string('none'), '1' => new lang_string('allfiles'), '2' => new lang_string('htmlfilesonly')));
 252          $items[] = new admin_setting_configcheckbox('filtermatchoneperpage', new lang_string('filtermatchoneperpage', 'admin'), new lang_string('configfiltermatchoneperpage', 'admin'), 0);
 253          $items[] = new admin_setting_configcheckbox('filtermatchonepertext', new lang_string('filtermatchonepertext', 'admin'), new lang_string('configfiltermatchonepertext', 'admin'), 0);
 254          $items[] = new admin_setting_configcheckbox('filternavigationwithsystemcontext',
 255                  new lang_string('filternavigationwithsystemcontext', 'admin'),
 256                  new lang_string('configfilternavigationwithsystemcontext', 'admin'), 0);
 257          foreach ($items as $item) {
 258              $item->set_updatedcallback('reset_text_filters_cache');
 259              $temp->add($item);
 260          }
 261      }
 262      $ADMIN->add('filtersettings', $temp);
 263  
 264      $plugins = core_plugin_manager::instance()->get_plugins_of_type('filter');
 265      core_collator::asort_objects_by_property($plugins, 'displayname');
 266      foreach ($plugins as $plugin) {
 267          /** @var \core\plugininfo\filter $plugin */
 268          $plugin->load_settings($ADMIN, 'filtersettings', $hassiteconfig);
 269      }
 270  
 271      // Media players.
 272      $ADMIN->add('modules', new admin_category('mediaplayers', new lang_string('type_media_plural', 'plugin')));
 273      $temp = new admin_settingpage('managemediaplayers', new lang_string('managemediaplayers', 'media'));
 274      $temp->add(new admin_setting_heading('mediaformats', get_string('mediaformats', 'core_media'),
 275          format_text(get_string('mediaformats_desc', 'core_media'), FORMAT_MARKDOWN)));
 276      $temp->add(new admin_setting_managemediaplayers());
 277      $temp->add(new admin_setting_heading('managemediaplayerscommonheading', new lang_string('commonsettings', 'admin'), ''));
 278      $temp->add(new admin_setting_configtext('media_default_width',
 279          new lang_string('defaultwidth', 'core_media'), new lang_string('defaultwidthdesc', 'core_media'),
 280          640, PARAM_INT, 10));
 281      $temp->add(new admin_setting_configtext('media_default_height',
 282          new lang_string('defaultheight', 'core_media'), new lang_string('defaultheightdesc', 'core_media'),
 283          360, PARAM_INT, 10));
 284      $ADMIN->add('mediaplayers', $temp);
 285  
 286      // Convert plugins.
 287      $ADMIN->add('modules', new admin_category('fileconverterplugins', new lang_string('type_fileconverter_plural', 'plugin')));
 288      $temp = new admin_settingpage('managefileconverterplugins', new lang_string('type_fileconvertermanage', 'plugin'));
 289      $temp->add(new admin_setting_manage_fileconverter_plugins());
 290      $ADMIN->add('fileconverterplugins', $temp);
 291  
 292      $plugins = core_plugin_manager::instance()->get_plugins_of_type('fileconverter');
 293      core_collator::asort_objects_by_property($plugins, 'displayname');
 294      foreach ($plugins as $plugin) {
 295          /** @var \core\plugininfo\media $plugin */
 296          $plugin->load_settings($ADMIN, 'fileconverterplugins', $hassiteconfig);
 297      }
 298  
 299      $plugins = core_plugin_manager::instance()->get_plugins_of_type('media');
 300      core_collator::asort_objects_by_property($plugins, 'displayname');
 301      foreach ($plugins as $plugin) {
 302          /** @var \core\plugininfo\media $plugin */
 303          $plugin->load_settings($ADMIN, 'mediaplayers', $hassiteconfig);
 304      }
 305  
 306      // Payment gateway plugins.
 307      $ADMIN->add('modules', new admin_category('paymentgateways', new lang_string('type_paygw_plural', 'plugin')));
 308      $temp = new admin_settingpage('managepaymentgateways', new lang_string('type_paygwmanage', 'plugin'));
 309      $temp->add(new \core_admin\local\settings\manage_payment_gateway_plugins());
 310      $temp->add(new admin_setting_description(
 311          'managepaymentgatewayspostfix',
 312          '',
 313          new lang_string('gotopaymentaccounts', 'payment',
 314              html_writer::link(new moodle_url('/payment/accounts.php'), get_string('paymentaccounts', 'payment')))
 315      ));
 316      $ADMIN->add('paymentgateways', $temp);
 317  
 318      $plugins = core_plugin_manager::instance()->get_plugins_of_type('paygw');
 319      core_collator::asort_objects_by_property($plugins, 'displayname');
 320      foreach ($plugins as $plugin) {
 321          /** @var \core\plugininfo\paygw $plugin */
 322          $plugin->load_settings($ADMIN, 'paymentgateways', $hassiteconfig);
 323      }
 324  
 325      // Data format settings.
 326      $ADMIN->add('modules', new admin_category('dataformatsettings', new lang_string('dataformats')));
 327      $temp = new admin_settingpage('managedataformats', new lang_string('managedataformats'));
 328      $temp->add(new admin_setting_managedataformats());
 329      $ADMIN->add('dataformatsettings', $temp);
 330  
 331      $plugins = core_plugin_manager::instance()->get_plugins_of_type('dataformat');
 332      core_collator::asort_objects_by_property($plugins, 'displayname');
 333      foreach ($plugins as $plugin) {
 334          /** @var \core\plugininfo\dataformat $plugin */
 335          $plugin->load_settings($ADMIN, 'dataformatsettings', $hassiteconfig);
 336      }
 337  
 338      //== Portfolio settings ==
 339      require_once($CFG->libdir. '/portfoliolib.php');
 340      $catname = new lang_string('portfolios', 'portfolio');
 341      $manage = new lang_string('manageportfolios', 'portfolio');
 342      $url = "$CFG->wwwroot/$CFG->admin/portfolio.php";
 343  
 344      $ADMIN->add('modules', new admin_category('portfoliosettings', $catname, empty($CFG->enableportfolios)));
 345  
 346      // Add manage page (with table)
 347      $temp = new admin_page_manageportfolios();
 348      $ADMIN->add('portfoliosettings', $temp);
 349  
 350      // Add common settings page
 351      $temp = new admin_settingpage('manageportfolioscommon', new lang_string('commonportfoliosettings', 'portfolio'));
 352      $temp->add(new admin_setting_heading('manageportfolioscommon', '', new lang_string('commonsettingsdesc', 'portfolio')));
 353      $fileinfo = portfolio_filesize_info(); // make sure this is defined in one place since its used inside portfolio too to detect insane settings
 354      $fileoptions = $fileinfo['options'];
 355      $temp->add(new admin_setting_configselect(
 356          'portfolio_moderate_filesize_threshold',
 357          new lang_string('moderatefilesizethreshold', 'portfolio'),
 358          new lang_string('moderatefilesizethresholddesc', 'portfolio'),
 359          $fileinfo['moderate'], $fileoptions));
 360      $temp->add(new admin_setting_configselect(
 361          'portfolio_high_filesize_threshold',
 362          new lang_string('highfilesizethreshold', 'portfolio'),
 363          new lang_string('highfilesizethresholddesc', 'portfolio'),
 364          $fileinfo['high'], $fileoptions));
 365  
 366      $temp->add(new admin_setting_configtext(
 367          'portfolio_moderate_db_threshold',
 368          new lang_string('moderatedbsizethreshold', 'portfolio'),
 369          new lang_string('moderatedbsizethresholddesc', 'portfolio'),
 370          20, PARAM_INT, 3));
 371  
 372      $temp->add(new admin_setting_configtext(
 373          'portfolio_high_db_threshold',
 374          new lang_string('highdbsizethreshold', 'portfolio'),
 375          new lang_string('highdbsizethresholddesc', 'portfolio'),
 376          50, PARAM_INT, 3));
 377  
 378      $ADMIN->add('portfoliosettings', $temp);
 379      $ADMIN->add('portfoliosettings', new admin_externalpage('portfolionew', new lang_string('addnewportfolio', 'portfolio'), $url, 'moodle/site:config', true));
 380      $ADMIN->add('portfoliosettings', new admin_externalpage('portfoliodelete', new lang_string('deleteportfolio', 'portfolio'), $url, 'moodle/site:config', true));
 381      $ADMIN->add('portfoliosettings', new admin_externalpage('portfoliocontroller', new lang_string('manageportfolios', 'portfolio'), $url, 'moodle/site:config', true));
 382  
 383      foreach (portfolio_instances(false, false) as $portfolio) {
 384          require_once($CFG->dirroot . '/portfolio/' . $portfolio->get('plugin') . '/lib.php');
 385          $classname = 'portfolio_plugin_' . $portfolio->get('plugin');
 386          $ADMIN->add(
 387              'portfoliosettings',
 388              new admin_externalpage(
 389                  'portfoliosettings' . $portfolio->get('id'),
 390                  $portfolio->get('name'),
 391                  $url . '?action=edit&pf=' . $portfolio->get('id'),
 392                  'moodle/site:config'
 393              )
 394          );
 395      }
 396  
 397      // repository setting
 398      require_once("$CFG->dirroot/repository/lib.php");
 399      $catname =new lang_string('repositories', 'repository');
 400      $managerepo = new lang_string('manage', 'repository');
 401      $url = $CFG->wwwroot.'/'.$CFG->admin.'/repository.php';
 402      $ADMIN->add('modules', new admin_category('repositorysettings', $catname));
 403  
 404      // Add main page (with table)
 405      $temp = new admin_page_managerepositories();
 406      $ADMIN->add('repositorysettings', $temp);
 407  
 408      // Add common settings page
 409      $temp = new admin_settingpage('managerepositoriescommon', new lang_string('commonrepositorysettings', 'repository'));
 410      $temp->add(new admin_setting_configtext('repositorycacheexpire', new lang_string('cacheexpire', 'repository'), new lang_string('configcacheexpire', 'repository'), 120, PARAM_INT));
 411      $temp->add(new admin_setting_configtext('repositorygetfiletimeout', new lang_string('getfiletimeout', 'repository'), new lang_string('configgetfiletimeout', 'repository'), 30, PARAM_INT));
 412      $temp->add(new admin_setting_configtext('repositorysyncfiletimeout', new lang_string('syncfiletimeout', 'repository'), new lang_string('configsyncfiletimeout', 'repository'), 1, PARAM_INT));
 413      $temp->add(new admin_setting_configtext('repositorysyncimagetimeout', new lang_string('syncimagetimeout', 'repository'), new lang_string('configsyncimagetimeout', 'repository'), 3, PARAM_INT));
 414      $temp->add(new admin_setting_configcheckbox('repositoryallowexternallinks', new lang_string('allowexternallinks', 'repository'), new lang_string('configallowexternallinks', 'repository'), 1));
 415      $temp->add(new admin_setting_configcheckbox('legacyfilesinnewcourses', new lang_string('legacyfilesinnewcourses', 'admin'), new lang_string('legacyfilesinnewcourses_help', 'admin'), 0));
 416      $temp->add(new admin_setting_configcheckbox('legacyfilesaddallowed', new lang_string('legacyfilesaddallowed', 'admin'), new lang_string('legacyfilesaddallowed_help', 'admin'), 1));
 417      $ADMIN->add('repositorysettings', $temp);
 418      $ADMIN->add('repositorysettings', new admin_externalpage('repositorynew',
 419          new lang_string('addplugin', 'repository'), $url, 'moodle/site:config', true));
 420      $ADMIN->add('repositorysettings', new admin_externalpage('repositorydelete',
 421          new lang_string('deleterepository', 'repository'), $url, 'moodle/site:config', true));
 422      $ADMIN->add('repositorysettings', new admin_externalpage('repositorycontroller',
 423          new lang_string('manage', 'repository'), $url, 'moodle/site:config', true));
 424      $ADMIN->add('repositorysettings', new admin_externalpage('repositoryinstancenew',
 425          new lang_string('createrepository', 'repository'), $url, 'moodle/site:config', true));
 426      $ADMIN->add('repositorysettings', new admin_externalpage('repositoryinstanceedit',
 427          new lang_string('editrepositoryinstance', 'repository'), $url, 'moodle/site:config', true));
 428      $plugins = core_plugin_manager::instance()->get_plugins_of_type('repository');
 429      core_collator::asort_objects_by_property($plugins, 'displayname');
 430      foreach ($plugins as $plugin) {
 431          /** @var \core\plugininfo\repository $plugin */
 432          $plugin->load_settings($ADMIN, 'repositorysettings', $hassiteconfig);
 433      }
 434  }
 435  
 436  // Question bank settings.
 437  if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) {
 438      $ADMIN->add('modules', new admin_category('qbanksettings',
 439              new lang_string('type_qbank_plural', 'plugin')));
 440      $temp = new admin_settingpage('manageqbanks', new lang_string('manageqbanks', 'admin'));
 441      $temp->add(new \core_question\admin\manage_qbank_plugins_page());
 442      $ADMIN->add('qbanksettings', $temp);
 443      $plugins = core_plugin_manager::instance()->get_plugins_of_type('qbank');
 444  
 445      foreach ($plugins as $plugin) {
 446          /** @var \core\plugininfo\qbank $plugin */
 447          $plugin->load_settings($ADMIN, 'qbanksettings', $hassiteconfig);
 448      }
 449  }
 450  
 451  // Question type settings
 452  if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) {
 453  
 454      // Question behaviour settings.
 455      $ADMIN->add('modules', new admin_category('qbehavioursettings', new lang_string('questionbehaviours', 'admin')));
 456      $ADMIN->add('qbehavioursettings', new admin_page_manageqbehaviours());
 457  
 458      // Question type settings.
 459      $ADMIN->add('modules', new admin_category('qtypesettings', new lang_string('questiontypes', 'admin')));
 460      $ADMIN->add('qtypesettings', new admin_page_manageqtypes());
 461  
 462      // Question preview defaults.
 463      $settings = new admin_settingpage('qdefaultsetting',
 464              get_string('questionpreviewdefaults', 'question'),
 465              'moodle/question:config');
 466      $ADMIN->add('qtypesettings', $settings);
 467  
 468      $settings->add(new admin_setting_heading('qdefaultsetting_preview_options',
 469              '', get_string('questionpreviewdefaults_desc', 'question')));
 470  
 471      // These keys are question_display_options::HIDDEN and VISIBLE.
 472      $hiddenofvisible = array(
 473          0 => get_string('notshown', 'question'),
 474          1 => get_string('shown', 'question'),
 475      );
 476  
 477      $settings->add(new admin_setting_question_behaviour('question_preview/behaviour',
 478              get_string('howquestionsbehave', 'question'), '',
 479                      'deferredfeedback'));
 480  
 481      $settings->add(new admin_setting_configselect('question_preview/correctness',
 482              get_string('whethercorrect', 'question'), '', 1, $hiddenofvisible));
 483  
 484      // These keys are question_display_options::HIDDEN, MARK_ONLY and MARK_AND_MAX.
 485      $marksoptions = array(
 486          0 => get_string('notshown', 'question'),
 487          1 => get_string('showmaxmarkonly', 'question'),
 488          2 => get_string('showmarkandmax', 'question'),
 489      );
 490      $settings->add(new admin_setting_configselect('question_preview/marks',
 491              get_string('marks', 'question'), '', 2, $marksoptions));
 492  
 493      $settings->add(new admin_setting_configselect('question_preview/markdp',
 494              get_string('decimalplacesingrades', 'question'), '', 2, array(0, 1, 2, 3, 4, 5, 6, 7)));
 495  
 496      $settings->add(new admin_setting_configselect('question_preview/feedback',
 497              get_string('specificfeedback', 'question'), '', 1, $hiddenofvisible));
 498  
 499      $settings->add(new admin_setting_configselect('question_preview/generalfeedback',
 500              get_string('generalfeedback', 'question'), '', 1, $hiddenofvisible));
 501  
 502      $settings->add(new admin_setting_configselect('question_preview/rightanswer',
 503              get_string('rightanswer', 'question'), '', 1, $hiddenofvisible));
 504  
 505      $settings->add(new admin_setting_configselect('question_preview/history',
 506              get_string('responsehistory', 'question'), '', 0, $hiddenofvisible));
 507  
 508      // Settings for particular question types.
 509      $plugins = core_plugin_manager::instance()->get_plugins_of_type('qtype');
 510      core_collator::asort_objects_by_property($plugins, 'displayname');
 511      foreach ($plugins as $plugin) {
 512          /** @var \core\plugininfo\qtype $plugin */
 513          $plugin->load_settings($ADMIN, 'qtypesettings', $hassiteconfig);
 514      }
 515  }
 516  
 517  // Plagiarism plugin settings
 518  if ($hassiteconfig && !empty($CFG->enableplagiarism)) {
 519      $ADMIN->add('modules', new admin_category('plagiarism', new lang_string('plagiarism', 'plagiarism')));
 520      $ADMIN->add('plagiarism', new admin_externalpage('manageplagiarismplugins', new lang_string('manageplagiarism', 'plagiarism'),
 521          $CFG->wwwroot . '/' . $CFG->admin . '/plagiarism.php'));
 522  
 523      $plugins = core_plugin_manager::instance()->get_plugins_of_type('plagiarism');
 524      core_collator::asort_objects_by_property($plugins, 'displayname');
 525      foreach ($plugins as $plugin) {
 526          /** @var \core\plugininfo\plagiarism $plugin */
 527          $plugin->load_settings($ADMIN, 'plagiarism', $hassiteconfig);
 528      }
 529  }
 530  
 531  // Comments report, note this page is really just a means to delete comments so check that.
 532  $ADMIN->add('reports', new admin_externalpage('comments', new lang_string('comments'), $CFG->wwwroot . '/comment/index.php',
 533      'moodle/comment:delete'));
 534  
 535  // Course reports settings
 536  if ($hassiteconfig) {
 537      $pages = array();
 538      foreach (core_component::get_plugin_list('coursereport') as $report => $path) {
 539          $file = $CFG->dirroot . '/course/report/' . $report . '/settings.php';
 540          if (file_exists($file)) {
 541              $settings = new admin_settingpage('coursereport' . $report,
 542                      new lang_string('pluginname', 'coursereport_' . $report), 'moodle/site:config');
 543              // settings.php may create a subcategory or unset the settings completely
 544              include($file);
 545              if ($settings) {
 546                  $pages[] = $settings;
 547              }
 548          }
 549      }
 550      if (!empty($pages)) {
 551          $ADMIN->add('modules', new admin_category('coursereports', new lang_string('coursereports')));
 552          core_collator::asort_objects_by_property($pages, 'visiblename');
 553          foreach ($pages as $page) {
 554              $ADMIN->add('coursereports', $page);
 555          }
 556      }
 557      unset($pages);
 558  }
 559  
 560  // Now add reports
 561  $pages = array();
 562  foreach (core_component::get_plugin_list('report') as $report => $plugindir) {
 563      $settings_path = "$plugindir/settings.php";
 564      if (file_exists($settings_path)) {
 565          $settings = new admin_settingpage('report' . $report,
 566                  new lang_string('pluginname', 'report_' . $report), 'moodle/site:config');
 567          include($settings_path);
 568          if ($settings) {
 569              $pages[] = $settings;
 570          }
 571      }
 572  }
 573  $ADMIN->add('modules', new admin_category('reportplugins', new lang_string('reports')));
 574  $ADMIN->add('reportplugins', new admin_externalpage('managereports', new lang_string('reportsmanage', 'admin'),
 575                                                      $CFG->wwwroot . '/' . $CFG->admin . '/reports.php'));
 576  core_collator::asort_objects_by_property($pages, 'visiblename');
 577  foreach ($pages as $page) {
 578      $ADMIN->add('reportplugins', $page);
 579  }
 580  
 581  if ($hassiteconfig) {
 582      // Global Search engine plugins.
 583      $ADMIN->add('modules', new admin_category('searchplugins', new lang_string('search', 'admin')));
 584      $temp = new admin_settingpage('manageglobalsearch', new lang_string('globalsearchmanage', 'admin'));
 585  
 586      $pages = array();
 587      $engines = array();
 588      foreach (core_component::get_plugin_list('search') as $engine => $plugindir) {
 589          $engines[$engine] = new lang_string('pluginname', 'search_' . $engine);
 590          $settingspath = "$plugindir/settings.php";
 591          if (file_exists($settingspath)) {
 592              $settings = new admin_settingpage('search' . $engine,
 593                      new lang_string('pluginname', 'search_' . $engine), 'moodle/site:config');
 594              include($settingspath);
 595              if ($settings) {
 596                  $pages[] = $settings;
 597              }
 598          }
 599      }
 600  
 601      // Setup status.
 602      $temp->add(new admin_setting_searchsetupinfo());
 603  
 604      // Search engine selection.
 605      $temp->add(new admin_setting_heading('searchengineheading', new lang_string('searchengine', 'admin'), ''));
 606      $searchengineselect = new admin_setting_configselect('searchengine',
 607              new lang_string('selectsearchengine', 'admin'), '', 'simpledb', $engines);
 608      $searchengineselect->set_validate_function(function(string $value): string {
 609          global $CFG;
 610  
 611          // Check nobody's setting the indexing and query-only server to the same one.
 612          if (isset($CFG->searchenginequeryonly) && $CFG->searchenginequeryonly === $value) {
 613              return get_string('searchenginequeryonlysame', 'admin');
 614          } else {
 615              return '';
 616          }
 617      });
 618      $temp->add($searchengineselect);
 619      $temp->add(new admin_setting_heading('searchoptionsheading', new lang_string('searchoptions', 'admin'), ''));
 620      $temp->add(new admin_setting_configcheckbox('searchindexwhendisabled',
 621              new lang_string('searchindexwhendisabled', 'admin'), new lang_string('searchindexwhendisabled_desc', 'admin'),
 622              0));
 623      $temp->add(new admin_setting_configduration('searchindextime',
 624              new lang_string('searchindextime', 'admin'), new lang_string('searchindextime_desc', 'admin'),
 625              600));
 626      $temp->add(new admin_setting_heading('searchcoursesheading', new lang_string('searchablecourses', 'admin'), ''));
 627      $options = [
 628          0 => new lang_string('searchallavailablecourses_off', 'admin'),
 629          1 => new lang_string('searchallavailablecourses_on', 'admin')
 630      ];
 631      $temp->add(new admin_setting_configselect('searchallavailablecourses',
 632              new lang_string('searchallavailablecourses', 'admin'),
 633              new lang_string('searchallavailablecoursesdesc', 'admin'),
 634              0, $options));
 635      $temp->add(new admin_setting_configcheckbox('searchincludeallcourses',
 636          new lang_string('searchincludeallcourses', 'admin'), new lang_string('searchincludeallcourses_desc', 'admin'),
 637          0));
 638  
 639      // Search display options.
 640      $temp->add(new admin_setting_heading('searchdisplay', new lang_string('searchdisplay', 'admin'), ''));
 641      $temp->add(new admin_setting_configcheckbox('searchenablecategories',
 642          new lang_string('searchenablecategories', 'admin'),
 643          new lang_string('searchenablecategories_desc', 'admin'),
 644          0));
 645      $options = [];
 646      foreach (\core_search\manager::get_search_area_categories() as $category) {
 647          $options[$category->get_name()] = $category->get_visiblename();
 648      }
 649      $temp->add(new admin_setting_configselect('searchdefaultcategory',
 650          new lang_string('searchdefaultcategory', 'admin'),
 651          new lang_string('searchdefaultcategory_desc', 'admin'),
 652          \core_search\manager::SEARCH_AREA_CATEGORY_ALL, $options));
 653      $temp->add(new admin_setting_configcheckbox('searchhideallcategory',
 654          new lang_string('searchhideallcategory', 'admin'),
 655          new lang_string('searchhideallcategory_desc', 'admin'),
 656          0));
 657  
 658      // Top result options.
 659      $temp->add(new admin_setting_heading('searchtopresults', new lang_string('searchtopresults', 'admin'), ''));
 660      // Max Top results.
 661      $options = range(0, 10);
 662      $temp->add(new admin_setting_configselect('searchmaxtopresults',
 663          new lang_string('searchmaxtopresults', 'admin'),
 664          new lang_string('searchmaxtopresults_desc', 'admin'),
 665          3, $options));
 666      // Teacher roles.
 667      $options = [];
 668      foreach (role_get_names() as $role) {
 669          $options[$role->id] = $role->localname;
 670      }
 671      $temp->add(new admin_setting_configmultiselect('searchteacherroles',
 672          new lang_string('searchteacherroles', 'admin'),
 673          new lang_string('searchteacherroles_desc', 'admin'),
 674          [], $options));
 675  
 676      $temp->add(new admin_setting_heading('searchmanagement', new lang_string('searchmanagement', 'admin'),
 677              new lang_string('searchmanagement_desc', 'admin')));
 678  
 679      // Get list of search engines including those with alternate settings.
 680      $searchenginequeryonlyselect = new admin_setting_configselect('searchenginequeryonly',
 681              new lang_string('searchenginequeryonly', 'admin'),
 682              new lang_string('searchenginequeryonly_desc', 'admin'), '', function() use($engines) {
 683                  $options = ['' => new lang_string('searchenginequeryonly_none', 'admin')];
 684                  foreach ($engines as $name => $display) {
 685                      $options[$name] = $display;
 686  
 687                      $classname = '\search_' . $name . '\engine';
 688                      $engine = new $classname;
 689                      if ($engine->has_alternate_configuration()) {
 690                          $options[$name . '-alternate'] =
 691                                  new lang_string('searchenginealternatesettings', 'admin', $display);
 692                      }
 693                  }
 694                  return $options;
 695              });
 696      $searchenginequeryonlyselect->set_validate_function(function(string $value): string {
 697          global $CFG;
 698  
 699          // Check nobody's setting the indexing and query-only server to the same one.
 700          if (isset($CFG->searchengine) && $CFG->searchengine === $value) {
 701              return get_string('searchenginequeryonlysame', 'admin');
 702          } else {
 703              return '';
 704          }
 705      });
 706      $temp->add($searchenginequeryonlyselect);
 707      $temp->add(new admin_setting_configcheckbox('searchbannerenable',
 708              new lang_string('searchbannerenable', 'admin'), new lang_string('searchbannerenable_desc', 'admin'),
 709              0));
 710      $temp->add(new admin_setting_confightmleditor('searchbanner',
 711              new lang_string('searchbanner', 'admin'), '', ''));
 712  
 713      $ADMIN->add('searchplugins', $temp);
 714      $ADMIN->add('searchplugins', new admin_externalpage('searchareas', new lang_string('searchareas', 'admin'),
 715          new moodle_url('/admin/searchareas.php')));
 716  
 717      core_collator::asort_objects_by_property($pages, 'visiblename');
 718      foreach ($pages as $page) {
 719          $ADMIN->add('searchplugins', $page);
 720      }
 721  }
 722  
 723  /// Add all admin tools
 724  if ($hassiteconfig) {
 725      $ADMIN->add('modules', new admin_category('tools', new lang_string('tools', 'admin')));
 726      $ADMIN->add('tools', new admin_externalpage('managetools', new lang_string('toolsmanage', 'admin'),
 727                                                       $CFG->wwwroot . '/' . $CFG->admin . '/tools.php'));
 728  }
 729  
 730  // Now add various admin tools.
 731  $plugins = core_plugin_manager::instance()->get_plugins_of_type('tool');
 732  core_collator::asort_objects_by_property($plugins, 'displayname');
 733  foreach ($plugins as $plugin) {
 734      /** @var \core\plugininfo\tool $plugin */
 735      $plugin->load_settings($ADMIN, null, $hassiteconfig);
 736  }
 737  
 738  // Now add the Cache plugins
 739  if ($hassiteconfig) {
 740      $ADMIN->add('modules', new admin_category('cache', new lang_string('caching', 'cache')));
 741      $ADMIN->add('cache', new admin_externalpage('cacheconfig', new lang_string('cacheconfig', 'cache'), $CFG->wwwroot .'/cache/admin.php'));
 742      $ADMIN->add('cache', new admin_externalpage('cachetestperformance', new lang_string('testperformance', 'cache'), $CFG->wwwroot . '/cache/testperformance.php'));
 743      $ADMIN->add('cache', new admin_externalpage('cacheusage',
 744              new lang_string('cacheusage', 'cache'), $CFG->wwwroot . '/cache/usage.php'));
 745      $ADMIN->add('cache', new admin_category('cachestores', new lang_string('cachestores', 'cache')));
 746      $ADMIN->locate('cachestores')->set_sorting(true);
 747      foreach (core_component::get_plugin_list('cachestore') as $plugin => $path) {
 748          $settingspath = $path.'/settings.php';
 749          if (file_exists($settingspath)) {
 750              $settings = new admin_settingpage('cachestore_'.$plugin.'_settings', new lang_string('pluginname', 'cachestore_'.$plugin), 'moodle/site:config');
 751              include($settingspath);
 752              $ADMIN->add('cachestores', $settings);
 753          }
 754      }
 755  }
 756  
 757  // Add Calendar type settings.
 758  if ($hassiteconfig) {
 759      $ADMIN->add('modules', new admin_category('calendartype', new lang_string('calendartypes', 'calendar')));
 760      $plugins = core_plugin_manager::instance()->get_plugins_of_type('calendartype');
 761      core_collator::asort_objects_by_property($plugins, 'displayname');
 762      foreach ($plugins as $plugin) {
 763          /** @var \core\plugininfo\calendartype $plugin */
 764          $plugin->load_settings($ADMIN, 'calendartype', $hassiteconfig);
 765      }
 766  }
 767  
 768  // Content bank content types.
 769  if ($hassiteconfig) {
 770      $ADMIN->add('modules', new admin_category('contentbanksettings', new lang_string('contentbank')));
 771      $temp = new admin_settingpage('managecontentbanktypes', new lang_string('managecontentbanktypes'));
 772      $temp->add(new admin_setting_managecontentbankcontenttypes());
 773      $ADMIN->add('contentbanksettings', $temp);
 774      $plugins = core_plugin_manager::instance()->get_plugins_of_type('contenttype');
 775      foreach ($plugins as $plugin) {
 776          /** @var \core\plugininfo\contentbank $plugin */
 777          $plugin->load_settings($ADMIN, 'contentbanksettings', $hassiteconfig);
 778      }
 779  }
 780  
 781  /// Add all local plugins - must be always last!
 782  if ($hassiteconfig) {
 783      $ADMIN->add('modules', new admin_category('localplugins', new lang_string('localplugins')));
 784      $ADMIN->add('localplugins', new admin_externalpage('managelocalplugins', new lang_string('localpluginsmanage'),
 785                                                          $CFG->wwwroot . '/' . $CFG->admin . '/localplugins.php'));
 786  }
 787  
 788  // Extend settings for each local plugin. Note that their settings may be in any part of the
 789  // settings tree and may be visible not only for administrators.
 790  $plugins = core_plugin_manager::instance()->get_plugins_of_type('local');
 791  core_collator::asort_objects_by_property($plugins, 'displayname');
 792  foreach ($plugins as $plugin) {
 793      /** @var \core\plugininfo\local $plugin */
 794      $plugin->load_settings($ADMIN, null, $hassiteconfig);
 795  }