r24562 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24561‎ | r24562 | r24563 >
Date:09:27, 3 August 2007
Author:werdna
Status:old
Tags:
Comment:
Use the new userCan changes to display better, clearer error messages when a permissions error is encountered.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -319,57 +319,35 @@
320320 return;
321321 }
322322
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;
349333 }
 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+ }
350342 }
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 );
360350 wfProfileOut( $fname );
361351 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 - }
374352 } else {
375353 if ( $this->save ) {
376354 $this->formtype = 'save';
Index: trunk/phase3/includes/OutputPage.php
@@ -831,16 +831,7 @@
832832 $this->mBodytext = '';
833833
834834 $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 ) );
845836 }
846837
847838 /** @deprecated */
@@ -959,20 +950,46 @@
960951 }
961952
962953 /**
 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+ /**
963975 * @todo document
964976 * @param bool $protected Is the reason the page can't be reached because it's protected?
965977 * @param mixed $source
966978 */
967 - public function readOnlyPage( $source = null, $protected = false ) {
 979+ public function readOnlyPage( $source = null, $protected = false, $reasons = array() ) {
968980 global $wgUser, $wgReadOnlyFile, $wgReadOnly, $wgTitle;
969981 $skin = $wgUser->getSkin();
970982
971983 $this->setRobotpolicy( 'noindex,nofollow' );
972984 $this->setArticleRelated( false );
973985
974 - if( $protected ) {
 986+ if ($reasons != array()) {
975987 $this->setPageTitle( wfMsg( 'viewsource' ) );
976988 $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 ) ) );
977994 list( $cascadeSources, /* $restrictions */ ) = $wgTitle->getCascadeProtectionSources();
978995
979996 // Show an appropriate explanation depending upon the reason
Index: trunk/phase3/includes/Title.php
@@ -1006,7 +1006,7 @@
10071007 }
10081008 return false;
10091009 }
1010 -
 1010+
10111011 /**
10121012 * Can $wgUser perform $action on this page?
10131013 * @param string $action action that permission needs to be checked for
@@ -1034,6 +1034,13 @@
10351035 $errors[] = array( 'readonlytext' );
10361036 }
10371037
 1038+ global $wgEmailConfirmToEdit;
 1039+
 1040+ if ( $wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed() )
 1041+ {
 1042+ $errors[] = array( 'confirmedittext' );
 1043+ }
 1044+
10381045 if ( $user->isBlockedFrom( $this ) ) {
10391046 $block = $user->mBlock;
10401047
Index: trunk/phase3/RELEASE-NOTES
@@ -161,6 +161,7 @@
162162 * (bug 10701) Link to Special:Listusers in default Special:Statistics messages
163163 * Improved file history presentation
164164 * (bug 10739) Users can now enter comments when reverting files
 165+* Improved handling of permissions errors.
165166
166167 == Bugfixes since 1.10 ==
167168

Follow-up revisions

RevisionCommit summaryAuthorDate
r24631Merged revisions 24480-24600 via svnmerge from...david18:39, 6 August 2007

Status & tagging log