r100795 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100794‎ | r100795 | r100796 >
Date:06:22, 26 October 2011
Author:aaron
Status:ok (Comments)
Tags:
Comment:
Split out checkExecutePermissions() function from userCanExecute() in FormSpecialPage. The former handles actual execute() calls and throws exceptions, the later inherits its purpose from SpecialPage. It just checks the page restriction to see if a user generally *could* execute. This avoids the breakage that came up in r100723 where Special:SpecialPages was throwing permission errors due to the getUsablePages() call.
Modified paths:
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialLockdb.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialPasswordReset.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUnlockdb.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialPasswordReset.php
@@ -43,6 +43,10 @@
4444 }
4545
4646 public function userCanExecute( User $user ) {
 47+ return $this->canChangePassword( $user ) === true && parent::userCanExecute( $user );
 48+ }
 49+
 50+ public function checkExecutePermissions( User $user ) {
4751 $error = $this->canChangePassword( $user );
4852 if ( is_string( $error ) ) {
4953 throw new ErrorPageError( 'internalerror', $error );
@@ -50,7 +54,7 @@
5155 throw new ErrorPageError( 'internalerror', 'resetpass_forbidden' );
5256 }
5357
54 - return parent::userCanExecute( $user );
 58+ return parent::checkExecutePermissions( $user );
5559 }
5660
5761 protected function getFormFields() {
Index: trunk/phase3/includes/specials/SpecialLockdb.php
@@ -37,11 +37,11 @@
3838 return false;
3939 }
4040
41 - public function userCanExecute( User $user ) {
42 - parent::userCanExecute( $user );
 41+ public function checkExecutePermissions( User $user ) {
 42+ global $wgReadOnlyFile;
4343
 44+ parent::checkExecutePermissions( $user );
4445 # If the lock file isn't writable, we can do sweet bugger all
45 - global $wgReadOnlyFile;
4646 if ( !is_writable( dirname( $wgReadOnlyFile ) ) ) {
4747 throw new ErrorPageError( 'lockdb', 'lockfilenotwritable' );
4848 }
Index: trunk/phase3/includes/specials/SpecialUnlockdb.php
@@ -36,11 +36,11 @@
3737 return false;
3838 }
3939
40 - public function userCanExecute( User $user ) {
41 - parent::userCanExecute( $user );
 40+ public function checkExecutePermissions( User $user ) {
 41+ global $wgReadOnlyFile;
4242
 43+ parent::checkExecutePermissions( $user );
4344 # If the lock file isn't writable, we can do sweet bugger all
44 - global $wgReadOnlyFile;
4545 if ( !file_exists( $wgReadOnlyFile ) ) {
4646 throw new ErrorPageError( 'lockdb', 'databasenotlocked' );
4747 }
Index: trunk/phase3/includes/SpecialPage.php
@@ -786,7 +786,7 @@
787787 $this->setHeaders();
788788
789789 // This will throw exceptions if there's a problem
790 - $this->userCanExecute( $this->getUser() );
 790+ $this->checkExecutePermissions( $this->getUser() );
791791
792792 $form = $this->getForm();
793793 if ( $form->show() ) {
@@ -801,20 +801,18 @@
802802 protected function setParameter( $par ){}
803803
804804 /**
805 - * Checks if the given user (identified by an object) can perform this action. Can be
806 - * overridden by sub-classes with more complicated permissions schemes. Failures here
807 - * must throw subclasses of ErrorPageError
808 - *
809 - * @param $user User: the user to check, or null to use the context user
 805+ * Called from execute() to check if the given user can perform this action.
 806+ * Failures here must throw subclasses of ErrorPageError.
 807+ * @param $user User
810808 * @return Bool true
811809 * @throws ErrorPageError
812810 */
813 - public function userCanExecute( User $user ) {
 811+ protected function checkExecutePermissions( User $user ) {
814812 if ( $this->requiresWrite() && wfReadOnly() ) {
815813 throw new ReadOnlyError();
816814 }
817815
818 - if ( $this->getRestriction() !== null && !$user->isAllowed( $this->getRestriction() ) ) {
 816+ if ( !$this->userCanExecute( $this->getUser() ) ) {
819817 throw new PermissionsError( $this->getRestriction() );
820818 }
821819

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100723Port Special:Lockdb and Special:Unlockdb to HTMLForm using FormSpecialPageialex18:20, 25 October 2011

Comments

#Comment by Nikerabbit (talk | contribs)   13:19, 26 October 2011

Took a while to identify the clause for me, only to find out it was already fixed :)

#Comment by IAlex (talk | contribs)   19:37, 26 October 2011

Thank you!

Status & tagging log