r23166 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23165‎ | r23166 | r23167 >
Date:15:51, 21 June 2007
Author:raymond
Status:old
Tags:
Comment:
* (bug 9415) Added options to Special:Protect to allow setting of per-page robot
policies. This can be done only by users with the 'editrobots' permission
Based on a patch of AmiDaniel
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/ProtectionForm.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesDe.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1182,6 +1182,7 @@
11831183 'protect-summary-cascade',
11841184 'protect-expiring',
11851185 'protect-cascade',
 1186+ 'protect-robotspolicy',
11861187 'restriction-type',
11871188 'restriction-level',
11881189 'minimum-size',
Index: trunk/phase3/includes/ProtectionForm.php
@@ -43,6 +43,7 @@
4444 // but the db allows multiples separated by commas.
4545 $this->mRestrictions[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
4646 }
 47+ $this->mRestrictions['robots'] = implode( ',', $this->mTitle->getRestrictions( 'robots' ) );
4748
4849 $this->mCascade = $this->mTitle->areRestrictionsCascading();
4950
@@ -72,9 +73,17 @@
7374 $this->mRestrictions[$action] = $val;
7475 }
7576 }
 77+
 78+ // Read checkboxex only if user is allowed to change robots policy, otherwise keep previous policy
 79+ if ( $wgUser->isAllowed( 'editrobots' ) ) {
 80+ $robotspolicy = $wgRequest->getBool( 'mwProtect-robots-noindex' ) ? 'noindex' : 'index';
 81+ $robotspolicy .= $wgRequest->getBool( 'mwProtect-robots-nofollow' ) ? ',nofollow' : ',follow';
 82+ // 'index,follow' is default, no need to set this explicitly at this point; is done at Article::View
 83+ $this->mRestrictions['robots'] = ( $robotspolicy == 'index,follow' ) ? '' : $robotspolicy;
 84+ }
7685 }
7786 }
78 -
 87+
