r101630 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101629‎ | r101630 | r101631 >
Date:15:30, 2 November 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
* Made PermissionsError exception accept an optional second parameter for the description of the errors (as returned by Title::getUserPermissionsErrors())
* PermissionsError now calls OutputPage::showPermissionsErrorPage() to display the error (this is needed to make the item above work correctly)
* Removed the override of the HTML title in OutputPage::showPermissionsErrorPage() so that it shows "Permission errors - Sitename" instead of simply "Permission errors" for consistency with the other things
* Pass the error array returned by Title::getUserPermissionsErrors() to PermissionsError where available
* Converted direct calls to OutputPage::showPermissionsErrorPage() to throw an PermissionsError error instead
* Added 'action-rollback' message that will be displayed when accessing action=rollback without sufficient rights
* Changed getRestriction() in subclasses of Action to return null when they previously returned 'read' so that user rights can be check with Title::getUserPermissionsErrors()
* Reordered checks to do first user rights, then block (if needed) and finally read only (also if needed) so that users don't think the error is temporary when they both don't have right and the database is locked
Modified paths:
  • /trunk/phase3/includes/Action.php (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Exception.php (modified) (history)
  • /trunk/phase3/includes/FileDeleteForm.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/actions/HistoryAction.php (modified) (history)
  • /trunk/phase3/includes/actions/InfoAction.php (modified) (history)
  • /trunk/phase3/includes/actions/MarkpatrolledAction.php (modified) (history)
  • /trunk/phase3/includes/actions/RawAction.php (modified) (history)
  • /trunk/phase3/includes/actions/RevertAction.php (modified) (history)
  • /trunk/phase3/includes/actions/RollbackAction.php (modified) (history)
  • /trunk/phase3/includes/actions/WatchAction.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialImport.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialMovepage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserlogin.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUserrights.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesQqq.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1181,6 +1181,7 @@
11821182 'action-suppressionlog',
11831183 'action-block',
11841184 'action-protect',
 1185+ 'action-rollback',
11851186 'action-import',
11861187 'action-importupload',
11871188 'action-patrol',
Index: trunk/phase3/includes/Article.php
@@ -1302,6 +1302,19 @@
13031303 public function delete() {
13041304 global $wgOut, $wgRequest;
13051305
 1306+ # This code desperately needs to be totally rewritten
 1307+
 1308+ # Check permissions
 1309+ $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $this->getContext()->getUser() );
 1310+ if ( count( $permission_errors ) ) {
 1311+ throw new PermissionsError( 'delete', $permission_errors );
 1312+ }
 1313+
 1314+ # Read-only check...
 1315+ if ( wfReadOnly() ) {
 1316+ throw new ReadOnlyError;
 1317+ }
 1318+
13061319 $confirm = $wgRequest->wasPosted() &&
13071320 $this->getContext()->getUser()->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
13081321
@@ -1320,24 +1333,6 @@
13211334 # Flag to hide all contents of the archived revisions
13221335 $suppress = $wgRequest->getVal( 'wpSuppress' ) && $this->getContext()->getUser()->isAllowed( 'suppressrevision' );
13231336
1324 - # This code desperately needs to be totally rewritten
1325 -
1326 - # Read-only check...
1327 - if ( wfReadOnly() ) {
1328 - $wgOut->readOnlyPage();
1329 -
1330 - return;
1331 - }
1332 -
1333 - # Check permissions
1334 - $permission_errors = $this->getTitle()->getUserPermissionsErrors( 'delete', $this->getContext()->getUser() );
1335 -
1336 - if ( count( $permission_errors ) > 0 ) {
1337 - $wgOut->showPermissionsErrorPage( $permission_errors );
1338 -
1339 - return;
1340 - }
1341 -
13421337 $wgOut->setPageTitle( wfMessage( 'delete-confirm', $this->getTitle()->getPrefixedText() ) );
13431338
13441339 # Better double-check that it hasn't been deleted yet!
Index: trunk/phase3/includes/OutputPage.php
@@ -1979,7 +1979,7 @@
19801980 * @param $action String: action that was denied or null if unknown
19811981 */
19821982 public function showPermissionsErrorPage( $errors, $action = null ) {
1983 - $this->prepareErrorPage( $this->msg( 'permissionserrors' ), $this->msg( 'permissionserrors' ) );
 1983+ $this->prepareErrorPage( $this->msg( 'permissionserrors' ) );
19841984
19851985 $this->addWikiText( $this->formatPermissionsErrorMessage( $errors, $action ) );
19861986 }
Index: trunk/phase3/includes/actions/InfoAction.php
@@ -30,7 +30,7 @@
3131 }
3232
3333 public function getRestriction() {
34 - return 'read';
 34+ return null;
3535 }
3636
3737 protected function getDescription() {
Index: trunk/phase3/includes/actions/HistoryAction.php
@@ -24,7 +24,7 @@
2525 }
2626
2727 public function getRestriction() {
28 - return 'read';
 28+ return null;
2929 }
3030
3131 public function requiresWrite() {
Index: trunk/phase3/includes/actions/MarkpatrolledAction.php
@@ -29,7 +29,7 @@
3030 }
3131
3232 public function getRestriction() {
33 - return 'read';
 33+ return null;
3434 }
3535
3636 protected function getDescription() {
@@ -73,9 +73,8 @@
7474 return;
7575 }
7676
77 - if ( !empty( $errors ) ) {
78 - $this->getOutput()->showPermissionsErrorPage( $errors );
79 - return;
 77+ if ( count( $errors ) ) {
 78+ throw new PermissionsErrorPage( 'patrol', $errors );
8079 }
8180
8281 # Inform the user
Index: trunk/phase3/includes/actions/WatchAction.php
@@ -27,7 +27,7 @@
2828 }
2929
3030 public function getRestriction() {
31 - return 'read';
 31+ return null;
3232 }
3333
3434 public function requiresUnblock() {
Index: trunk/phase3/includes/actions/RevertAction.php
@@ -35,7 +35,7 @@
3636 }
3737
3838 public function getRestriction() {
39 - return 'read';
 39+ return null;
4040 }
4141
4242 public function show() {
Index: trunk/phase3/includes/actions/RawAction.php
@@ -25,7 +25,7 @@
2626 }
2727
2828 public function getRestriction() {
29 - return 'read';
 29+ return null;
3030 }
3131
3232 public function requiresWrite() {
Index: trunk/phase3/includes/actions/RollbackAction.php
@@ -83,9 +83,7 @@
8484 $out [] = $error;
8585 }
8686 }
87 - $this->getOutput()->showPermissionsErrorPage( $out );
88 -
89 - return;
 87+ throw new PermissionsError( 'rollback', $out );
