Index: trunk/phase3/includes/Title.php |
— | — | @@ -1056,7 +1056,7 @@ |
1057 | 1057 | */ |
1058 | 1058 | public function userCan( $action, $doExpensiveQueries = true ) { |
1059 | 1059 | global $wgUser; |
1060 | | - return ( $this->getUserPermissionsErrorsInternal( $action, $wgUser, $doExpensiveQueries ) === array()); |
| 1060 | + return ($this->getUserPermissionsErrorsInternal( $action, $wgUser, $doExpensiveQueries, true ) === array()); |
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | /** |
— | — | @@ -1158,9 +1158,10 @@ |
1159 | 1159 | * @param $action \type{\string} action that permission needs to be checked for |
1160 | 1160 | * @param $user \type{User} user to check |
1161 | 1161 | * @param $doExpensiveQueries \type{\bool} Set this to false to avoid doing unnecessary queries. |
| 1162 | + * @param $short \type{\bool} Set this to true to stop after the first permission error. |
1162 | 1163 | * @return \type{\array} Array of arrays of the arguments to wfMsg to explain permissions problems. |
1163 | 1164 | */ |
1164 | | - private function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries = true ) { |
| 1165 | + private function getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries=true, $short=false ) { |
1165 | 1166 | wfProfileIn( __METHOD__ ); |
1166 | 1167 | |
1167 | 1168 | $errors = array(); |
— | — | @@ -1170,7 +1171,7 @@ |
1171 | 1172 | wfProfileOut( __METHOD__ ); |
1172 | 1173 | return $result ? array() : array( array( 'badaccess-group0' ) ); |
1173 | 1174 | } |
1174 | | - |
| 1175 | + // Check getUserPermissionsErrors hook |
1175 | 1176 | if( !wfRunHooks( 'getUserPermissionsErrors', array(&$this,&$user,$action,&$result) ) ) { |
1176 | 1177 | if( is_array($result) && count($result) && !is_array($result[0]) ) |
1177 | 1178 | $errors[] = $result; # A single array representing an error |
— | — | @@ -1181,6 +1182,12 @@ |
1182 | 1183 | else if( $result === false ) |
1183 | 1184 | $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that" |
1184 | 1185 | } |
| 1186 | + # Short-circuit point |
| 1187 | + if( $short && count($errors) > 0 ) { |
| 1188 | + wfProfileOut( __METHOD__ ); |
| 1189 | + return $errors; |
| 1190 | + } |
| 1191 | + // Check getUserPermissionsErrorsExpensive hook |
1185 | 1192 | if( $doExpensiveQueries && !wfRunHooks( 'getUserPermissionsErrorsExpensive', array(&$this,&$user,$action,&$result) ) ) { |
1186 | 1193 | if( is_array($result) && count($result) && !is_array($result[0]) ) |
1187 | 1194 | $errors[] = $result; # A single array representing an error |
— | — | @@ -1191,6 +1198,11 @@ |
1192 | 1199 | else if( $result === false ) |
1193 | 1200 | $errors[] = array('badaccess-group0'); # a generic "We don't want them to do that" |
1194 | 1201 | } |
| 1202 | + # Short-circuit point |
| 1203 | + if( $short && count($errors) > 0 ) { |
| 1204 | + wfProfileOut( __METHOD__ ); |
| 1205 | + return $errors; |
| 1206 | + } |
1195 | 1207 | |
1196 | 1208 | // TODO: document |
1197 | 1209 | $specialOKActions = array( 'createaccount', 'execute' ); |
— | — | @@ -1236,6 +1248,11 @@ |
1237 | 1249 | } |
1238 | 1250 | } |
1239 | 1251 | } |
| 1252 | + # Short-circuit point |
| 1253 | + if( $short && count($errors) > 0 ) { |
| 1254 | + wfProfileOut( __METHOD__ ); |
| 1255 | + return $errors; |
| 1256 | + } |
1240 | 1257 | |
1241 | 1258 | foreach( $this->getRestrictions($action) as $right ) { |
1242 | 1259 | // Backwards compatibility, rewrite sysop -> protect |
— | — | @@ -1249,14 +1266,17 @@ |
1250 | 1267 | // with cascading option turned on. |
1251 | 1268 | if( $this->mCascadeRestriction ) { |
1252 | 1269 | $errors[] = array( 'protectedpagetext', $right ); |
1253 | | - } else { |
1254 | | - // Nothing, user can edit! |
1255 | 1270 | } |
1256 | 1271 | } else { |
1257 | 1272 | $errors[] = array( 'protectedpagetext', $right ); |
1258 | 1273 | } |
1259 | 1274 | } |
1260 | 1275 | } |
| 1276 | + # Short-circuit point |
| 1277 | + if( $short && count($errors) > 0 ) { |
| 1278 | + wfProfileOut( __METHOD__ ); |
| 1279 | + return $errors; |
| 1280 | + } |
1261 | 1281 | |
1262 | 1282 | if( $action == 'protect' ) { |
1263 | 1283 | if( $this->getUserPermissionsErrors('edit', $user) != array() ) { |