7988 function execute() {
8089 global $wgRequest;
8190 if( $wgRequest->wasPosted() ) {
@@ -199,7 +208,7 @@
200209 }
201210
202211 function buildForm() {
203 - global $wgUser;
 212+ global $wgUser, $wgRestrictionTypes;
204213
205214 $out = '';
206215 if( !$this->disabled ) {
@@ -223,14 +232,17 @@
224233 $out .= "<tr>\n";
225234 foreach( $this->mRestrictions as $action => $required ) {
226235 /* Not all languages have V_x <-> N_x relation */
227 - $out .= "<th>" . wfMsgHtml( 'restriction-' . $action ) . "</th>\n";
 236+ if ( in_array( $action, $wgRestrictionTypes ) )
 237+ $out .= "<th>" . wfMsgHtml( 'restriction-' . $action ) . "</th>\n";
228238 }
229239 $out .= "</tr>\n";
230240 $out .= "<tr>\n";
231241 foreach( $this->mRestrictions as $action => $selected ) {
232 - $out .= "<td>\n";
233 - $out .= $this->buildSelector( $action, $selected );
234 - $out .= "</td>\n";
 242+ if ( in_array( $action, $wgRestrictionTypes ) ) {
 243+ $out .= "<td>\n";
 244+ $out .= $this->buildSelector( $action, $selected );
 245+ $out .= "</td>\n";
 246+ }
235247 }
236248 $out .= "</tr>\n";
237249
@@ -249,6 +261,7 @@
250262 if( !$this->disabled )
251263 $out .= '<tr><td></td><td>' . $this->buildWatchInput() . "</td></tr>\n";
252264
 265+ $out .= $this->buildRobotsInput();
253266 $out .= $this->buildExpiryInput();
254267
255268 if( !$this->disabled ) {
@@ -317,6 +330,20 @@
318331 return $ci;
319332 }
320333
 334+ function buildRobotsInput() {
 335+ global $wgUser;
 336+ $robotsallowed = $wgUser->isAllowed( 'editrobots' ) ? array() : array( 'disabled' => 'disabled' );
 337+ $noindexset = ( isset( $this->mRestrictions['robots'] ) && strstr( $this->mRestrictions['robots'], 'noindex' ) ) ? true : false;
 338+ $nofollowset = ( isset( $this->mRestrictions['robots'] ) && strstr( $this->mRestrictions['robots'], 'nofollow' ) ) ? true : false;
 339+ $ret = "<tr><td align=\"right\">";
 340+ $ret .= Xml::label( wfMsg( 'protect-robotspolicy' ), 'mwProtect-robots-label' );
 341+ $ret .= "</td> <td align=\"left\" width=\"60\">";
 342+ $ret .= Xml::checkLabel( 'noindex', 'mwProtect-robots-noindex', 'mwProtect-robots-noindex', $noindexset, $robotsallowed );
 343+ $ret .= Xml::checkLabel( 'nofollow', 'mwProtect-robots-nofollow', 'mwProtect-robots-nofollow', $nofollowset, $robotsallowed );
 344+ $ret .= "</td></tr>";
 345+ return $ret;
 346+ }
 347+
321348 function buildExpiryInput() {
322349 $attribs = array( 'id' => 'expires' ) + $this->disabledAttrib;
323350 return '<tr>'
Index: trunk/phase3/includes/Article.php
@@ -641,6 +641,8 @@
642642 } elseif( isset( $wgNamespaceRobotPolicies[$ns] ) ) {
643643 # Honour customised robot policies for this namespace
644644 $policy = $wgNamespaceRobotPolicies[$ns];
 645+ } elseif ( $this->mTitle->getRestrictions( 'robots' ) ) {
 646+ $policy = implode( ',', $this->mTitle->getRestrictions( 'robots' ) );
645647 } else {
646648 # Default to encourage indexing and following links
647649 $policy = 'index,follow';
@@ -1675,6 +1677,7 @@
16761678 $current = array();
16771679 foreach( $wgRestrictionTypes as $action )
16781680 $current[$action] = implode( '', $this->mTitle->getRestrictions( $action ) );
 1681+ $current['robots'] = implode( '', $this->mTitle->getRestrictions( 'robots' ) );
16791682
16801683 $current = Article::flattenRestrictions( $current );
16811684 $updated = Article::flattenRestrictions( $limit );
@@ -1710,7 +1713,9 @@
17111714 foreach( $limit as $action => $restrictions ) {
17121715 # Check if the group level required to edit also can protect pages
17131716 # Otherwise, people who cannot normally protect can "protect" pages via transclusion
1714 - $cascade = ( $cascade && isset($wgGroupPermissions[$restrictions]['protect']) && $wgGroupPermissions[$restrictions]['protect'] );
 1717+ if ( in_array( $restrictions, $wgRestrictionTypes ) ) {
 1718+ $cascade = ( $cascade && isset($wgGroupPermissions[$restrictions]['protect']) && $wgGroupPermissions[$restrictions]['protect'] );
 1719+ }
17151720 }
17161721
17171722 $cascade_description = '';
Index: trunk/phase3/includes/Title.php
@@ -940,6 +940,9 @@
941941 if( $this->getNamespace() == NS_SPECIAL )
942942 return true;
943943
 944+ if ( $this->getRestrictions( 'robots' ) && $this->getRestrictions( 'robots' ) != '' )
 945+ return true;
 946+
944947 # Check regular protection levels
945948 if( $action == 'edit' || $action == '' ) {
946949 $r = $this->getRestrictions( 'edit' );
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1063,6 +1063,7 @@
10641064 $wgGroupPermissions['sysop']['upload_by_url'] = true;
10651065 $wgGroupPermissions['sysop']['ipblock-exempt'] = true;
10661066 $wgGroupPermissions['sysop']['blockemail'] = true;
 1067+$wgGroupPermissions['sysop']['editrobots'] = true;
10671068
10681069 // Permission to change users' group assignments
10691070 $wgGroupPermissions['bureaucrat']['userrights'] = true;
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1839,6 +1839,7 @@
18401840 'protect-summary-cascade' => 'cascading',
18411841 'protect-expiring' => 'expires $1 (UTC)',
18421842 'protect-cascade' => 'Protect pages included in this page (cascading protection)',
 1843+'protect-robotspolicy' => 'Robot policy:',
18431844 'restriction-type' => 'Permission:',
18441845 'restriction-level' => 'Restriction level:',
18451846 'minimum-size' => 'Min size',
Index: trunk/phase3/languages/messages/MessagesDe.php
@@ -1442,6 +1442,7 @@
14431443 'protect-summary-cascade' => 'kaskadierend',
14441444 'protect-expiring' => 'bis $1 (UTC)',
14451445 'protect-cascade' => 'Kaskadierende Sperre – alle in diese Seite eingebundenen Vorlagen werden ebenfalls gesperrt.',
 1446+'protect-robotspolicy' => 'Anweisung für Suchroboter:',
14461447 'restriction-type' => 'Schutzstatus',
14471448 'restriction-level' => 'Schutzhöhe',
14481449 'minimum-size' => 'Mindestgröße:',
Index: trunk/phase3/RELEASE-NOTES
@@ -95,6 +95,8 @@
9696 * Throw a showstopper exception when a hook function fails to return a value.
9797 Forgetting to give a 'true' return value is a very common error which tends
9898 to cause hard-to-track-down interactions between extensions.
 99+* (bug 9415) Added options to Special:Protect to allow setting of per-page robot
 100+ policies. This can be done only by users with the 'editrobots' permission
99101
100102 == Bugfixes since 1.10 ==
101103

Follow-up revisions

RevisionCommit summaryAuthorDate
r23203Merged revisions 23120-23202 via svnmerge from...david09:07, 22 June 2007
r23226Revert r23166, 23178, 23179, and probably some other related bits....brion14:52, 22 June 2007
r23407Merged revisions 23203-23405 via svnmerge from...david23:00, 25 June 2007

Status & tagging log