r54615 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54614‎ | r54615 | r54616 >
Date:23:34, 7 August 2009
Author:nad
Status:deferred
Tags:
Comment:
add meta tag so that restricted pages are not archived by robots
Modified paths:
  • /trunk/extensions/SimpleSecurity/SimpleSecurity.php (modified) (history)
  • /trunk/extensions/SimpleSecurity/SimpleSecurity_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SimpleSecurity/SimpleSecurity_body.php
@@ -20,10 +20,10 @@
2121
2222 # Add our hooks
2323 $wgHooks['UserGetRights'][] = $this;
 24+ $wgHooks['OutputPageBeforeHTML'][] = $this;
2425 if ( $wgSecurityMagicIf ) $wgParser->setFunctionHook( $wgSecurityMagicIf, array( $this, 'ifUserCan' ) );
2526 if ( $wgSecurityMagicGroup ) $wgParser->setFunctionHook( $wgSecurityMagicGroup, array( $this, 'ifGroup' ) );
2627 if ( $wgSecurityAllowUnreadableLinks ) $wgHooks['BeforePageDisplay'][] = $this;
27 - if ( $wgSecurityRenderInfo ) $wgHooks['OutputPageBeforeHTML'][] = $this;
2828
2929 # Add a new log type
3030 $wgLogTypes[] = 'security';
@@ -105,44 +105,51 @@
106106
107107 /**
108108 * Render security info if any restrictions on this title
 109+ * Also make restricted pages not archive by robots
109110 */
110111 public function onOutputPageBeforeHTML( &$out, &$text ) {
111 - global $wgUser, $wgTitle;
 112+ global $wgUser, $wgTitle, $wgSecurityRenderInfo;
 113+ $title = $wgTitle;
112114
113 - $title = $wgTitle;
114 - # Render security info if any
 115+ # Any restrictions?
115116 if ( is_object( $title ) && $title->exists() && count( $this->info['LS'] ) + count( $this->info['PR'] ) ) {
116117
117 - $rights = $wgUser->getRights();
118 - $title->getRestrictions( false );
119 - $reqgroups = $title->mRestrictions;
120 - $sysop = in_array( 'sysop', $wgUser->getGroups() );
 118+ # Don't archive restricted pages
 119+ $out->addMeta( "robots", "noarchive" );
121120
122 - # Build restrictions text
123 - $itext = "<ul>\n";
124 - foreach ( $this->info as $source => $rules ) if ( !( $sysop && $source === 'CR' ) ) {
125 - foreach ( $rules as $info ) {
126 - list( $action, $groups, $comment ) = $info;
127 - $gtext = $this->groupText( $groups );
128 - $itext .= "<li>" . wfMsg( 'security-inforestrict', "<b>$action</b>", $gtext ) . " $comment</li>\n";
 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+ }
129136 }
130 - }
131 - if ( $sysop ) $itext .= "<li>" . wfMsg( 'security-infosysops' ) . "</li>\n";
132 - $itext .= "</ul>\n";
 137+ if ( $sysop ) $itext .= "<li>" . wfMsg( 'security-infosysops' ) . "</li>\n";
 138+ $itext .= "</ul>\n";
133139
134 - # Add some javascript to allow toggling the security-info
135 - $out->addScript( "<script type='text/javascript'>
136 - function toggleSecurityInfo() {
137 - var info = document.getElementById('security-info');
138 - info.style.display = info.style.display ? '' : 'none';
139 - }</script>"
140 - );
 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+ );
141147
142 - # Add info-toggle before title and hidden info after title
143 - $link = "<a href='javascript:'>" . wfMsg( 'security-info-toggle' ) . "</a>";
144 - $link = "<span onClick='toggleSecurityInfo()'>$link</span>";
145 - $info = "<div id='security-info-toggle'>" . wfMsg( 'security-info', $link ) . "</div>\n";
146 - $text = "$info<div id='security-info' style='display:none'>$itext</div>\n$text";
 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+ }
147154 }
148155
149156 return true;
Index: trunk/extensions/SimpleSecurity/SimpleSecurity.php
@@ -22,7 +22,7 @@
2323 if ( !defined( 'MEDIAWIKI' ) ) die( 'Not an entry point.' );
2424 if ( version_compare( $wgVersion, '1.12.0' ) < 0 ) die( 'Sorry, this extension requires at least MediaWiki version 1.12.0' );
2525
26 -define( 'SIMPLESECURITY_VERSION', '4.3.4, 2009-07-29' );
 26+define( 'SIMPLESECURITY_VERSION', '4.3.5, 2009-08-08' );
2727
2828 # Load the SimpleSecurity class and messages
2929 $dir = dirname( __FILE__ ) . '/';

Status & tagging log