Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

   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())), ''));
 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      // Enable quarantine.
 186      $temp->add(
 187          new admin_setting_configcheckbox(
 188              'antivirus/enablequarantine',
 189              new lang_string('enablequarantine', 'antivirus'),
 190              new lang_string('enablequarantine_help', 'antivirus',
 191              \core\antivirus\quarantine::DEFAULT_QUARANTINE_FOLDER),
 192              0
 193          )
 194      );
 195  
 196      // Quarantine time.
 197      $temp->add(
 198          new admin_setting_configduration(
 199              'antivirus/quarantinetime',
 200              new lang_string('quarantinetime', 'antivirus'),
 201              new lang_string('quarantinetime_desc', 'antivirus'),
 202              \core\antivirus\quarantine::DEFAULT_QUARANTINE_TIME
 203          )
 204      );
 205  
 206      $ADMIN->add('antivirussettings', $temp);
 207      $plugins = core_plugin_manager::instance()->get_plugins_of_type('antivirus');
 208      core_collator::asort_objects_by_property($plugins, 'displayname');
 209      foreach ($plugins as $plugin) {
 210          /* @var \core\plugininfo\antivirus $plugin */
 211          $plugin->load_settings($ADMIN, 'antivirussettings', $hassiteconfig);
 212      }
 213  
 214      // Machine learning backend plugins.
 215      $ADMIN->add('modules', new admin_category('mlbackendsettings', new lang_string('mlbackendsettings', 'admin')));
 216      $plugins = core_plugin_manager::instance()->get_plugins_of_type('mlbackend');
 217      foreach ($plugins as $plugin) {
 218          $plugin->load_settings($ADMIN, 'mlbackendsettings', $hassiteconfig);
 219      }
 220  
 221  /// Filter plugins
 222      $ADMIN->add('modules', new admin_category('filtersettings', new lang_string('managefilters')));
 223  
 224      $ADMIN->add('filtersettings', new admin_page_managefilters());
 225  
 226      // "filtersettings" settingpage
 227      $temp = new admin_settingpage('commonfiltersettings', new lang_string('commonfiltersettings', 'admin'));
 228      if ($ADMIN->fulltree) {
 229          $items = array();
 230          $items[] = new admin_setting_configselect('filteruploadedfiles', new lang_string('filteruploadedfiles', 'admin'), new lang_string('configfilteruploadedfiles', 'admin'), 0,
 231                  array('0' => new lang_string('none'), '1' => new lang_string('allfiles'), '2' => new lang_string('htmlfilesonly')));
 232          $items[] = new admin_setting_configcheckbox('filtermatchoneperpage', new lang_string('filtermatchoneperpage', 'admin'), new lang_string('configfiltermatchoneperpage', 'admin'), 0);
 233          $items[] = new admin_setting_configcheckbox('filtermatchonepertext', new lang_string('filtermatchonepertext', 'admin'), new lang_string('configfiltermatchonepertext', 'admin'), 0);
 234          foreach ($items as $item) {
 235              $item->set_updatedcallback('reset_text_filters_cache');
 236              $temp->add($item);
 237          }
 238      }
 239      $ADMIN->add('filtersettings', $temp);
 240  
 241      $plugins = core_plugin_manager::instance()->get_plugins_of_type('filter');
 242      core_collator::asort_objects_by_property($plugins, 'displayname');
 243      foreach ($plugins as $plugin) {
 244          /** @var \core\plugininfo\filter $plugin */
 245          $plugin->load_settings($ADMIN, 'filtersettings', $hassiteconfig);
 246      }
 247  
 248      // Media players.
 249      $ADMIN->add('modules', new admin_category('mediaplayers', new lang_string('type_media_plural', 'plugin')));
 250      $temp = new admin_settingpage('managemediaplayers', new lang_string('managemediaplayers', 'media'));
 251      $temp->add(new admin_setting_heading('mediaformats', get_string('mediaformats', 'core_media'),
 252          format_text(get_string('mediaformats_desc', 'core_media'), FORMAT_MARKDOWN)));
 253      $temp->add(new admin_setting_managemediaplayers());
 254      $temp->add(new admin_setting_heading('managemediaplayerscommonheading', new lang_string('commonsettings', 'admin'), ''));
 255      $temp->add(new admin_setting_configtext('media_default_width',
 256          new lang_string('defaultwidth', 'core_media'), new lang_string('defaultwidthdesc', 'core_media'),
 257          400, PARAM_INT, 10));
 258      $temp->add(new admin_setting_configtext('media_default_height',
 259          new lang_string('defaultheight', 'core_media'), new lang_string('defaultheightdesc', 'core_media'),
 260          300, PARAM_INT, 10));
 261      $ADMIN->add('mediaplayers', $temp);
 262  
 263      // Convert plugins.
 264      $ADMIN->add('modules', new admin_category('fileconverterplugins', new lang_string('type_fileconverter_plural', 'plugin')));
 265      $temp = new admin_settingpage('managefileconverterplugins', new lang_string('type_fileconvertermanage', 'plugin'));
 266      $temp->add(new admin_setting_manage_fileconverter_plugins());
 267      $ADMIN->add('fileconverterplugins', $temp);
 268  
 269      $plugins = core_plugin_manager::instance()->get_plugins_of_type('fileconverter');
 270      core_collator::asort_objects_by_property($plugins, 'displayname');
 271      foreach ($plugins as $plugin) {
 272          /** @var \core\plugininfo\media $plugin */
 273          $plugin->load_settings($ADMIN, 'fileconverterplugins', $hassiteconfig);
 274      }
 275  
 276      $plugins = core_plugin_manager::instance()->get_plugins_of_type('media');
 277      core_collator::asort_objects_by_property($plugins, 'displayname');
 278      foreach ($plugins as $plugin) {
 279          /** @var \core\plugininfo\media $plugin */
 280          $plugin->load_settings($ADMIN, 'mediaplayers', $hassiteconfig);
 281      }
 282  
 283      // Payment gateway plugins.
 284      $ADMIN->add('modules', new admin_category('paymentgateways', new lang_string('type_paygw_plural', 'plugin')));
 285      $temp = new admin_settingpage('managepaymentgateways', new lang_string('type_paygwmanage', 'plugin'));
 286      $temp->add(new \core_admin\local\settings\manage_payment_gateway_plugins());
 287      $temp->add(new admin_setting_description(
 288          'managepaymentgatewayspostfix',
 289          '',
 290          new lang_string('gotopaymentaccounts', 'payment',
 291              html_writer::link(new moodle_url('/payment/accounts.php'), get_string('paymentaccounts', 'payment')))
 292      ));
 293      $ADMIN->add('paymentgateways', $temp);
 294  
 295      $plugins = core_plugin_manager::instance()->get_plugins_of_type('paygw');
 296      core_collator::asort_objects_by_property($plugins, 'displayname');
 297      foreach ($plugins as $plugin) {
 298          /** @var \core\plugininfo\paygw $plugin */
 299          $plugin->load_settings($ADMIN, 'paymentgateways', $hassiteconfig);
 300      }
 301  
 302      // Data format settings.
 303      $ADMIN->add('modules', new admin_category('dataformatsettings', new lang_string('dataformats')));
 304      $temp = new admin_settingpage('managedataformats', new lang_string('managedataformats'));
 305      $temp->add(new admin_setting_managedataformats());
 306      $ADMIN->add('dataformatsettings', $temp);
 307  
 308      //== Portfolio settings ==
 309      require_once($CFG->libdir. '/portfoliolib.php');
 310      $catname = new lang_string('portfolios', 'portfolio');
 311      $manage = new lang_string('manageportfolios', 'portfolio');
 312      $url = "$CFG->wwwroot/$CFG->admin/portfolio.php";
 313  
 314      $ADMIN->add('modules', new admin_category('portfoliosettings', $catname, empty($CFG->enableportfolios)));
 315  
 316      // Add manage page (with table)
 317      $temp = new admin_page_manageportfolios();
 318      $ADMIN->add('portfoliosettings', $temp);
 319  
 320      // Add common settings page
 321      $temp = new admin_settingpage('manageportfolioscommon', new lang_string('commonportfoliosettings', 'portfolio'));
 322      $temp->add(new admin_setting_heading('manageportfolioscommon', '', new lang_string('commonsettingsdesc', 'portfolio')));
 323      $fileinfo = portfolio_filesize_info(); // make sure this is defined in one place since its used inside portfolio too to detect insane settings
 324      $fileoptions = $fileinfo['options'];
 325      $temp->add(new admin_setting_configselect(
 326          'portfolio_moderate_filesize_threshold',
 327          new lang_string('moderatefilesizethreshold', 'portfolio'),
 328          new lang_string('moderatefilesizethresholddesc', 'portfolio'),
 329          $fileinfo['moderate'], $fileoptions));
 330      $temp->add(new admin_setting_configselect(
 331          'portfolio_high_filesize_threshold',
 332          new lang_string('highfilesizethreshold', 'portfolio'),
 333          new lang_string('highfilesizethresholddesc', 'portfolio'),
 334          $fileinfo['high'], $fileoptions));
 335  
 336      $temp->add(new admin_setting_configtext(
 337          'portfolio_moderate_db_threshold',
 338          new lang_string('moderatedbsizethreshold', 'portfolio'),
 339          new lang_string('moderatedbsizethresholddesc', 'portfolio'),
 340          20, PARAM_INT, 3));
 341  
 342      $temp->add(new admin_setting_configtext(
 343          'portfolio_high_db_threshold',
 344          new lang_string('highdbsizethreshold', 'portfolio'),
 345          new lang_string('highdbsizethresholddesc', 'portfolio'),
 346          50, PARAM_INT, 3));
 347  
 348      $ADMIN->add('portfoliosettings', $temp);
 349      $ADMIN->add('portfoliosettings', new admin_externalpage('portfolionew', new lang_string('addnewportfolio', 'portfolio'), $url, 'moodle/site:config', true));
 350      $ADMIN->add('portfoliosettings', new admin_externalpage('portfoliodelete', new lang_string('deleteportfolio', 'portfolio'), $url, 'moodle/site:config', true));
 351      $ADMIN->add('portfoliosettings', new admin_externalpage('portfoliocontroller', new lang_string('manageportfolios', 'portfolio'), $url, 'moodle/site:config', true));
 352  
 353      foreach (portfolio_instances(false, false) as $portfolio) {
 354          require_once($CFG->dirroot . '/portfolio/' . $portfolio->get('plugin') . '/lib.php');
 355          $classname = 'portfolio_plugin_' . $portfolio->get('plugin');
 356          $ADMIN->add(
 357              'portfoliosettings',
 358              new admin_externalpage(
 359                  'portfoliosettings' . $portfolio->get('id'),
 360                  $portfolio->get('name'),
 361                  $url . '?action=edit&pf=' . $portfolio->get('id'),
 362                  'moodle/site:config'
 363              )
 364          );
 365      }
 366  
 367      // repository setting
 368      require_once("$CFG->dirroot/repository/lib.php");
 369      $catname =new lang_string('repositories', 'repository');
 370      $managerepo = new lang_string('manage', 'repository');
 371      $url = $CFG->wwwroot.'/'.$CFG->admin.'/repository.php';
 372      $ADMIN->add('modules', new admin_category('repositorysettings', $catname));
 373  
 374      // Add main page (with table)
 375      $temp = new admin_page_managerepositories();
 376      $ADMIN->add('repositorysettings', $temp);
 377  
 378      // Add common settings page
 379      $temp = new admin_settingpage('managerepositoriescommon', new lang_string('commonrepositorysettings', 'repository'));
 380      $temp->add(new admin_setting_configtext('repositorycacheexpire', new lang_string('cacheexpire', 'repository'), new lang_string('configcacheexpire', 'repository'), 120, PARAM_INT));
 381      $temp->add(new admin_setting_configtext('repositorygetfiletimeout', new lang_string('getfiletimeout', 'repository'), new lang_string('configgetfiletimeout', 'repository'), 30, PARAM_INT));
 382      $temp->add(new admin_setting_configtext('repositorysyncfiletimeout', new lang_string('syncfiletimeout', 'repository'), new lang_string('configsyncfiletimeout', 'repository'), 1, PARAM_INT));
 383      $temp->add(new admin_setting_configtext('repositorysyncimagetimeout', new lang_string('syncimagetimeout', 'repository'), new lang_string('configsyncimagetimeout', 'repository'), 3, PARAM_INT));
 384      $temp->add(new admin_setting_configcheckbox('repositoryallowexternallinks', new lang_string('allowexternallinks', 'repository'), new lang_string('configallowexternallinks', 'repository'), 1));
 385      $temp->add(new admin_setting_configcheckbox('legacyfilesinnewcourses', new lang_string('legacyfilesinnewcourses', 'admin'), new lang_string('legacyfilesinnewcourses_help', 'admin'), 0));
 386      $temp->add(new admin_setting_configcheckbox('legacyfilesaddallowed', new lang_string('legacyfilesaddallowed', 'admin'), new lang_string('legacyfilesaddallowed_help', 'admin'), 1));
 387      $ADMIN->add('repositorysettings', $temp);
 388      $ADMIN->add('repositorysettings', new admin_externalpage('repositorynew',
 389          new lang_string('addplugin', 'repository'), $url, 'moodle/site:config', true));
 390      $ADMIN->add('repositorysettings', new admin_externalpage('repositorydelete',
 391          new lang_string('deleterepository', 'repository'), $url, 'moodle/site:config', true));
 392      $ADMIN->add('repositorysettings', new admin_externalpage('repositorycontroller',
 393          new lang_string('manage', 'repository'), $url, 'moodle/site:config', true));
 394      $ADMIN->add('repositorysettings', new admin_externalpage('repositoryinstancenew',
 395          new lang_string('createrepository', 'repository'), $url, 'moodle/site:config', true));
 396      $ADMIN->add('repositorysettings', new admin_externalpage('repositoryinstanceedit',
 397          new lang_string('editrepositoryinstance', 'repository'), $url, 'moodle/site:config', true));
 398      $plugins = core_plugin_manager::instance()->get_plugins_of_type('repository');
 399      core_collator::asort_objects_by_property($plugins, 'displayname');
 400      foreach ($plugins as $plugin) {
 401          /** @var \core\plugininfo\repository $plugin */
 402          $plugin->load_settings($ADMIN, 'repositorysettings', $hassiteconfig);
 403      }
 404  
 405  /// Web services
 406      $ADMIN->add('modules', new admin_category('webservicesettings', new lang_string('webservices', 'webservice')));
 407  
 408      /// overview page
 409      $temp = new admin_settingpage('webservicesoverview', new lang_string('webservicesoverview', 'webservice'));
 410      $temp->add(new admin_setting_webservicesoverview());
 411      $ADMIN->add('webservicesettings', $temp);
 412      //API documentation
 413      $ADMIN->add('webservicesettings', new admin_externalpage('webservicedocumentation', new lang_string('wsdocapi', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/documentation.php", 'moodle/site:config', false));
 414      /// manage service
 415      $temp = new admin_settingpage('externalservices', new lang_string('externalservices', 'webservice'));
 416      $temp->add(new admin_setting_heading('manageserviceshelpexplaination', new lang_string('information', 'webservice'), new lang_string('servicehelpexplanation', 'webservice')));
 417      $temp->add(new admin_setting_manageexternalservices());
 418      $ADMIN->add('webservicesettings', $temp);
 419      $ADMIN->add('webservicesettings', new admin_externalpage('externalservice', new lang_string('editaservice', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service.php", 'moodle/site:config', true));
 420      $ADMIN->add('webservicesettings', new admin_externalpage('externalservicefunctions', new lang_string('externalservicefunctions', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service_functions.php", 'moodle/site:config', true));
 421      $ADMIN->add('webservicesettings', new admin_externalpage('externalserviceusers', new lang_string('externalserviceusers', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service_users.php", 'moodle/site:config', true));
 422      $ADMIN->add('webservicesettings', new admin_externalpage('externalserviceusersettings', new lang_string('serviceusersettings', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service_user_settings.php", 'moodle/site:config', true));
 423      /// manage protocol page link
 424      $temp = new admin_settingpage('webserviceprotocols', new lang_string('manageprotocols', 'webservice'));
 425      $temp->add(new admin_setting_managewebserviceprotocols());
 426      if (empty($CFG->enablewebservices)) {
 427          $temp->add(new admin_setting_heading('webservicesaredisabled', '', new lang_string('disabledwarning', 'webservice')));
 428      }
 429  
 430      // We cannot use $OUTPUT this early, doing so means that we lose the ability
 431      // to set the page layout on all admin pages.
 432      // $wsdoclink = $OUTPUT->doc_link('How_to_get_a_security_key');
 433      $url = new moodle_url(get_docs_url('How_to_get_a_security_key'));
 434      $wsdoclink = html_writer::tag('a', new lang_string('supplyinfo', 'webservice'), array('href'=>$url));
 435      $temp->add(new admin_setting_configcheckbox('enablewsdocumentation', new lang_string('enablewsdocumentation',
 436                          'admin'), new lang_string('configenablewsdocumentation', 'admin', $wsdoclink), false));
 437      $ADMIN->add('webservicesettings', $temp);
 438      /// links to protocol pages
 439      $plugins = core_plugin_manager::instance()->get_plugins_of_type('webservice');
 440      core_collator::asort_objects_by_property($plugins, 'displayname');
 441      foreach ($plugins as $plugin) {
 442          /** @var \core\plugininfo\webservice $plugin */
 443          $plugin->load_settings($ADMIN, 'webservicesettings', $hassiteconfig);
 444      }
 445      /// manage token page link
 446      $ADMIN->add('webservicesettings', new admin_externalpage('addwebservicetoken', new lang_string('managetokens', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/tokens.php", 'moodle/site:config', true));
 447      $temp = new admin_settingpage('webservicetokens', new lang_string('managetokens', 'webservice'));
 448      $temp->add(new admin_setting_managewebservicetokens());
 449      if (empty($CFG->enablewebservices)) {
 450          $temp->add(new admin_setting_heading('webservicesaredisabled', '', new lang_string('disabledwarning', 'webservice')));
 451      }
 452      $ADMIN->add('webservicesettings', $temp);
 453  }
 454  
 455  // Question type settings
 456  if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) {
 457  
 458      // Question behaviour settings.
 459      $ADMIN->add('modules', new admin_category('qbehavioursettings', new lang_string('questionbehaviours', 'admin')));
 460      $ADMIN->add('qbehavioursettings', new admin_page_manageqbehaviours());
 461  
 462      // Question type settings.
 463      $ADMIN->add('modules', new admin_category('qtypesettings', new lang_string('questiontypes', 'admin')));
 464      $ADMIN->add('qtypesettings', new admin_page_manageqtypes());
 465  
 466      // Question preview defaults.
 467      $settings = new admin_settingpage('qdefaultsetting',
 468              get_string('questionpreviewdefaults', 'question'),
 469              'moodle/question:config');
 470      $ADMIN->add('qtypesettings', $settings);
 471  
 472      $settings->add(new admin_setting_heading('qdefaultsetting_preview_options',
 473              '', get_string('questionpreviewdefaults_desc', 'question')));
 474  
 475      // These keys are question_display_options::HIDDEN and VISIBLE.
 476      $hiddenofvisible = array(
 477          0 => get_string('notshown', 'question'),
 478          1 => get_string('shown', 'question'),
 479      );
 480  
 481      $settings->add(new admin_setting_question_behaviour('question_preview/behaviour',
 482              get_string('howquestionsbehave', 'question'), '',
 483                      'deferredfeedback'));
 484  
 485      $settings->add(new admin_setting_configselect('question_preview/correctness',
 486              get_string('whethercorrect', 'question'), '', 1, $hiddenofvisible));
 487  
 488      // These keys are question_display_options::HIDDEN, MARK_ONLY and MARK_AND_MAX.
 489      $marksoptions = array(
 490          0 => get_string('notshown', 'question'),
 491          1 => get_string('showmaxmarkonly', 'question'),
 492          2 => get_string('showmarkandmax', 'question'),
 493      );
 494      $settings->add(new admin_setting_configselect('question_preview/marks',
 495              get_string('marks', 'question'), '', 2, $marksoptions));
 496  
 497      $settings->add(new admin_setting_configselect('question_preview/markdp',
 498              get_string('decimalplacesingrades', 'question'), '', 2, array(0, 1, 2, 3, 4, 5, 6, 7)));
 499  
 500      $settings->add(new admin_setting_configselect('question_preview/feedback',
 501              get_string('specificfeedback', 'question'), '', 1, $hiddenofvisible));
 502  
 503      $settings->add(new admin_setting_configselect('question_preview/generalfeedback',
 504              get_string('generalfeedback', 'question'), '', 1, $hiddenofvisible));
 505  
 506      $settings->add(new admin_setting_configselect('question_preview/rightanswer',
 507              get_string('rightanswer', 'question'), '', 1, $hiddenofvisible));
 508  
 509      $settings->add(new admin_setting_configselect('question_preview/history',
 510              get_string('responsehistory', 'question'), '', 0, $hiddenofvisible));
 511  
 512      // Settings for particular question types.
 513      $plugins = core_plugin_manager::instance()->get_plugins_of_type('qtype');
 514      core_collator::asort_objects_by_property($plugins, 'displayname');
 515      foreach ($plugins as $plugin) {
 516          /** @var \core\plugininfo\qtype $plugin */
 517          $plugin->load_settings($ADMIN, 'qtypesettings', $hassiteconfig);
 518      }
 519  }
 520  
 521  // Plagiarism plugin settings
 522  if ($hassiteconfig && !empty($CFG->enableplagiarism)) {
 523      $ADMIN->add('modules', new admin_category('plagiarism', new lang_string('plagiarism', 'plagiarism')));
 524      $ADMIN->add('plagiarism', new admin_externalpage('manageplagiarismplugins', new lang_string('manageplagiarism', 'plagiarism'),
 525          $CFG->wwwroot . '/' . $CFG->admin . '/plagiarism.php'));
 526  
 527      $plugins = core_plugin_manager::instance()->get_plugins_of_type('plagiarism');
 528      core_collator::asort_objects_by_property($plugins, 'displayname');
 529      foreach ($plugins as $plugin) {
 530          /** @var \core\plugininfo\plagiarism $plugin */
 531          $plugin->load_settings($ADMIN, 'plagiarism', $hassiteconfig);
 532      }
 533  }
 534  $ADMIN->add('reports', new admin_externalpage('comments', new lang_string('comments'), $CFG->wwwroot.'/comment/', 'moodle/site:viewreports'));
 535  
 536  // Course reports settings
 537  if ($hassiteconfig) {
 538      $pages = array();
 539      foreach (core_component::get_plugin_list('coursereport') as $report => $path) {
 540          $file = $CFG->dirroot . '/course/report/' . $report . '/settings.php';
 541          if (file_exists($file)) {
 542              $settings = new admin_settingpage('coursereport' . $report,
 543                      new lang_string('pluginname', 'coursereport_' . $report), 'moodle/site:config');
 544              // settings.php may create a subcategory or unset the settings completely
 545              include($file);
 546              if ($settings) {
 547                  $pages[] = $settings;
 548              }
 549          }
 550      }
 551      if (!empty($pages)) {
 552          $ADMIN->add('modules', new admin_category('coursereports', new lang_string('coursereports')));
 553          core_collator::asort_objects_by_property($pages, 'visiblename');
 554          foreach ($pages as $page) {
 555              $ADMIN->add('coursereports', $page);
 556          }
 557      }
 558      unset($pages);
 559  }
 560  
 561  // Now add reports
 562  $pages = array();
 563  foreach (core_component::get_plugin_list('report') as $report => $plugindir) {
 564      $settings_path = "$plugindir/settings.php";
 565      if (file_exists($settings_path)) {
 566          $settings = new admin_settingpage('report' . $report,
 567                  new lang_string('pluginname', 'report_' . $report), 'moodle/site:config');
 568          include($settings_path);
 569          if ($settings) {
 570              $pages[] = $settings;
 571          }
 572      }
 573  }
 574  $ADMIN->add('modules', new admin_category('reportplugins', new lang_string('reports')));
 575  $ADMIN->add('reportplugins', new admin_externalpage('managereports', new lang_string('reportsmanage', 'admin'),
 576                                                      $CFG->wwwroot . '/' . $CFG->admin . '/reports.php'));
 577  core_collator::asort_objects_by_property($pages, 'visiblename');
 578  foreach ($pages as $page) {
 579      $ADMIN->add('reportplugins', $page);
 580  }
 581  
 582  if ($hassiteconfig) {
 583      // Global Search engine plugins.
 584      $ADMIN->add('modules', new admin_category('searchplugins', new lang_string('search', 'admin')));
 585      $temp = new admin_settingpage('manageglobalsearch', new lang_string('globalsearchmanage', 'admin'));
 586  
 587      $pages = array();
 588      $engines = array();
 589      foreach (core_component::get_plugin_list('search') as $engine => $plugindir) {
 590          $engines[$engine] = new lang_string('pluginname', 'search_' . $engine);
 591          $settingspath = "$plugindir/settings.php";
 592          if (file_exists($settingspath)) {
 593              $settings = new admin_settingpage('search' . $engine,
 594                      new lang_string('pluginname', 'search_' . $engine), 'moodle/site:config');
 595              include($settingspath);
 596              if ($settings) {
 597                  $pages[] = $settings;
 598              }
 599          }
 600      }
 601  
 602      // Setup status.
 603      $temp->add(new admin_setting_searchsetupinfo());
 604  
 605      // Search engine selection.
 606      $temp->add(new admin_setting_heading('searchengineheading', new lang_string('searchengine', 'admin'), ''));
 607      $searchengineselect = new admin_setting_configselect('searchengine',
 608              new lang_string('selectsearchengine', 'admin'), '', 'simpledb', $engines);
 609      $searchengineselect->set_validate_function(function(string $value): string {
 610          global $CFG;
 611  
 612          // Check nobody's setting the indexing and query-only server to the same one.
 613          if (isset($CFG->searchenginequeryonly) && $CFG->searchenginequeryonly === $value) {
 614              return get_string('searchenginequeryonlysame', 'admin');
 615          } else {
 616              return '';
 617          }
 618      });
 619      $temp->add($searchengineselect);
 620      $temp->add(new admin_setting_heading('searchoptionsheading', new lang_string('searchoptions', 'admin'), ''));
 621      $temp->add(new admin_setting_configcheckbox('searchindexwhendisabled',
 622              new lang_string('searchindexwhendisabled', 'admin'), new lang_string('searchindexwhendisabled_desc', 'admin'),
 623              0));
 624      $temp->add(new admin_setting_configduration('searchindextime',
 625              new lang_string('searchindextime', 'admin'), new lang_string('searchindextime_desc', 'admin'),
 626              600));
 627      $temp->add(new admin_setting_heading('searchcoursesheading', new lang_string('searchablecourses', 'admin'), ''));
 628      $options = [
 629          0 => new lang_string('searchallavailablecourses_off', 'admin'),
 630          1 => new lang_string('searchallavailablecourses_on', 'admin')
 631      ];
 632      $temp->add(new admin_setting_configselect('searchallavailablecourses',
 633              new lang_string('searchallavailablecourses', 'admin'),
 634              new lang_string('searchallavailablecoursesdesc', 'admin'),
 635              0, $options));
 636      $temp->add(new admin_setting_configcheckbox('searchincludeallcourses',
 637          new lang_string('searchincludeallcourses', 'admin'), new lang_string('searchincludeallcourses_desc', 'admin'),
 638          0));
 639  
 640      // Search display options.
 641      $temp->add(new admin_setting_heading('searchdisplay', new lang_string('searchdisplay', 'admin'), ''));
 642      $temp->add(new admin_setting_configcheckbox('searchenablecategories',
 643          new lang_string('searchenablecategories', 'admin'),
 644          new lang_string('searchenablecategories_desc', 'admin'),
 645          0));
 646      $options = [];
 647      foreach (\core_search\manager::get_search_area_categories() as $category) {
 648          $options[$category->get_name()] = $category->get_visiblename();
 649      }
 650      $temp->add(new admin_setting_configselect('searchdefaultcategory',
 651          new lang_string('searchdefaultcategory', 'admin'),
 652          new lang_string('searchdefaultcategory_desc', 'admin'),
 653          \core_search\manager::SEARCH_AREA_CATEGORY_ALL, $options));
 654      $temp->add(new admin_setting_configcheckbox('searchhideallcategory',
 655          new lang_string('searchhideallcategory', 'admin'),
 656          new lang_string('searchhideallcategory_desc', 'admin'),
 657          0));
 658  
 659      $temp->add(new admin_setting_heading('searchmanagement', new lang_string('searchmanagement', 'admin'),
 660              new lang_string('searchmanagement_desc', 'admin')));
 661  
 662      // Get list of search engines including those with alternate settings.
 663      $searchenginequeryonlyselect = new admin_setting_configselect('searchenginequeryonly',
 664              new lang_string('searchenginequeryonly', 'admin'),
 665              new lang_string('searchenginequeryonly_desc', 'admin'), '', function() use($engines) {
 666                  $options = ['' => new lang_string('searchenginequeryonly_none', 'admin')];
 667                  foreach ($engines as $name => $display) {
 668                      $options[$name] = $display;
 669  
 670                      $classname = '\search_' . $name . '\engine';
 671                      $engine = new $classname;
 672                      if ($engine->has_alternate_configuration()) {
 673                          $options[$name . '-alternate'] =
 674                                  new lang_string('searchenginealternatesettings', 'admin', $display);
 675                      }
 676                  }
 677                  return $options;
 678              });
 679      $searchenginequeryonlyselect->set_validate_function(function(string $value): string {
 680          global $CFG;
 681  
 682          // Check nobody's setting the indexing and query-only server to the same one.
 683          if (isset($CFG->searchengine) && $CFG->searchengine === $value) {
 684              return get_string('searchenginequeryonlysame', 'admin');
 685          } else {
 686              return '';
 687          }
 688      });
 689      $temp->add($searchenginequeryonlyselect);
 690      $temp->add(new admin_setting_configcheckbox('searchbannerenable',
 691              new lang_string('searchbannerenable', 'admin'), new lang_string('searchbannerenable_desc', 'admin'),
 692              0));
 693      $temp->add(new admin_setting_confightmleditor('searchbanner',
 694              new lang_string('searchbanner', 'admin'), '', ''));
 695  
 696      $ADMIN->add('searchplugins', $temp);
 697      $ADMIN->add('searchplugins', new admin_externalpage('searchareas', new lang_string('searchareas', 'admin'),
 698          new moodle_url('/admin/searchareas.php')));
 699  
 700      core_collator::asort_objects_by_property($pages, 'visiblename');
 701      foreach ($pages as $page) {
 702          $ADMIN->add('searchplugins', $page);
 703      }
 704  }
 705  
 706  /// Add all admin tools
 707  if ($hassiteconfig) {
 708      $ADMIN->add('modules', new admin_category('tools', new lang_string('tools', 'admin')));
 709      $ADMIN->add('tools', new admin_externalpage('managetools', new lang_string('toolsmanage', 'admin'),
 710                                                       $CFG->wwwroot . '/' . $CFG->admin . '/tools.php'));
 711  }
 712  
 713  // Now add various admin tools.
 714  $plugins = core_plugin_manager::instance()->get_plugins_of_type('tool');
 715  core_collator::asort_objects_by_property($plugins, 'displayname');
 716  foreach ($plugins as $plugin) {
 717      /** @var \core\plugininfo\tool $plugin */
 718      $plugin->load_settings($ADMIN, null, $hassiteconfig);
 719  }
 720  
 721  // Now add the Cache plugins
 722  if ($hassiteconfig) {
 723      $ADMIN->add('modules', new admin_category('cache', new lang_string('caching', 'cache')));
 724      $ADMIN->add('cache', new admin_externalpage('cacheconfig', new lang_string('cacheconfig', 'cache'), $CFG->wwwroot .'/cache/admin.php'));
 725      $ADMIN->add('cache', new admin_externalpage('cachetestperformance', new lang_string('testperformance', 'cache'), $CFG->wwwroot . '/cache/testperformance.php'));
 726      $ADMIN->add('cache', new admin_category('cachestores', new lang_string('cachestores', 'cache')));
 727      $ADMIN->locate('cachestores')->set_sorting(true);
 728      foreach (core_component::get_plugin_list('cachestore') as $plugin => $path) {
 729          $settingspath = $path.'/settings.php';
 730          if (file_exists($settingspath)) {
 731              $settings = new admin_settingpage('cachestore_'.$plugin.'_settings', new lang_string('pluginname', 'cachestore_'.$plugin), 'moodle/site:config');
 732              include($settingspath);
 733              $ADMIN->add('cachestores', $settings);
 734          }
 735      }
 736  }
 737  
 738  // Add Calendar type settings.
 739  if ($hassiteconfig) {
 740      $ADMIN->add('modules', new admin_category('calendartype', new lang_string('calendartypes', 'calendar')));
 741      $plugins = core_plugin_manager::instance()->get_plugins_of_type('calendartype');
 742      core_collator::asort_objects_by_property($plugins, 'displayname');
 743      foreach ($plugins as $plugin) {
 744          /** @var \core\plugininfo\calendartype $plugin */
 745          $plugin->load_settings($ADMIN, 'calendartype', $hassiteconfig);
 746      }
 747  }
 748  
 749  // Content bank content types.
 750  if ($hassiteconfig) {
 751      $ADMIN->add('modules', new admin_category('contentbanksettings', new lang_string('contentbank')));
 752      $temp = new admin_settingpage('managecontentbanktypes', new lang_string('managecontentbanktypes'));
 753      $temp->add(new admin_setting_managecontentbankcontenttypes());
 754      $ADMIN->add('contentbanksettings', $temp);
 755      $plugins = core_plugin_manager::instance()->get_plugins_of_type('contenttype');
 756      foreach ($plugins as $plugin) {
 757          /** @var \core\plugininfo\contentbank $plugin */
 758          $plugin->load_settings($ADMIN, 'contentbanksettings', $hassiteconfig);
 759      }
 760  }
 761  
 762  /// Add all local plugins - must be always last!
 763  if ($hassiteconfig) {
 764      $ADMIN->add('modules', new admin_category('localplugins', new lang_string('localplugins')));
 765      $ADMIN->add('localplugins', new admin_externalpage('managelocalplugins', new lang_string('localpluginsmanage'),
 766                                                          $CFG->wwwroot . '/' . $CFG->admin . '/localplugins.php'));
 767  }
 768  
 769  // Extend settings for each local plugin. Note that their settings may be in any part of the
 770  // settings tree and may be visible not only for administrators.
 771  $plugins = core_plugin_manager::instance()->get_plugins_of_type('local');
 772  core_collator::asort_objects_by_property($plugins, 'displayname');
 773  foreach ($plugins as $plugin) {
 774      /** @var \core\plugininfo\local $plugin */
 775      $plugin->load_settings($ADMIN, null, $hassiteconfig);
 776  }