Index: trunk/extensions/SimpleSecurity/SimpleSecurity_body.php |
— | — | @@ -20,9 +20,9 @@ |
21 | 21 | |
22 | 22 | # Add our hooks |
23 | 23 | $wgHooks['UserGetRights'][] = $this; |
24 | | - $wgHooks['OutputPageBeforeHTML'][] = $this; |
25 | 24 | if ( $wgSecurityMagicIf ) $wgParser->setFunctionHook( $wgSecurityMagicIf, array( $this, 'ifUserCan' ) ); |
26 | 25 | if ( $wgSecurityMagicGroup ) $wgParser->setFunctionHook( $wgSecurityMagicGroup, array( $this, 'ifGroup' ) ); |
| 26 | + if ( $wgSecurityRenderInfo ) $wgHooks['OutputPageBeforeHTML'][] = $this; |
27 | 27 | if ( $wgSecurityAllowUnreadableLinks ) $wgHooks['BeforePageDisplay'][] = $this; |
28 | 28 | |
29 | 29 | # Add a new log type |
— | — | @@ -108,48 +108,42 @@ |
109 | 109 | * Also make restricted pages not archive by robots |
110 | 110 | */ |
111 | 111 | public function onOutputPageBeforeHTML( &$out, &$text ) { |
112 | | - global $wgUser, $wgTitle, $wgSecurityRenderInfo; |
| 112 | + global $wgUser, $wgTitle; |
113 | 113 | $title = $wgTitle; |
114 | 114 | |
115 | | - # Any restrictions? |
| 115 | + # Render info |
116 | 116 | if ( is_object( $title ) && $title->exists() && count( $this->info['LS'] ) + count( $this->info['PR'] ) ) { |
117 | 117 | |
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() ); |
120 | 122 | |
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"; |
136 | 130 | } |
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"; |
139 | 134 | |
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 | + ); |
147 | 142 | |
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"; |
154 | 148 | } |
155 | 149 | |
156 | 150 | return true; |
— | — | @@ -172,7 +166,7 @@ |
173 | 167 | * - clears and populates the info array |
174 | 168 | */ |
175 | 169 | public function onUserGetRights( &$user, &$rights ) { |
176 | | - global $wgGroupPermissions, $wgTitle, $wgRequest, $wgPageRestrictions; |
| 170 | + global $wgGroupPermissions, $wgOut, $wgTitle, $wgRequest, $wgPageRestrictions; |
177 | 171 | |
178 | 172 | # Hack to prevent specialpage operations on unreadable pages |
179 | 173 | if ( !is_object( $wgTitle ) ) return true; |
— | — | @@ -210,10 +204,12 @@ |
211 | 205 | if ( array_intersect( $groups, $g ) ) $rights[] = $a; |
212 | 206 | } |
213 | 207 | |
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 |
215 | 209 | if ( !in_array( 'sysop', $groups ) && !$this->userCanReadTitle( $user, $title, $error ) ) { |
216 | 210 | foreach ( $rights as $i => $right ) if ( $right === 'read' || $right === 'move' ) unset( $rights[$i] ); |
217 | 211 | # $this->info['CR'] = array('read', '', ''); |
| 212 | + $wgOut->addMeta( 'robots', 'noarchive' ); |
| 213 | + |
218 | 214 | } |
219 | 215 | |
220 | 216 | return true; |