Index: trunk/phase3/includes/Title.php |
— | — | @@ -1166,6 +1166,59 @@ |
1167 | 1167 | |
1168 | 1168 | $errors = array(); |
1169 | 1169 | |
| 1170 | + // First stop is permissions checks, which fail most often, and which are easiest to test. |
| 1171 | + if ( $action == 'move' ) { |
| 1172 | + if( !$user->isAllowed( 'move-rootuserpages' ) |
| 1173 | + && $this->getNamespace() == NS_USER && !$this->isSubpage() ) |
| 1174 | + { |
| 1175 | + // Show user page-specific message only if the user can move other pages |
| 1176 | + $errors[] = array( 'cant-move-user-page' ); |
| 1177 | + } |
| 1178 | + |
| 1179 | + // Check if user is allowed to move files if it's a file |
| 1180 | + if( $this->getNamespace() == NS_FILE && !$user->isAllowed( 'movefile' ) ) { |
| 1181 | + $errors[] = array( 'movenotallowedfile' ); |
| 1182 | + } |
| 1183 | + |
| 1184 | + if( !$user->isAllowed( 'move' ) ) { |
| 1185 | + // User can't move anything |
| 1186 | + $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed'); |
| 1187 | + } |
| 1188 | + } elseif ( $action == 'create' ) { |
| 1189 | + if( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) || |
| 1190 | + ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) |
| 1191 | + { |
| 1192 | + $errors[] = $user->isAnon() ? array ('nocreatetext') : array ('nocreate-loggedin'); |
| 1193 | + } |
| 1194 | + } elseif( $action == 'move-target' ) { |
| 1195 | + if( !$user->isAllowed( 'move' ) ) { |
| 1196 | + // User can't move anything |
| 1197 | + $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed'); |
| 1198 | + } elseif( !$user->isAllowed( 'move-rootuserpages' ) |
| 1199 | + && $this->getNamespace() == NS_USER && !$this->isSubpage() ) |
| 1200 | + { |
| 1201 | + // Show user page-specific message only if the user can move other pages |
| 1202 | + $errors[] = array( 'cant-move-to-user-page' ); |
| 1203 | + } |
| 1204 | + } elseif( !$user->isAllowed( $action ) ) { |
| 1205 | + $return = null; |
| 1206 | + $groups = array_map( array( 'User', 'makeGroupLinkWiki' ), |
| 1207 | + User::getGroupsWithPermission( $action ) ); |
| 1208 | + if( $groups ) { |
| 1209 | + $return = array( 'badaccess-groups', |
| 1210 | + array( implode( ', ', $groups ), count( $groups ) ) ); |
| 1211 | + } else { |
| 1212 | + $return = array( "badaccess-group0" ); |
| 1213 | + } |
| 1214 | + $errors[] = $return; |
| 1215 | + } |
| 1216 | + |
| 1217 | + # Short-circuit point |
| 1218 | + if( $short && count($errors) > 0 ) { |
| 1219 | + wfProfileOut( __METHOD__ ); |
| 1220 | + return $errors; |
| 1221 | + } |
| 1222 | + |
1170 | 1223 | // Use getUserPermissionsErrors instead |
1171 | 1224 | if( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) { |
1172 | 1225 | wfProfileOut( __METHOD__ ); |
— | — | @@ -1300,26 +1353,7 @@ |
1301 | 1354 | $errors[] = array( 'titleprotected', User::whoIs($pt_user), $pt_reason ); |
1302 | 1355 | } |
1303 | 1356 | } |
1304 | | - |
1305 | | - if( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) || |
1306 | | - ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) |
1307 | | - { |
1308 | | - $errors[] = $user->isAnon() ? array ('nocreatetext') : array ('nocreate-loggedin'); |
1309 | | - } |
1310 | 1357 | } elseif( $action == 'move' ) { |
1311 | | - if( !$user->isAllowed( 'move' ) ) { |
1312 | | - // User can't move anything |
1313 | | - $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed'); |
1314 | | - } elseif( !$user->isAllowed( 'move-rootuserpages' ) |
1315 | | - && $this->getNamespace() == NS_USER && !$this->isSubpage() ) |
1316 | | - { |
1317 | | - // Show user page-specific message only if the user can move other pages |
1318 | | - $errors[] = array( 'cant-move-user-page' ); |
1319 | | - } |
1320 | | - // Check if user is allowed to move files if it's a file |
1321 | | - if( $this->getNamespace() == NS_FILE && !$user->isAllowed( 'movefile' ) ) { |
1322 | | - $errors[] = array( 'movenotallowedfile' ); |
1323 | | - } |
1324 | 1358 | // Check for immobile pages |
1325 | 1359 | if( !MWNamespace::isMovable( $this->getNamespace() ) ) { |
1326 | 1360 | // Specific message for this case |
— | — | @@ -1329,31 +1363,11 @@ |
1330 | 1364 | $errors[] = array( 'immobile-page' ); |
1331 | 1365 | } |
1332 | 1366 | } elseif( $action == 'move-target' ) { |
1333 | | - if( !$user->isAllowed( 'move' ) ) { |
1334 | | - // User can't move anything |
1335 | | - $errors[] = $user->isAnon() ? array ( 'movenologintext' ) : array ('movenotallowed'); |
1336 | | - } elseif( !$user->isAllowed( 'move-rootuserpages' ) |
1337 | | - && $this->getNamespace() == NS_USER && !$this->isSubpage() ) |
1338 | | - { |
1339 | | - // Show user page-specific message only if the user can move other pages |
1340 | | - $errors[] = array( 'cant-move-to-user-page' ); |
1341 | | - } |
1342 | 1367 | if( !MWNamespace::isMovable( $this->getNamespace() ) ) { |
1343 | 1368 | $errors[] = array( 'immobile-target-namespace', $this->getNsText() ); |
1344 | 1369 | } elseif( !$this->isMovable() ) { |
1345 | 1370 | $errors[] = array( 'immobile-target-page' ); |
1346 | 1371 | } |
1347 | | - } elseif( !$user->isAllowed( $action ) ) { |
1348 | | - $return = null; |
1349 | | - $groups = array_map( array( 'User', 'makeGroupLinkWiki' ), |
1350 | | - User::getGroupsWithPermission( $action ) ); |
1351 | | - if( $groups ) { |
1352 | | - $return = array( 'badaccess-groups', |
1353 | | - array( implode( ', ', $groups ), count( $groups ) ) ); |
1354 | | - } else { |
1355 | | - $return = array( "badaccess-group0" ); |
1356 | | - } |
1357 | | - $errors[] = $return; |
1358 | 1372 | } |
1359 | 1373 | |
1360 | 1374 | wfProfileOut( __METHOD__ ); |