r86086 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86085‎ | r86086 | r86087 >
Date:21:09, 14 April 2011
Author:btongminh
Status:ok
Tags:
Comment:
Follow-up r83302: Check permissions
Modified paths:
  • /trunk/phase3/includes/api/ApiFileRevert.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiFileRevert.php
@@ -49,12 +49,13 @@
5050 public function execute() {
5151 global $wgUser;
5252
53 - // First check permission to upload/revert
54 - $this->checkPermissions( $wgUser );
55 -
5653 $this->params = $this->extractRequestParams();
 54+ // Extract the file and archiveName from the request parameters
5755 $this->validateParameters();
5856
 57+ // Check whether we're allowed to revert this file
 58+ $this->checkPermissions( $wgUser );
 59+
5960 $sourceUrl = $this->file->getArchiveVirtualUrl( $this->archiveName );
6061 $status = $this->file->upload( $sourceUrl, $this->params['comment'], $this->params['comment'] );
6162
@@ -77,15 +78,16 @@
7879 * @param $user User The user to check.
7980 */
8081 protected function checkPermissions( $user ) {
81 - $permission = $user->isAllowedAll( 'edit', 'upload' );
 82+ $permissionErrors = array_merge(
 83+ $this->file->getTitle()->getUserPermissionsErrors( 'edit' , $user ),
 84+ $this->file->getTitle()->getUserPermissionsErrors( 'upload' , $user )
 85+ );
8286
83 - if ( $permission !== true ) {
84 - if ( !$user->isLoggedIn() ) {
85 - $this->dieUsageMsg( array( 'mustbeloggedin', 'upload' ) );
86 - } else {
87 - $this->dieUsageMsg( array( 'badaccess-groups' ) );
88 - }
 87+ if ( $permissionErrors ) {
 88+ $this->dieUsageMsg( $permissionErrors[0] );
8989 }
 90+
 91+
9092 }
9193
9294 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r83302(bug 27018) Added action=filerevert to revert files to an old version. Copied...btongminh17:23, 5 March 2011

Status & tagging log