Index: trunk/phase3/includes/api/ApiFileRevert.php |
— | — | @@ -49,12 +49,13 @@ |
50 | 50 | public function execute() { |
51 | 51 | global $wgUser; |
52 | 52 | |
53 | | - // First check permission to upload/revert |
54 | | - $this->checkPermissions( $wgUser ); |
55 | | - |
56 | 53 | $this->params = $this->extractRequestParams(); |
| 54 | + // Extract the file and archiveName from the request parameters |
57 | 55 | $this->validateParameters(); |
58 | 56 | |
| 57 | + // Check whether we're allowed to revert this file |
| 58 | + $this->checkPermissions( $wgUser ); |
| 59 | + |
59 | 60 | $sourceUrl = $this->file->getArchiveVirtualUrl( $this->archiveName ); |
60 | 61 | $status = $this->file->upload( $sourceUrl, $this->params['comment'], $this->params['comment'] ); |
61 | 62 | |
— | — | @@ -77,15 +78,16 @@ |
78 | 79 | * @param $user User The user to check. |
79 | 80 | */ |
80 | 81 | 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 | + ); |
82 | 86 | |
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] ); |
89 | 89 | } |
| 90 | + |
| 91 | + |
90 | 92 | } |
91 | 93 | |
92 | 94 | /** |