* Factorise common code in ImagePage::delete() and allow normal page deletion if...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Tue, 15 Nov 2011 18:08:34 +0000 (18:08 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Tue, 15 Nov 2011 18:08:34 +0000 (18:08 +0000)
* Moved $wgUploadMaintenance check after permissions and read only, so that the user doesn't think the error is temporary if he both doesn't have the permission and $wgUploadMaintenance is true
* Show normal error page when $wgUploadMaintenance and added a message for the error title
* Moved watchlist updating to FileDeletForm::execute(), it has nothing to do in doDelete() (would also be executed for api requests, etc.)
* Added $user parameter to FileDeletForm::doDelete() to pass the user doing the action
* Use WikiPage instead of Article

docs/hooks.txt
includes/FileDeleteForm.php
includes/ImagePage.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index 9ff4bda..3536c35 100644 (file)
@@ -874,7 +874,7 @@ $user: User the list is being fetched for
 $file: reference to the deleted file
 $oldimage: in case of the deletion of an old image, the name of the old file
 $article: in case all revisions of the file are deleted a reference to the
-       article associated with the file.
+       WikiFilePage associated with the file.
 $user: user who performed the deletion
 $reason: reason
 
index 900b7d9..a528213 100644 (file)
@@ -39,7 +39,7 @@ class FileDeleteForm {
         * pending authentication, confirmation, etc.
         */
        public function execute() {
-               global $wgOut, $wgRequest, $wgUser;
+               global $wgOut, $wgRequest, $wgUser, $wgUploadMaintenance;
 
                $permissionErrors = $this->title->getUserPermissionsErrors( 'delete', $wgUser );
                if ( count( $permissionErrors ) ) {
@@ -50,6 +50,10 @@ class FileDeleteForm {
                        throw new ReadOnlyError;
                }
 
+               if ( $wgUploadMaintenance ) {
+                       throw new ErrorPageError( 'filedelete-maintenance-title', 'filedelete-maintenance' );
+               }
+
                $this->setHeaders();
 
                $this->oldimage = $wgRequest->getText( 'oldimage', false );
@@ -81,7 +85,7 @@ class FileDeleteForm {
                                $reason = $deleteReasonList;
                        }
 
-                       $status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress );
+                       $status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress, $wgUser );
 
                        if( !$status->isGood() ) {
                                $wgOut->addHTML( '<h2>' . $this->prepareMessage( 'filedeleteerror-short' ) . "</h2>\n" );
@@ -95,6 +99,12 @@ class FileDeleteForm {
                                // Return to the main page if we just deleted all versions of the
                                // file, otherwise go back to the description page
                                $wgOut->addReturnTo( $this->oldimage ? $this->title : Title::newMainPage() );
+
+                               if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
+                                       WatchAction::doWatch( $title, $wgUser );
+                               } elseif ( $this->title->userIsWatching() ) {
+                                       WatchAction::doUnwatch( $title, $wgUser );
+                               }
                        }
                        return;
                }
@@ -111,13 +121,16 @@ class FileDeleteForm {
         * @param $oldimage String: archive name
         * @param $reason String: reason of the deletion
         * @param $suppress Boolean: whether to mark all deleted versions as restricted
+        * @param $user User object performing the request
         */
-       public static function doDelete( &$title, &$file, &$oldimage, $reason, $suppress ) {
-               global $wgUser;
-               $article = null;
-               $status = Status::newFatal( 'error' );
+       public static function doDelete( &$title, &$file, &$oldimage, $reason, $suppress, User $user = null ) {
+               if ( $user === null ) {
+                       global $wgUser;
+                       $user = $wgUser;
+               }
 
                if( $oldimage ) {
+                       $page = null;
                        $status = $file->deleteOld( $oldimage, $reason, $suppress );
                        if( $status->ok ) {
                                // Need to do a log item
@@ -129,18 +142,14 @@ class FileDeleteForm {
                                $log->addEntry( 'delete', $title, $logComment );
                        }
                } else {
+                       $status = Status::newFatal( 'error' );
                        $id = $title->getArticleID( Title::GAID_FOR_UPDATE );
-                       $article = new Article( $title );
+                       $page = WikiPage::factory( $title );
                        $dbw = wfGetDB( DB_MASTER );
                        try {
                                // delete the associated article first
-                               if( $article->doDeleteArticle( $reason, $suppress, $id, false ) ) {
-                                       global $wgRequest;
-                                       if ( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
-                                               WatchAction::doWatch( $title, $wgUser );
-                                       } elseif ( $title->userIsWatching() ) {
-                                               WatchAction::doUnwatch( $title, $wgUser );
-                                       }
+                               $error = '';
+                               if ( $page->doDeleteArticle( $reason, $suppress, $id, false, $error, $user ) ) {
                                        $status = $file->delete( $reason, $suppress );
                                        if( $status->ok ) {
                                                $dbw->commit();
@@ -154,8 +163,10 @@ class FileDeleteForm {
                                throw $e;
                        }
                }
-               if( $status->isGood() )
-                       wfRunHooks('FileDeleteComplete', array( &$file, &$oldimage, &$article, &$wgUser, &$reason));
+
+               if ( $status->isGood() ) {
+                       wfRunHooks( 'FileDeleteComplete', array( &$file, &$oldimage, &$page, &$user, &$reason ) );
+               }
 
                return $status;
        }
index 0bed464..f9aab29 100644 (file)
@@ -789,19 +789,15 @@ EOT
         */
        public function delete() {
                global $wgUploadMaintenance;
-               if ( $wgUploadMaintenance && $this->getTitle() && $this->getTitle()->getNamespace() == NS_FILE ) {
-                       global $wgOut;
-                       $wgOut->wrapWikiMsg( "<div class='error'>\n$1\n</div>\n", array( 'filedelete-maintenance' ) );
-                       return;
-               }
 
-               $this->loadFile();
-               if ( !$this->mPage->getFile()->exists() || !$this->mPage->getFile()->isLocal() || $this->mPage->getFile()->getRedirected() ) {
+               $file = $this->mPage->getFile();
+               if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
                        // Standard article deletion
                        parent::delete();
                        return;
                }
-               $deleter = new FileDeleteForm( $this->mPage->getFile() );
+
+               $deleter = new FileDeleteForm( $file );
                $deleter->execute();
        }
 
index 79105de..79f7dee 100644 (file)
@@ -2365,23 +2365,24 @@ The description on its [$2 file description page] there is shown below.',
 'filerevert-badversion'     => 'There is no previous local version of this file with the provided timestamp.',
 
 # File deletion
-'filedelete'                  => 'Delete $1',
-'filedelete-legend'           => 'Delete file',
-'filedelete-intro'            => "You are about to delete the file '''[[Media:$1|$1]]''' along with all of its history.",
-'filedelete-intro-old'        => "You are deleting the version of '''[[Media:$1|$1]]''' as of [$4 $3, $2].",
-'filedelete-comment'          => 'Reason:',
-'filedelete-submit'           => 'Delete',
-'filedelete-success'          => "'''$1''' has been deleted.",
-'filedelete-success-old'      => "The version of '''[[Media:$1|$1]]''' as of $3, $2 has been deleted.",
-'filedelete-nofile'           => "'''$1''' does not exist.",
-'filedelete-nofile-old'       => "There is no archived version of '''$1''' with the specified attributes.",
-'filedelete-otherreason'      => 'Other/additional reason:',
-'filedelete-reason-otherlist' => 'Other reason',
-'filedelete-reason-dropdown'  => '*Common delete reasons
+'filedelete'                   => 'Delete $1',
+'filedelete-legend'            => 'Delete file',
+'filedelete-intro'             => "You are about to delete the file '''[[Media:$1|$1]]''' along with all of its history.",
+'filedelete-intro-old'         => "You are deleting the version of '''[[Media:$1|$1]]''' as of [$4 $3, $2].",
+'filedelete-comment'           => 'Reason:',
+'filedelete-submit'            => 'Delete',
+'filedelete-success'           => "'''$1''' has been deleted.",
+'filedelete-success-old'       => "The version of '''[[Media:$1|$1]]''' as of $3, $2 has been deleted.",
+'filedelete-nofile'            => "'''$1''' does not exist.",
+'filedelete-nofile-old'        => "There is no archived version of '''$1''' with the specified attributes.",
+'filedelete-otherreason'       => 'Other/additional reason:',
+'filedelete-reason-otherlist'  => 'Other reason',
+'filedelete-reason-dropdown'   => '*Common delete reasons
 ** Copyright violation
 ** Duplicated file',
-'filedelete-edit-reasonlist'  => 'Edit delete reasons',
-'filedelete-maintenance'      => 'Deletion and restoration of files temporarily disabled during maintenance.',
+'filedelete-edit-reasonlist'   => 'Edit delete reasons',
+'filedelete-maintenance'       => 'Deletion and restoration of files temporarily disabled during maintenance.',
+'filedelete-maintenance-title' => 'Cannot delete file',
 
 # MIME search
 'mimesearch'         => 'MIME search',
index 7588e2e..f27a885 100644 (file)
@@ -2015,30 +2015,32 @@ $1 is the name of the shared repository. On wikimedia sites, $1 is {{msg-mw|shar
 {{Identical|Revert}}',
 
 # File deletion
-'filedelete-legend'           => '{{Identical|Delete}}',
-'filedelete-intro-old'        => 'Message displayed when you try to delete a version of a file.
+'filedelete-legend'            => '{{Identical|Delete}}',
+'filedelete-intro-old'         => 'Message displayed when you try to delete a version of a file.
 * $1 is the name of the media
 * $2 is a date
 * $3 is a hour
 * $4 is a URL and must follow square bracket: [$4',
-'filedelete-comment'          => '{{Identical|Reason}}',
-'filedelete-submit'           => 'Delete button when deleting a file for admins
+'filedelete-comment'           => '{{Identical|Reason}}',
+'filedelete-submit'            => 'Delete button when deleting a file for admins
 
 {{Identical|Delete}}',
-'filedelete-success-old'      => 'Message displayed when you succeed in deleting a version of a file.
+'filedelete-success-old'       => 'Message displayed when you succeed in deleting a version of a file.
 * $1 is the name of the media
 * $2 is a date
 * $3 is a hour',
-'filedelete-otherreason'      => 'Message used when deleting a file. This is the description field for "Other/additional reason" for deletion.
+'filedelete-otherreason'       => 'Message used when deleting a file. This is the description field for "Other/additional reason" for deletion.
 
 {{Identical|Other/additional reason}}',
-'filedelete-reason-otherlist' => 'Message used as default in the dropdown menu in the form for deleting a file. Keeping this message selected assumes that a reason for deletion is specified in the field below.
+'filedelete-reason-otherlist'  => 'Message used as default in the dropdown menu in the form for deleting a file. Keeping this message selected assumes that a reason for deletion is specified in the field below.
 
 {{Identical|Other reason}}',
-'filedelete-reason-dropdown'  => 'Predefined reasons for deleting a file that can be selected in a drop down list. Entries prefixed with one asterisk ("*") are group headers and cannot be selected. Entries prefixed with two asterisks can be selected as reason for deletion.',
-'filedelete-edit-reasonlist'  => 'Shown beneath the file deletion form on the right side. It is a link to [[MediaWiki:Filedelete-reason-dropdown]].
+'filedelete-reason-dropdown'   => 'Predefined reasons for deleting a file that can be selected in a drop down list. Entries prefixed with one asterisk ("*") are group headers and cannot be selected. Entries prefixed with two asterisks can be selected as reason for deletion.',
+'filedelete-edit-reasonlist'   => 'Shown beneath the file deletion form on the right side. It is a link to [[MediaWiki:Filedelete-reason-dropdown]].
 
 {{Identical|Edit delete reasons}}',
+'filedelete-maintenance'       => 'Content of the error page when $wgUploadMaintenance is set to true.',
+'filedelete-maintenance-title' => 'Title of the error page when $wgUploadMaintenance is set to true.',
 
 # MIME search
 'mimesearch'         => 'Title of [[Special:MIMESearch]].',
index 42fd76b..71b0995 100644 (file)
@@ -1481,6 +1481,7 @@ $wgMessageStructure = array(
                'filedelete-reason-dropdown',
                'filedelete-edit-reasonlist',
                'filedelete-maintenance',
+               'filedelete-maintenance-title',
        ),
        'mimesearch' => array(
                'mimesearch',