]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/FileDeleteForm.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / includes / FileDeleteForm.php
index 5177d35fe71ac356041d62c083212e68aa45473c..030330bbeb10c285ba8beb038879b90d2d79a94c 100644 (file)
@@ -17,7 +17,7 @@ class FileDeleteForm {
        /**
         * Constructor
         *
-        * @param File $file File we're deleting
+        * @param $file File object we're deleting
         */
        public function __construct( $file ) {
                $this->title = $file->getTitle();
@@ -90,36 +90,59 @@ class FileDeleteForm {
                $this->showLogEntries();
        }
 
+       /**
+        * Really delete the file
+        *
+        * @param $title Title object
+        * @param $file File object
+        * @param $oldimage String: archive name
+        * @param $reason String: reason of the deletion
+        * @param $suppress Boolean: whether to mark all deleted versions as restricted
+        */
        public static function doDelete( &$title, &$file, &$oldimage, $reason, $suppress ) {
+               global $wgUser;
                $article = null;
+               $status = Status::newFatal( 'error' );
+
                if( $oldimage ) {
                        $status = $file->deleteOld( $oldimage, $reason, $suppress );
                        if( $status->ok ) {
                                // Need to do a log item
                                $log = new LogPage( 'delete' );
                                $logComment = wfMsgForContent( 'deletedrevision', $oldimage );
-                               if( trim( $reason ) != '' )
-                                       $logComment .= ": {$reason}";
-                                       $log->addEntry( 'delete', $title, $logComment );
+                               if( trim( $reason ) != '' ) {
+                                       $logComment .= wfMsgForContent( 'colon-separator' ) . $reason;
+                               }
+                               $log->addEntry( 'delete', $title, $logComment );
                        }
                } else {
-                       $status = $file->delete( $reason, $suppress );
-                       if( $status->ok ) {
-                               $id = $title->getArticleID( GAID_FOR_UPDATE );
-                               // Need to delete the associated article
-                               $article = new Article( $title );
-                               $error = '';
-                               if( wfRunHooks('ArticleDelete', array(&$article, &$wgUser, &$reason, &$error)) ) {
-                                       if( $article->doDeleteArticle( $reason, $suppress, $id ) ) {
+                       $id = $title->getArticleID( Title::GAID_FOR_UPDATE );
+                       $article = new Article( $title );
+                       $error = '';
+                       $dbw = wfGetDB( DB_MASTER );
+                       try {
+                               if( wfRunHooks( 'ArticleDelete', array( &$article, &$wgUser, &$reason, &$error ) ) ) {
+                                       // delete the associated article first
+                                       if( $article->doDeleteArticle( $reason, $suppress, $id, false ) ) {
                                                global $wgRequest;
-                                               if( $wgRequest->getCheck( 'wpWatch' ) ) {
+                                               if( $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn() ) {
                                                        $article->doWatch();
                                                } elseif( $title->userIsWatching() ) {
                                                        $article->doUnwatch();
                                                }
-                                               wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $id));
+                                               $status = $file->delete( $reason, $suppress );
+                                               if( $status->ok ) {
+                                                       $dbw->commit();
+                                                       wfRunHooks( 'ArticleDeleteComplete', array( &$article, &$wgUser, $reason, $id ) );
+                                               } else {
+                                                       $dbw->rollback();
+                                               }
                                        }
                                }
+                       } catch ( MWException $e ) {
+                               // rollback before returning to prevent UI from displaying incorrect "View or restore N deleted edits?"
+                               $dbw->rollback();
+                               throw $e;
                        }
                }
                if( $status->isGood() ) 
@@ -137,10 +160,10 @@ class FileDeleteForm {
                if( $wgUser->isAllowed( 'suppressrevision' ) ) {
                        $suppress = "<tr id=\"wpDeleteSuppressRow\">
                                        <td></td>
-                                       <td class='mw-input'>" .
+                                       <td class='mw-input'><strong>" .
                                                Xml::checkLabel( wfMsg( 'revdelete-suppress' ),
                                                        'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '3' ) ) .
-                                       "</td>
+                                       "</strong></td>
                                </tr>";
                } else {
                        $suppress = '';
@@ -151,7 +174,7 @@ class FileDeleteForm {
                        'id' => 'mw-img-deleteconfirm' ) ) .
                        Xml::openElement( 'fieldset' ) .
                        Xml::element( 'legend', null, wfMsg( 'filedelete-legend' ) ) .
-                       Xml::hidden( 'wpEditToken', $wgUser->editToken( $this->oldimage ) ) .
+                       Html::hidden( 'wpEditToken', $wgUser->editToken( $this->oldimage ) ) .
                        $this->prepareMessage( 'filedelete-intro' ) .
                        Xml::openElement( 'table', array( 'id' => 'mw-img-deleteconfirm-table' ) ) .
                        "<tr>
@@ -173,14 +196,18 @@ class FileDeleteForm {
                                                array( 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ) ) .
                                "</td>
                        </tr>
-                       {$suppress}
+                       {$suppress}";
+               if( $wgUser->isLoggedIn() ) {   
+                       $form .= "
                        <tr>
                                <td></td>
                                <td class='mw-input'>" .
                                        Xml::checkLabel( wfMsg( 'watchthis' ),
                                                'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
                                "</td>
-                       </tr>
+                       </tr>";
+               }
+               $form .= "
                        <tr>
                                <td></td>
                                <td class='mw-submit'>" .
@@ -194,7 +221,13 @@ class FileDeleteForm {
 
                        if ( $wgUser->isAllowed( 'editinterface' ) ) {
                                $skin = $wgUser->getSkin();
-                               $link = $skin->makeLink ( 'MediaWiki:Filedelete-reason-dropdown', wfMsgHtml( 'filedelete-edit-reasonlist' ) );
+                               $title = Title::makeTitle( NS_MEDIAWIKI, 'Filedelete-reason-dropdown' );
+                               $link = $skin->link(
+                                       $title,
+                                       wfMsgHtml( 'filedelete-edit-reasonlist' ),
+                                       array(),
+                                       array( 'action' => 'edit' )
+                               );
                                $form .= '<p class="mw-filedelete-editreasons">' . $link . '</p>';
                        }
 
@@ -215,13 +248,12 @@ class FileDeleteForm {
         * showing an appropriate message depending upon whether
         * it's a current file or an old version
         *
-        * @param string $message Message base
-        * @return string
+        * @param $message String: message base
+        * @return String
         */
        private function prepareMessage( $message ) {
                global $wgLang;
                if( $this->oldimage ) {
-                       $url = $this->file->getArchiveUrl( $this->oldimage );
                        return wfMsgExt(
                                "{$message}-old", # To ensure grep will find them: 'filedelete-intro-old', 'filedelete-nofile-old', 'filedelete-success-old'
                                'parse',
@@ -245,7 +277,16 @@ class FileDeleteForm {
                global $wgOut, $wgUser;
                $wgOut->setPageTitle( wfMsg( 'filedelete', $this->title->getText() ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
-               $wgOut->setSubtitle( wfMsg( 'filedelete-backlink', $wgUser->getSkin()->makeKnownLinkObj( $this->title ) ) );
+               $wgOut->setSubtitle( wfMsg(
+                       'filedelete-backlink',
+                       $wgUser->getSkin()->link(
+                               $this->title,
+                               null,
+                               array(),
+                               array(),
+                               array( 'known', 'noclasses' )
+                       )
+               ) );
        }
 
        /**
@@ -279,10 +320,12 @@ class FileDeleteForm {
         */
        private function getAction() {
                $q = array();
-               $q[] = 'action=delete';
+               $q['action'] = 'delete';
+
                if( $this->oldimage )
-                       $q[] = 'oldimage=' . urlencode( $this->oldimage );
-               return $this->title->getLocalUrl( implode( '&', $q ) );
+                       $q['oldimage'] = $this->oldimage;
+
+               return $this->title->getLocalUrl( $q );
        }
 
        /**
@@ -293,5 +336,4 @@ class FileDeleteForm {
        private function getTimestamp() {
                return $this->oldfile->getTimestamp();
        }
-
 }