r54616 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54615‎ | r54616 | r54617 >
Date:23:55, 7 August 2009
Author:nad
Status:deferred
Tags:
Comment:
move robots meta to UserGetRights hoom instead of OutputPageBeforeHTML
Modified paths:
  • /trunk/extensions/SimpleSecurity/SimpleSecurity_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SimpleSecurity/SimpleSecurity_body.php
@@ -20,9 +20,9 @@
2121
2222 # Add our hooks
2323 $wgHooks['UserGetRights'][] = $this;
24 - $wgHooks['OutputPageBeforeHTML'][] = $this;
2524 if ( $wgSecurityMagicIf ) $wgParser->setFunctionHook( $wgSecurityMagicIf, array( $this, 'ifUserCan' ) );
2625 if ( $wgSecurityMagicGroup ) $wgParser->setFunctionHook( $wgSecurityMagicGroup, array( $this, 'ifGroup' ) );
 26+ if ( $wgSecurityRenderInfo ) $wgHooks['OutputPageBeforeHTML'][] = $this;
2727 if ( $wgSecurityAllowUnreadableLinks ) $wgHooks['BeforePageDisplay'][] = $this;
2828
2929 # Add a new log type
@@ -108,48 +108,42 @@
109109 * Also make restricted pages not archive by robots
110110 */
111111 public function onOutputPageBeforeHTML( &$out, &$text ) {
112 - global $wgUser, $wgTitle, $wgSecurityRenderInfo;
 112+ global $wgUser, $wgTitle;
113113 $title = $wgTitle;
114114
115 - # Any restrictions?
 115+ # Render info
116116 if ( is_object( $title ) && $title->exists() && count( $this->info['LS'] ) + count( $this->info['PR'] ) ) {
117117
118 - # Don't archive restricted pages
119 - $out->addMeta( "robots", "noarchive" );
 118+ $rights = $wgUser->getRights();
 119+ $title->getRestrictions( false );
 120+ $reqgroups = $title->mRestrictions;
 121+ $sysop = in_array( 'sysop', $wgUser->getGroups() );
120122
121 - # Render info if enabled
122 - if ( $wgSecurityRenderInfo ) {
123 - $rights = $wgUser->getRights();
124 - $title->getRestrictions( false );
125 - $reqgroups = $title->mRestrictions;
126 - $sysop = in_array( 'sysop', $wgUser->getGroups() );
127 -
128 - # Build restrictions text
129 - $itext = "<ul>\n";
130 - foreach ( $this->info as $source => $rules ) if ( !( $sysop && $source === 'CR' ) ) {
131 - foreach ( $rules as $info ) {
132 - list( $action, $groups, $comment ) = $info;
133 - $gtext = $this->groupText( $groups );
134 - $itext .= "<li>" . wfMsg( 'security-inforestrict', "<b>$action</b>", $gtext ) . " $comment</li>\n";
135 - }
 123+ # Build restrictions text
 124+ $itext = "<ul>\n";
 125+ foreach ( $this->info as $source => $rules ) if ( !( $sysop && $source === 'CR' ) ) {
 126+ foreach ( $rules as $info ) {
 127+ list( $action, $groups, $comment ) = $info;
 128+ $gtext = $this->groupText( $groups );
 129+ $itext .= "<li>" . wfMsg( 'security-inforestrict', "<b>$action</b>", $gtext ) . " $comment</li>\n";
136130 }
137 - if ( $sysop ) $itext .= "<li>" . wfMsg( 'security-infosysops' ) . "</li>\n";
138 - $itext .= "</ul>\n";
 131+ }
 132+ if ( $sysop ) $itext .= "<li>" . wfMsg( 'security-infosysops' ) . "</li>\n";
 133+ $itext .= "</ul>\n";
139134
140 - # Add some javascript to allow toggling the security-info
141 - $out->addScript( "<script type='text/javascript'>
142 - function toggleSecurityInfo() {
143 - var info = document.getElementById('security-info');
144 - info.style.display = info.style.display ? '' : 'none';
145 - }</script>"
146 - );
 135+ # Add some javascript to allow toggling the security-info
 136+ $out->addScript( "<script type='text/javascript'>
 137+ function toggleSecurityInfo() {
 138+ var info = document.getElementById('security-info');
 139+ info.style.display = info.style.display ? '' : 'none';
 140+ }</script>"
 141+ );
147142
148 - # Add info-toggle before title and hidden info after title
149 - $link = "<a href='javascript:'>" . wfMsg( 'security-info-toggle' ) . "</a>";
150 - $link = "<span onClick='toggleSecurityInfo()'>$link</span>";
151 - $info = "<div id='security-info-toggle'>" . wfMsg( 'security-info', $link ) . "</div>\n";
152 - $text = "$info<div id='security-info' style='display:none'>$itext</div>\n$text";
153 - }
 143+ # Add info-toggle before title and hidden info after title
 144+ $link = "<a href='javascript:'>" . wfMsg( 'security-info-toggle' ) . "</a>";
 145+ $link = "<span onClick='toggleSecurityInfo()'>$link</span>";
 146+ $info = "<div id='security-info-toggle'>" . wfMsg( 'security-info', $link ) . "</div>\n";
 147+ $text = "$info<div id='security-info' style='display:none'>$itext</div>\n$text";
154148 }
155149
156150 return true;
@@ -172,7 +166,7 @@
173167 * - clears and populates the info array
174168 */
175169 public function onUserGetRights( &$user, &$rights ) {
176 - global $wgGroupPermissions, $wgTitle, $wgRequest, $wgPageRestrictions;
 170+ global $wgGroupPermissions, $wgOut, $wgTitle, $wgRequest, $wgPageRestrictions;
177171
178172 # Hack to prevent specialpage operations on unreadable pages
179173 if ( !is_object( $wgTitle ) ) return true;
@@ -210,10 +204,12 @@
211205 if ( array_intersect( $groups, $g ) ) $rights[] = $a;
212206 }
213207
214 - # If title is not readable by user, remove the read and move rights
 208+ # If title is not readable by user, remove the read and move rights, and tell robots not to archive
215209 if ( !in_array( 'sysop', $groups ) && !$this->userCanReadTitle( $user, $title, $error ) ) {
216210 foreach ( $rights as $i => $right ) if ( $right === 'read' || $right === 'move' ) unset( $rights[$i] );
217211 # $this->info['CR'] = array('read', '', '');
 212+ $wgOut->addMeta( 'robots', 'noarchive' );
 213+
218214 }
219215
220216 return true;

Status & tagging log