Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -319,57 +319,35 @@ |
320 | 320 | return; |
321 | 321 | } |
322 | 322 | |
323 | | - if ( ! $this->mTitle->userCan( 'edit' ) ) { |
324 | | - wfDebug( "$fname: user can't edit\n" ); |
325 | | - $wgOut->readOnlyPage( $this->getContent(), true ); |
326 | | - wfProfileOut( $fname ); |
327 | | - return; |
328 | | - } |
329 | | - wfDebug( "$fname: Checking blocks\n" ); |
330 | | - if ( !$this->preview && !$this->diff && $wgUser->isBlockedFrom( $this->mTitle, !$this->save ) ) { |
331 | | - # When previewing, don't check blocked state - will get caught at save time. |
332 | | - # Also, check when starting edition is done against slave to improve performance. |
333 | | - wfDebug( "$fname: user is blocked\n" ); |
334 | | - $this->blockedPage(); |
335 | | - wfProfileOut( $fname ); |
336 | | - return; |
337 | | - } |
338 | | - if ( !$wgUser->isAllowed('edit') ) { |
339 | | - if ( $wgUser->isAnon() ) { |
340 | | - wfDebug( "$fname: user must log in\n" ); |
341 | | - $this->userNotLoggedInPage(); |
342 | | - wfProfileOut( $fname ); |
343 | | - return; |
344 | | - } else { |
345 | | - wfDebug( "$fname: read-only page\n" ); |
346 | | - $wgOut->readOnlyPage( $this->getContent(), true ); |
347 | | - wfProfileOut( $fname ); |
348 | | - return; |
| 323 | + $permErrors = $this->mTitle->getUserPermissionsErrors( 'edit', $wgUser); |
| 324 | + |
| 325 | + # Ignore some permissions errors. |
| 326 | + $remove = array(); |
| 327 | + foreach( $permErrors as $error ) { |
| 328 | + if ($this->preview || $this->diff && |
| 329 | + ($error[0] == 'blockedtext' || $error[0] == 'autoblockedtext')) |
| 330 | + { |
| 331 | + // Don't worry about blocks when previewing/diffing |
| 332 | + $remove[] = $error; |
349 | 333 | } |
| 334 | + |
| 335 | + if ($error[0] == 'readonlytext') |
| 336 | + { |
| 337 | + if ($this->edit) |
| 338 | + $this->formtype = 'preview'; |
| 339 | + else if ($this->save || $this->preview || $this->diff) |
| 340 | + $remove[] = $error; |
| 341 | + } |
350 | 342 | } |
351 | | - if ($wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed()) { |
352 | | - wfDebug("$fname: user must confirm e-mail address\n"); |
353 | | - $this->userNotConfirmedPage(); |
354 | | - wfProfileOut($fname); |
355 | | - return; |
356 | | - } |
357 | | - if ( !$this->mTitle->userCan( 'create' ) && !$this->mTitle->exists() ) { |
358 | | - wfDebug( "$fname: no create permission\n" ); |
359 | | - $this->noCreatePermission(); |
| 343 | + # array_diff returns elements in $permErrors that are not in $remove. |
| 344 | + $permErrors = array_diff( $permErrors, $remove ); |
| 345 | + |
| 346 | + if ($permErrors != array()) |
| 347 | + { |
| 348 | + wfDebug( "$fname: User can't edit\n" ); |
| 349 | + $wgOut->readOnlyPage( $this->getContent(), true, $permErrors ); |
360 | 350 | wfProfileOut( $fname ); |
361 | 351 | return; |
362 | | - } |
363 | | - if ( wfReadOnly() ) { |
364 | | - wfDebug( "$fname: read-only mode is engaged\n" ); |
365 | | - if( $this->save || $this->preview ) { |
366 | | - $this->formtype = 'preview'; |
367 | | - } else if ( $this->diff ) { |
368 | | - $this->formtype = 'diff'; |
369 | | - } else { |
370 | | - $wgOut->readOnlyPage( $this->getContent() ); |
371 | | - wfProfileOut( $fname ); |
372 | | - return; |
373 | | - } |
374 | 352 | } else { |
375 | 353 | if ( $this->save ) { |
376 | 354 | $this->formtype = 'save'; |
Index: trunk/phase3/includes/OutputPage.php |
— | — | @@ -831,16 +831,7 @@ |
832 | 832 | $this->mBodytext = ''; |
833 | 833 | |
834 | 834 | $this->addWikiText( wfMsg('permissionserrorstext') ); |
835 | | - $this->addHtml( '<ul class="permissions-errors">' . "\n" ); |
836 | | - |
837 | | - foreach( $errors as $error ) |
838 | | - { |
839 | | - $this->addHtml( '<li>' ); |
840 | | - $this->addWikiText( call_user_func_array( 'wfMsg', $error ) ); |
841 | | - $this->addHtml( '</li>'); |
842 | | - } |
843 | | - $this->addHtml( '</ul>' ); |
844 | | - |
| 835 | + $this->addWikitext( $this->formatPermissionsErrorMessage( $errors ) ); |
845 | 836 | } |
846 | 837 | |
847 | 838 | /** @deprecated */ |
— | — | @@ -959,20 +950,46 @@ |
960 | 951 | } |
961 | 952 | |
962 | 953 | /** |
| 954 | + * @param array $errors An array returned by Title::getUserPermissionsErrors |
| 955 | + * @return string The error-messages, formatted into a list. |
| 956 | + */ |
| 957 | + public function formatPermissionsErrorMessage( $errors ) { |
| 958 | + $text = ''; |
| 959 | + |
| 960 | + $text .= wfMsg('permissionserrorstext')."\n"; |
| 961 | + $text .= '<ul class="permissions-errors">' . "\n"; |
| 962 | + |
| 963 | + foreach( $errors as $error ) |
| 964 | + { |
| 965 | + $text .= '<li>'; |
| 966 | + $text .= call_user_func_array( 'wfMsg', $error ); |
| 967 | + $text .= "</li>\n"; |
| 968 | + } |
| 969 | + $text .= '</ul>'; |
| 970 | + |
| 971 | + return $text; |
| 972 | + } |
| 973 | + |
| 974 | + /** |
963 | 975 | * @todo document |
964 | 976 | * @param bool $protected Is the reason the page can't be reached because it's protected? |
965 | 977 | * @param mixed $source |
966 | 978 | */ |
967 | | - public function readOnlyPage( $source = null, $protected = false ) { |
| 979 | + public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) { |
968 | 980 | global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle; |
969 | 981 | $skin = $wgUser->getSkin(); |
970 | 982 | |
971 | 983 | $this->setRobotpolicy( 'noindex,nofollow' ); |
972 | 984 | $this->setArticleRelated( false ); |
973 | 985 | |
974 | | - if( $protected ) { |
| 986 | + if ($reasons != array()) { |
975 | 987 | $this->setPageTitle( wfMsg( 'viewsource' ) ); |
976 | 988 | $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) ); |
| 989 | + |
| 990 | + $this->addWikiText( $this->formatPermissionsErrorMessage( $reasons ) ); |
| 991 | + } else if( $protected ) { |
| 992 | + $this->setPageTitle( wfMsg( 'viewsource' ) ); |
| 993 | + $this->setSubtitle( wfMsg( 'viewsourcefor', $skin->makeKnownLinkObj( $wgTitle ) ) ); |
977 | 994 | list( $cascadeSources, /* $restrictions */ ) = $wgTitle->getCascadeProtectionSources(); |
978 | 995 | |
979 | 996 | // Show an appropriate explanation depending upon the reason |
Index: trunk/phase3/includes/Title.php |
— | — | @@ -1006,7 +1006,7 @@ |
1007 | 1007 | } |
1008 | 1008 | return false; |
1009 | 1009 | } |
1010 | | - |
| 1010 | + |
1011 | 1011 | /** |
1012 | 1012 | * Can $wgUser perform $action on this page? |
1013 | 1013 | * @param string $action action that permission needs to be checked for |
— | — | @@ -1034,6 +1034,13 @@ |
1035 | 1035 | $errors[] = array( 'readonlytext' ); |
1036 | 1036 | } |
1037 | 1037 | |
| 1038 | + global $wgEmailConfirmToEdit; |
| 1039 | + |
| 1040 | + if ( $wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed() ) |
| 1041 | + { |
| 1042 | + $errors[] = array( 'confirmedittext' ); |
| 1043 | + } |
| 1044 | + |
1038 | 1045 | if ( $user->isBlockedFrom( $this ) ) { |
1039 | 1046 | $block = $user->mBlock; |
1040 | 1047 | |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -161,6 +161,7 @@ |
162 | 162 | * (bug 10701) Link to Special:Listusers in default Special:Statistics messages |
163 | 163 | * Improved file history presentation |
164 | 164 | * (bug 10739) Users can now enter comments when reverting files |
| 165 | +* Improved handling of permissions errors. |
165 | 166 | |
166 | 167 | == Bugfixes since 1.10 == |
167 | 168 | |