From 409ad1d60ad84bc506e710183670f5616f81e380 Mon Sep 17 00:00:00 2001 From: Yair Spielmann Date: Fri, 16 Jun 2017 16:13:37 +0100 Subject: [PATCH] MDL-57734 admin: New setting for when to use the noindex meta tag --- admin/settings/security.php | 5 +++++ lang/en/admin.php | 5 +++++ lib/outputrenderers.php | 10 ++++++++++ login/index.php | 6 ------ login/signup.php | 6 ------ 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/admin/settings/security.php b/admin/settings/security.php index c36a4248b5f..34185cb48ac 100644 --- a/admin/settings/security.php +++ b/admin/settings/security.php @@ -18,6 +18,11 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $temp->add(new admin_setting_configcheckbox('forceloginforprofiles', new lang_string('forceloginforprofiles', 'admin'), new lang_string('configforceloginforprofiles', 'admin'), 1)); $temp->add(new admin_setting_configcheckbox('forceloginforprofileimage', new lang_string('forceloginforprofileimage', 'admin'), new lang_string('forceloginforprofileimage_help', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('opentogoogle', new lang_string('opentogoogle', 'admin'), new lang_string('configopentogoogle', 'admin'), 0)); + $temp->add(new admin_setting_configselect('allowindexing', new lang_string('allowindexing', 'admin'), new lang_string('allowindexing_desc', 'admin'), + 0, + array(0 => new lang_string('allowindexingexceptlogin', 'admin'), + 1 => new lang_string('allowindexingeverywhere', 'admin'), + 2 => new lang_string('allowindexingnowhere', 'admin')))); $temp->add(new admin_setting_pickroles('profileroles', new lang_string('profileroles','admin'), new lang_string('configprofileroles', 'admin'), diff --git a/lang/en/admin.php b/lang/en/admin.php index b9bb1e5cded..dca2305d5fe 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -49,6 +49,11 @@ $string['allowcoursethemes'] = 'Allow course themes'; $string['allowediplist'] = 'Allowed IP list'; $string['allowedemaildomains'] = 'Allowed email domains'; $string['allowemailaddresses'] = 'Allowed email domains'; +$string['allowindexing'] = 'Allow indexing by search engines'; +$string['allowindexing_desc'] = 'This determines whether to allow search engines to index your site. "Everywhere" will allow the search engines to search everywhere including login and signup pages, which means sites with Force Login turned on are still indexed. To avoid the risk of spam involved with the signup page being searchable, use "Everywhere except login and signup pages". "Nowhere" will tell search engines not to index any page. Note this is only a tag in the header of the site. It is up to the search engine to respect the tag.'; +$string['allowindexingeverywhere'] = 'Everywhere'; +$string['allowindexingexceptlogin'] = 'Everywhere except login and signup pages'; +$string['allowindexingnowhere'] = 'Nowhere'; $string['allowusermailcharset'] = 'Allow user to select character set'; $string['allowframembedding'] = 'Allow frame embedding'; $string['allowframembedding_help'] = 'If enabled, this site may be embedded in a frame in a remote system, as recommended when using the \'Publish as LTI tool\' enrolment plugin. Otherwise, it is recommended to leave frame embedding disabled for security reasons.'; diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 0aae68d5ccb..15705a87fd6 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -650,6 +650,16 @@ class core_renderer extends renderer_base { 'type' => $type, 'title' => $alt->title, 'href' => $alt->url)); } + // Add noindex tag if relevant page and setting applied. + $allowindexing = isset($CFG->allowindexing) ? $CFG->allowindexing : 0; + $loginpages = array('login-index', 'login-signup'); + if ($allowindexing == 2 || ($allowindexing == 0 && in_array($this->page->pagetype, $loginpages))) { + if (!isset($CFG->additionalhtmlhead)) { + $CFG->additionalhtmlhead = ''; + } + $CFG->additionalhtmlhead .= ''; + } + if (!empty($CFG->additionalhtmlhead)) { $output .= "\n".$CFG->additionalhtmlhead; } diff --git a/login/index.php b/login/index.php index dec075c3c2f..ef92109deb9 100644 --- a/login/index.php +++ b/login/index.php @@ -27,12 +27,6 @@ require('../config.php'); require_once('lib.php'); -// Try to prevent searching for sites that allow sign-up. -if (!isset($CFG->additionalhtmlhead)) { - $CFG->additionalhtmlhead = ''; -} -$CFG->additionalhtmlhead .= ''; - redirect_if_major_upgrade_required(); $testsession = optional_param('testsession', 0, PARAM_INT); // test session works properly diff --git a/login/signup.php b/login/signup.php index dc6774dd0ee..03321e459e6 100644 --- a/login/signup.php +++ b/login/signup.php @@ -28,12 +28,6 @@ require('../config.php'); require_once($CFG->dirroot . '/user/editlib.php'); require_once($CFG->libdir . '/authlib.php'); -// Try to prevent searching for sites that allow sign-up. -if (!isset($CFG->additionalhtmlhead)) { - $CFG->additionalhtmlhead = ''; -} -$CFG->additionalhtmlhead .= ''; - if (!$authplugin = signup_is_enabled()) { print_error('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.'); }