9088 }
9189
9290 if ( $result == array( array( 'readonlytext' ) ) ) {
Index: trunk/phase3/includes/FileDeleteForm.php
@@ -41,18 +41,18 @@
4242 */
4343 public function execute() {
4444 global $wgOut, $wgRequest, $wgUser;
45 - $this->setHeaders();
4645
47 - $permission_errors = $this->title->getUserPermissionsErrors('delete', $wgUser);
48 - if ( count( $permission_errors ) > 0 ) {
49 - $wgOut->showPermissionsErrorPage( $permission_errors );
50 - return;
 46+ $permissionErrors = $this->title->getUserPermissionsErrors( 'delete', $wgUser );
 47+ if ( count( $permissionErrors ) ) {
 48+ throw new PermissionsError( 'delete', $permissionErrors );
5149 }
5250
5351 if ( wfReadOnly() ) {
5452 throw new ReadOnlyError;
5553 }
5654
 55+ $this->setHeaders();
 56+
5757 $this->oldimage = $wgRequest->getText( 'oldimage', false );
5858 $token = $wgRequest->getText( 'wpEditToken' );
5959 # Flag to hide all contents of the archived revisions
Index: trunk/phase3/includes/specials/SpecialUserrights.php
@@ -99,24 +99,21 @@
100100 $this->isself = true;
101101 }
102102
103 - $out = $this->getOutput();
104 -
105103 if( !$this->userCanChangeRights( $user, true ) ) {
106104 // @todo FIXME: There may be intermediate groups we can mention.
107 - $out->showPermissionsErrorPage( array( array(
108 - $user->isAnon()
109 - ? 'userrights-nologin'
110 - : 'userrights-notallowed' ) ) );
111 - return;
 105+ $msg = $user->isAnon() ? 'userrights-nologin' : 'userrights-notallowed';
 106+ throw new PermissionsError( null, array( array( $msg ) ) );
112107 }
113108
114109 if ( wfReadOnly() ) {
115110 throw new ReadOnlyError;
116111 }
117112
 113+ $this->setHeaders();
118114 $this->outputHeader();
 115+
 116+ $out = $this->getOutput();
119117 $out->addModuleStyles( 'mediawiki.special' );
120 - $this->setHeaders();
121118
122119 // show the general form
123120 if ( count( $available['add'] ) || count( $available['remove'] ) ) {
Index: trunk/phase3/includes/specials/SpecialImport.php
@@ -60,10 +60,6 @@
6161 throw new PermissionsError( 'import' );
6262 }
6363
64 - if ( wfReadOnly() ) {
65 - throw new ReadOnlyError;
66 - }
67 -
6864 # @todo Allow Title::getUserPermissionsErrors() to take an array
6965 # @todo FIXME: Title::checkSpecialsAndNSPermissions() has a very wierd expectation of what
7066 # getUserPermissionsErrors() might actually be used for, hence the 'ns-specialprotected'
@@ -78,11 +74,14 @@
7975 )
8076 );
8177
82 - if( $errors ){
83 - $this->getOutput()->showPermissionsErrorPage( $errors );
84 - return;
 78+ if ( $errors ) {
 79+ throw new PermissionsError( 'import', $errors );
8580 }
8681
 82+ if ( wfReadOnly() ) {
 83+ throw new ReadOnlyError;
 84+ }
 85+
8786 $request = $this->getRequest();
8887 if ( $request->wasPosted() && $request->getVal( 'action' ) == 'submit' ) {
8988 $this->doImport();
Index: trunk/phase3/includes/specials/SpecialUserlogin.php
@@ -953,14 +953,14 @@
954954 // Block signup here if in readonly. Keeps user from
955955 // going through the process (filling out data, etc)
956956 // and being informed later.
957 - if ( wfReadOnly() ) {
958 - throw new ReadOnlyError;
 957+ $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $user, true );
 958+ if ( count( $permErrors ) ) {
 959+ throw new PermissionsError( 'createaccount', $permErrors );
959960 } elseif ( $user->isBlockedFromCreateAccount() ) {
960961 $this->userBlockedMessage( $user->isBlockedFromCreateAccount() );
961962 return;
962 - } elseif ( count( $permErrors = $titleObj->getUserPermissionsErrors( 'createaccount', $user, true ) )>0 ) {
963 - $this->getOutput()->showPermissionsErrorPage( $permErrors, 'createaccount' );
964 - return;
 963+ } elseif ( wfReadOnly() ) {
 964+ throw new ReadOnlyError;
965965 }
966966 }
967967
Index: trunk/phase3/includes/specials/SpecialMovepage.php
@@ -74,8 +74,7 @@
7575 if( !empty( $permErrors ) ) {
7676 // Auto-block user's IP if the account was "hard" blocked
7777 $user->spreadAnyEditBlock();
78 - $this->getOutput()->showPermissionsErrorPage( $permErrors );
79 - return;
 78+ throw new PermissionsError( 'move', $permErrors );
8079 }
8180
8281 $def = !$request->wasPosted();
Index: trunk/phase3/includes/Action.php
@@ -200,18 +200,25 @@
201201 * @throws ErrorPageError
202202 */
203203 protected function checkCanExecute( User $user ) {
204 - if ( $this->requiresWrite() && wfReadOnly() ) {
205 - throw new ReadOnlyError();
 204+ $right = $this->getRestriction();
 205+ if ( $right !== null ) {
 206+ $errors = $this->getTitle()->getUserPermissionsErrors( $right, $user );
 207+ if ( count( $errors ) ) {
 208+ throw new PermissionsError( $right, $errors );
 209+ }
206210 }
207211
208 - if ( $this->getRestriction() !== null && !$user->isAllowed( $this->getRestriction() ) ) {
209 - throw new PermissionsError( $this->getRestriction() );
210 - }
211 -
212212 if ( $this->requiresUnblock() && $user->isBlocked() ) {
213213 $block = $user->mBlock;
214214 throw new UserBlockedError( $block );
215215 }
 216+
 217+ // This should be checked at the end so that the user won't think the
 218+ // error is only temporary when he also don't have the rights to execute
 219+ // this action
 220+ if ( $this->requiresWrite() && wfReadOnly() ) {
 221+ throw new ReadOnlyError();
 222+ }
216223 }
217224
218225 /**
Index: trunk/phase3/includes/Exception.php
@@ -276,34 +276,35 @@
277277 * @ingroup Exception
278278 */
279279 class PermissionsError extends ErrorPageError {
280 - public $permission;
 280+ public $permission, $errors;
281281
282 - function __construct( $permission ) {
 282+ function __construct( $permission, $errors = array() ) {
283283 global $wgLang;
284284
285285 $this->permission = $permission;
286286
287 - $groups = array_map(
288 - array( 'User', 'makeGroupLinkWiki' ),
289 - User::getGroupsWithPermission( $this->permission )
290 - );
 287+ if ( !count( $errors ) ) {
 288+ $groups = array_map(
 289+ array( 'User', 'makeGroupLinkWiki' ),
 290+ User::getGroupsWithPermission( $this->permission )
 291+ );
291292
292 - if( $groups ) {
293 - parent::__construct(
294 - 'badaccess',
295 - 'badaccess-groups',
296 - array(
297 - $wgLang->commaList( $groups ),
298 - count( $groups )
299 - )
300 - );
301 - } else {
302 - parent::__construct(
303 - 'badaccess',
304 - 'badaccess-group0'
305 - );
 293+ if ( $groups ) {
 294+ $errors[] = array( 'badaccess-groups', $wgLang->commaList( $groups ), count( $groups ) );
 295+ } else {
 296+ $errors[] = array( 'badaccess-group0' );
 297+ }
306298 }
 299+
 300+ $this->errors = $errors;
307301 }
 302+
 303+ function report() {
 304+ global $wgOut;
 305+
 306+ $wgOut->showPermissionsErrorPage( $this->errors, $this->permission );
 307+ $wgOut->output();
 308+ }
308309 }
309310
310311 /**
Index: trunk/phase3/languages/messages/MessagesQqq.php
@@ -1684,6 +1684,7 @@
16851685 'action-suppressionlog' => '{{Doc-action|suppressionlog}}',
16861686 'action-block' => '{{Doc-action|block}}',
16871687 'action-protect' => '{{Doc-action|protect}}',
 1688+'action-rollback' => '{{Doc-action|rollback}}',
16881689 'action-import' => '{{Doc-action|import}}',
16891690 'action-importupload' => '{{Doc-action|importupload}}',
16901691 'action-patrol' => '{{Doc-action|patrol}}',
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2016,6 +2016,7 @@
20172017 'action-suppressionlog' => 'view this private log',
20182018 'action-block' => 'block this user from editing',
20192019 'action-protect' => 'change protection levels for this page',
 2020+'action-rollback' => 'quickly rollback the edits of the last user who edited a particular page',
20202021 'action-import' => 'import this page from another wiki',
20212022 'action-importupload' => 'import this page from a file upload',
20222023 'action-patrol' => "mark others' edit as patrolled",

Follow-up revisions

RevisionCommit summaryAuthorDate
r101967Per Platonides, fix for r101630: correct class nameialex06:59, 4 November 2011

Comments

#Comment by Platonides (talk | contribs)   23:02, 3 November 2011

You're throwing a PermissionsErrorPage in includes/actions/MarkpatrolledAction.php line 77 but that class doesn't exist.

#Comment by IAlex (talk | contribs)   07:00, 4 November 2011

Fixed in r101967.

Status & tagging log