Page MenuHomePhabricator

robots-protect.diff

Authored By
bzimport
Nov 21 2014, 9:40 PM
Size
6 KB
Referenced Files
None
Subscribers
None

robots-protect.diff

Index: /home/amidaniel/php/mediawiki/phase3/includes/Article.php
===================================================================
--- /home/amidaniel/php/mediawiki/phase3/includes/Article.php (revision 22619)
+++ /home/amidaniel/php/mediawiki/phase3/includes/Article.php (working copy)
@@ -641,6 +641,8 @@
} elseif( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
# Honour customised robot policies for this namespace
$policy = $wgNamespaceRobotPolicies[$ns];
+ } elseif ( $this->mTitle->getRestrictions( 'robots' ) ) {
+ $policy = implode( ',', $this->mTitle->getRestrictions( 'robots' ) );
} else {
# Default to encourage indexing and following links
$policy = 'index,follow';
@@ -1675,6 +1677,7 @@
$current = array();
foreach( $wgRestrictionTypes as $action )
$current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
+ $current['robots'] = implode( '', $this->mTitle->getRestrictions( 'robots' ) );
$current = Article::flattenRestrictions( $current );
$updated = Article::flattenRestrictions( $limit );
Index: /home/amidaniel/php/mediawiki/phase3/includes/DefaultSettings.php
===================================================================
--- /home/amidaniel/php/mediawiki/phase3/includes/DefaultSettings.php (revision 22619)
+++ /home/amidaniel/php/mediawiki/phase3/includes/DefaultSettings.php (working copy)
@@ -1056,6 +1056,7 @@
$wgGroupPermissions['sysop']['autoconfirmed'] = true;
$wgGroupPermissions['sysop']['upload_by_url'] = true;
$wgGroupPermissions['sysop']['ipblock-exempt'] = true;
+$wgGroupPermissions['sysop']['editrobots'] = true;
// Permission to change users' group assignments
$wgGroupPermissions['bureaucrat']['userrights'] = true;
Index: /home/amidaniel/php/mediawiki/phase3/languages/messages/MessagesEn.php
===================================================================
--- /home/amidaniel/php/mediawiki/phase3/languages/messages/MessagesEn.php (revision 22619)
+++ /home/amidaniel/php/mediawiki/phase3/languages/messages/MessagesEn.php (working copy)
@@ -1856,6 +1856,7 @@
'protect-summary-cascade' => 'cascading',
'protect-expiring' => 'expires $1 (UTC)',
'protect-cascade' => 'Cascading protection - protect any pages included in this page.',
+'protect-robotspolicy' => 'Robot policy:',
'restriction-type' => 'Permission:',
'restriction-level' => 'Restriction level:',
'minimum-size' => 'Min size',
Index: /home/amidaniel/php/mediawiki/phase3/includes/ProtectionForm.php
===================================================================
--- /home/amidaniel/php/mediawiki/phase3/includes/ProtectionForm.php (revision 22619)
+++ /home/amidaniel/php/mediawiki/phase3/includes/ProtectionForm.php (working copy)
@@ -43,6 +43,7 @@
// but the db allows multiples separated by commas.
$this->mRestrictions[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
}
+ $this->mRestrictions['robots'] = implode( '', $this->mTitle->getRestrictions( 'robots' ) );
$this->mCascade = $this->mTitle->areRestrictionsCascading();
@@ -72,6 +73,21 @@
$this->mRestrictions[$action] = $val;
}
}
+
+ $robotspolicy;
+ if ( $wgRequest->getVal( 'mwProtect-robots-noindex' ) )
+ $robotspolicy = 'noindex';
+ else
+ $robotspolicy = 'index';
+ if ( $wgRequest->getVal( 'mwProtect-robots-nofollow' ))
+ $robotspolicy .= ',nofollow';
+ else
+ $robotspolicy .= ',follow';
+
+ if ( $robotspolicy != 'index,follow')
+ $this->mRestrictions['robots'] = $robotspolicy;
+ else
+ $this->mRestrictions['robots'] = '';
}
}
@@ -192,7 +208,7 @@
}
function buildForm() {
- global $wgUser;
+ global $wgUser, $wgRestrictionTypes;
$out = '';
if( !$this->disabled ) {
@@ -216,7 +232,8 @@
$out .= "<tr>\n";
foreach( $this->mRestrictions as $action => $required ) {
/* Not all languages have V_x <-> N_x relation */
- $out .= "<th>" . wfMsgHtml( 'restriction-' . $action ) . "</th>\n";
+ if (in_array( $action, $wgRestrictionTypes ) )
+ $out .= "<th>" . wfMsgHtml( 'restriction-' . $action ) . "</th>\n";
}
$out .= "</tr>\n";
$out .= "<tr>\n";
@@ -221,9 +238,11 @@
$out .= "</tr>\n";
$out .= "<tr>\n";
foreach( $this->mRestrictions as $action => $selected ) {
- $out .= "<td>\n";
- $out .= $this->buildSelector( $action, $selected );
- $out .= "</td>\n";
+ if (in_array( $action, $wgRestrictionTypes ) ) {
+ $out .= "<td>\n";
+ $out .= $this->buildSelector( $action, $selected );
+ $out .= "</td>\n";
+ }
}
$out .= "</tr>\n";
@@ -240,6 +259,7 @@
$out .= "<table>\n";
$out .= "<tbody>\n";
+ $out .= $this->buildRobotsInput();
$out .= $this->buildExpiryInput();
if( !$this->disabled ) {
@@ -308,6 +328,34 @@
return $ci;
}
+ function buildRobotsInput() {
+ global $wgUser;
+ $robotsallowed = $wgUser->isAllowed( 'editrobots' )
+ ?array():array('disabled' => 'disabled');
+
+ $noindexset = 0;
+ $nofollowset = 0;
+ if ( isset($this->mRestrictions['robots']) ) {
+ if ( strstr( $this->mRestrictions['robots'], 'noindex') )
+ $noindexset = true;
+ if ( strstr( $this->mRestrictions['robots'], 'nofollow') )
+ $nofollowset = true;
+ }
+
+ $ret = "<tr><td align=\"right\">";
+ $ret .= wfElement('label', array ('id' => 'mwProtect-robots-label'),
+ wfMsg( 'protect-robotspolicy' ));
+ $id = 'mwProtect-robots-';
+
+ $ret .= "</td> <td align=\"left\" width=\"60\">";
+ $ret .= wfCheckLabel( 'noindex', $id . 'noindex', $id . 'noindex',
+ $noindexset, $robotsallowed);
+ $ret .= wfCheckLabel( 'nofollow', $id . 'nofollow', $id . 'nofollow',
+ $nofollowset, $robotsallowed);
+ $ret .= "</td></tr>";
+ return $ret;
+ }
+
function buildExpiryInput() {
$id = 'mwProtect-expiry';
Index: /home/amidaniel/php/mediawiki/phase3/RELEASE-NOTES
===================================================================
--- /home/amidaniel/php/mediawiki/phase3/RELEASE-NOTES (revision 22619)
+++ /home/amidaniel/php/mediawiki/phase3/RELEASE-NOTES (working copy)
@@ -49,7 +49,9 @@
* Improved thumb.php error handling
* Display file history on local image description pages of shared images
* Added $wgArticleRobotPolicies
-
+* Added options to Special:Protect to allow setting of per-page robot
+ policies. This can be done only by users with the 'editrobots'
+ permission.
== Bugfixes since 1.10 ==
Index: /home/amidaniel/php/mediawiki/phase3/includes/Title.php
===================================================================
--- /home/amidaniel/php/mediawiki/phase3/includes/Title.php (revision 22619)
+++ /home/amidaniel/php/mediawiki/phase3/includes/Title.php (working copy)
@@ -933,6 +933,9 @@
if( $this->getNamespace() == NS_SPECIAL )
return true;
+ if ( $this->getRestrictions('robots') && $this->getRestrictions( 'robots' ) != '' )
+ return true;
+
# Check regular protection levels
if( $action == 'edit' || $action == '' ) {
$r = $this->getRestrictions( 'edit' );

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3446
Default Alt Text
robots-protect.diff (6 KB)

Event Timeline