r87901 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87900‎ | r87901 | r87902 >
Date:06:36, 12 May 2011
Author:skizzerz
Status:ok
Tags:
Comment:
* Followup r87897: coding convention fixes in Lockdown and clarify a poorly-worded comment
Modified paths:
  • /trunk/extensions/Lockdown/Lockdown.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Lockdown/Lockdown.php
@@ -60,7 +60,9 @@
6161 $result = null;
6262
6363 // don't impose extra restrictions on UI pages
64 - if ( $title->isCssJsSubpage() ) return true;
 64+ if ( $title->isCssJsSubpage() ) {
 65+ return true;
 66+ }
6567
6668 if ( $action == 'read' && $wgWhitelistRead ) {
6769 // don't impose read restrictions on whitelisted pages
@@ -75,8 +77,7 @@
7678 if ( $action != 'read' ) {
7779 $result = false;
7880 return true;
79 - }
80 - else {
 81+ } else {
8182 foreach ( $wgSpecialPageLockdown as $page => $g ) {
8283 if ( !$title->isSpecial( $page ) ) continue;
8384 $groups = $g;
@@ -86,12 +87,20 @@
8788 }
8889 else {
8990 $groups = @$wgNamespacePermissionLockdown[$ns][$action];
90 - if ( $groups === null ) $groups = @$wgNamespacePermissionLockdown['*'][$action];
91 - if ( $groups === null ) $groups = @$wgNamespacePermissionLockdown[$ns]['*'];
 91+ if ( $groups === null ) {
 92+ $groups = @$wgNamespacePermissionLockdown['*'][$action];
 93+ }
 94+ if ( $groups === null ) {
 95+ $groups = @$wgNamespacePermissionLockdown[$ns]['*'];
 96+ }
9297 }
9398
94 - if ( $groups === null ) return true;
95 - if ( count( $groups ) == 0 ) return false;
 99+ if ( $groups === null ) {
 100+ return true;
 101+ }
 102+ if ( count( $groups ) == 0 ) {
 103+ return false;
 104+ }
96105
97106 # print "<br />nsAccessUserCan(".$title->getPrefixedDBkey().", ".$user->getName().", $action)<br />\n";
98107 # print_r($groups);
@@ -107,8 +116,7 @@
108117 # group is allowed - keep processing
109118 $result = null;
110119 return true;
111 - }
112 - else {
 120+ } else {
113121 # print "<br />DENY<br />\n";
114122 # group is denied - abort
115123 $result = false;
@@ -121,24 +129,33 @@
122130
123131 $action = $wiki->getAction( $request );
124132
125 - if ( !isset( $wgActionLockdown[$action] ) ) return true;
 133+ if ( !isset( $wgActionLockdown[$action] ) ) {
 134+ return true;
 135+ }
126136
127137 $groups = $wgActionLockdown[$action];
128 - if ( $groups === null ) return true;
129 - if ( count( $groups ) == 0 ) return false;
 138+ if ( $groups === null ) {
 139+ return true;
 140+ }
 141+ if ( count( $groups ) == 0 ) {
 142+ return false;
 143+ }
130144
131145 $ugroups = $user->getEffectiveGroups();
132146 $match = array_intersect( $ugroups, $groups );
133147
134 - if ( $match ) return true;
135 - else return false;
 148+ if ( $match ) {
 149+ return true;
 150+ } else {
 151+ return false;
 152+ }
136153 }
137154
138155 function lockdownSearchableNamespaces($arr) {
139156 global $wgUser, $wgNamespacePermissionLockdown;
140157
141 - //don't continue if $wgUser's name and id are both false (bug 28842)
142 - if ( $wgUser->getId() === NULL && $wgUser->getName() === NULL ) {
 158+ //don't continue if $wgUser's name and id are both null (bug 28842)
 159+ if ( $wgUser->getId() === null && $wgUser->getName() === null ) {
143160 return true;
144161 }
145162
@@ -146,12 +163,18 @@
147164
148165 foreach ( $arr as $ns => $name ) {
149166 $groups = @$wgNamespacePermissionLockdown[$ns]['read'];
150 - if ( $groups === NULL ) $groups = @$wgNamespacePermissionLockdown['*']['read'];
151 - if ( $groups === NULL ) $groups = @$wgNamespacePermissionLockdown[$ns]['*'];
 167+ if ( $groups === null ) {
 168+ $groups = @$wgNamespacePermissionLockdown['*']['read'];
 169+ }
 170+ if ( $groups === null ) {
 171+ $groups = @$wgNamespacePermissionLockdown[$ns]['*'];
 172+ }
152173
153 - if ( $groups === NULL ) continue;
 174+ if ( $groups === null ) {
 175+ continue;
 176+ }
154177
155 - if ( ( count( $groups ) == 0 ) || !array_intersect($ugroups, $groups) ) {
 178+ if ( ( count( $groups ) == 0 ) || !array_intersect( $ugroups, $groups ) ) {
156179 unset( $arr[$ns] );
157180 }
158181 }
@@ -164,10 +187,16 @@
165188 $ugroups = $wgUser->getEffectiveGroups();
166189
167190 $groups = @$wgNamespacePermissionLockdown[$title->getNamespace()]['read'];
168 - if ( $groups === NULL ) $groups = @$wgNamespacePermissionLockdown['*']['read'];
169 - if ( $groups === NULL ) $groups = @$wgNamespacePermissionLockdown[$title->getNamespace()]['*'];
 191+ if ( $groups === null ) {
 192+ $groups = @$wgNamespacePermissionLockdown['*']['read'];
 193+ }
 194+ if ( $groups === null ) {
 195+ $groups = @$wgNamespacePermissionLockdown[$title->getNamespace()]['*'];
 196+ }
170197
171 - if ( $groups === NULL ) return false;
 198+ if ( $groups === null ) {
 199+ return false;
 200+ }
172201
173202 if ( ( count( $groups ) == 0 ) || !array_intersect($ugroups, $groups) ) {
174203 $title = null;
@@ -178,12 +207,12 @@
179208 }
180209
181210 #Stop a Go search for a hidden title to send you to the login required page. Will show a no such page message instead.
182 -function lockdownSearchGetNearMatchComplete($searchterm, $title) {
 211+function lockdownSearchGetNearMatchComplete( $searchterm, $title ) {
183212 return lockdownTitle( $title );
184213 }
185214
186215 #Protect against namespace prefixes, explicit ones and <searchall> ('all:'-queries).
187 -function lockdownSearchEngineReplacePrefixesComplete($searchEngine, $query, $parsed) {
 216+function lockdownSearchEngineReplacePrefixesComplete( $searchEngine, $query, $parsed ) {
188217 global $wgUser, $wgNamespacePermissionLockdown;
189218 if ( $searchEngine->namespaces === null ) { #null means all namespaces.
190219 $searchEngine->namespaces = array_keys( SearchEngine::searchableNamespaces() ); #Use the namespaces... filtered
@@ -194,17 +223,23 @@
195224
196225 foreach ( $searchEngine->namespaces as $key => $ns ) {
197226 $groups = @$wgNamespacePermissionLockdown[$ns]['read'];
198 - if ( $groups === NULL ) $groups = @$wgNamespacePermissionLockdown['*']['read'];
199 - if ( $groups === NULL ) $groups = @$wgNamespacePermissionLockdown[$ns]['*'];
 227+ if ( $groups === null ) {
 228+ $groups = @$wgNamespacePermissionLockdown['*']['read'];
 229+ }
 230+ if ( $groups === null ) {
 231+ $groups = @$wgNamespacePermissionLockdown[$ns]['*'];
 232+ }
200233
201 - if ( $groups === NULL ) continue;
 234+ if ( $groups === null ) {
 235+ continue;
 236+ }
202237
203 - if ( ( count( $groups ) == 0 ) || !array_intersect($ugroups, $groups) ) {
 238+ if ( ( count( $groups ) == 0 ) || !array_intersect( $ugroups, $groups ) ) {
204239 unset( $searchEngine->namespaces[$key] );
205240 }
206241 }
207242
208 - if (count($searchEngine->namespaces) == 0) {
 243+ if ( count( $searchEngine->namespaces ) == 0 ) {
209244 $searchEngine->namespaces = array_keys( SearchEngine::searchableNamespaces() );
210245 }
211246 return true;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r87897* (bug 28842) Fix userrights issue on 1.16.5 with the Lockdown extension (che...skizzerz01:12, 12 May 2011

Status & tagging log