r92377 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92376‎ | r92377 | r92378 >
Date:19:31, 16 July 2011
Author:ialex
Status:ok
Tags:
Comment:
* Use standard method to check user permissions
* Directly throw an ReadOnlyError instead of calling OutputPage::readOnlyPage()
* In Special:Block: don't let user think the error is temporary if he doesn't have right and the database is locked, instead check permissions first and then the database lock
Modified paths:
  • /trunk/phase3/includes/specials/SpecialBlock.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialLockdb.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUnblock.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUnlockdb.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialUnblock.php
@@ -38,13 +38,14 @@
3939 global $wgUser, $wgOut, $wgRequest;
4040
4141 # Check permissions
42 - if( !$wgUser->isAllowed( 'block' ) ) {
43 - $wgOut->permissionRequired( 'block' );
 42+ if( !$this->userCanExecute( $wgUser ) ) {
 43+ $this->displayRestrictionError();
4444 return;
4545 }
 46+
4647 # Check for database lock
4748 if( wfReadOnly() ) {
48 - $wgOut->readOnlyPage();
 49+ throw new ReadOnlyError;
4950 return;
5051 }
5152
Index: trunk/phase3/includes/specials/SpecialLockdb.php
@@ -38,8 +38,9 @@
3939
4040 $this->setHeaders();
4141
42 - if( !$wgUser->isAllowed( 'siteadmin' ) ) {
43 - $wgOut->permissionRequired( 'siteadmin' );
 42+ # Permission check
 43+ if( !$this->userCanExecute( $wgUser ) ) {
 44+ $this->displayRestrictionError();
4445 return;
4546 }
4647
Index: trunk/phase3/includes/specials/SpecialUnlockdb.php
@@ -33,12 +33,13 @@
3434 }
3535
3636 public function execute( $par ) {
37 - global $wgUser, $wgOut, $wgRequest;
 37+ global $wgUser, $wgRequest;
3838
3939 $this->setHeaders();
4040
41 - if( !$wgUser->isAllowed( 'siteadmin' ) ) {
42 - $wgOut->permissionRequired( 'siteadmin' );
 41+ # Permission check
 42+ if( !$this->userCanExecute( $wgUser ) ) {
 43+ $this->displayRestrictionError();
4344 return;
4445 }
4546
Index: trunk/phase3/includes/specials/SpecialBlock.php
@@ -59,17 +59,17 @@
6060 public function execute( $par ) {
6161 global $wgUser, $wgOut, $wgRequest;
6262
63 - # Can't block when the database is locked
64 - if( wfReadOnly() ) {
65 - $wgOut->readOnlyPage();
66 - return;
67 - }
6863 # Permission check
6964 if( !$this->userCanExecute( $wgUser ) ) {
70 - $wgOut->permissionRequired( 'block' );
 65+ $this->displayRestrictionError();
7166 return;
7267 }
7368
 69+ # Can't block when the database is locked
 70+ if( wfReadOnly() ) {
 71+ throw new ReadOnlyError;
 72+ }
 73+
7474 # Extract variables from the request. Try not to get into a situation where we
7575 # need to extract *every* variable from the form just for processing here, but
7676 # there are legitimate uses for some variables

Status & tagging log