Merge "includes: Replace implicit Bugzilla bug numbers with Phab ones"
[lhc/web/wiklou.git] / includes / FileDeleteForm.php
index ae186bc..f284d92 100644 (file)
@@ -21,6 +21,7 @@
  * @author Rob Church <robchur@gmail.com>
  * @ingroup Media
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * File deletion user interface
@@ -125,7 +126,7 @@ class FileDeleteForm {
                                        $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' )
                                        . '</div>' );
                        }
-                       if ( $status->ok ) {
+                       if ( $status->isOK() ) {
                                $wgOut->setPageTitle( wfMessage( 'actioncomplete' ) );
                                $wgOut->addHTML( $this->prepareMessage( 'filedelete-success' ) );
                                // Return to the main page if we just deleted all versions of the
@@ -150,11 +151,12 @@ class FileDeleteForm {
         * @param string $reason Reason of the deletion
         * @param bool $suppress Whether to mark all deleted versions as restricted
         * @param User $user User object performing the request
+        * @param array $tags Tags to apply to the deletion action
         * @throws MWException
-        * @return bool|Status
+        * @return Status
         */
        public static function doDelete( &$title, &$file, &$oldimage, $reason,
-               $suppress, User $user = null
+               $suppress, User $user = null, $tags = []
        ) {
                if ( $user === null ) {
                        global $wgUser;
@@ -178,8 +180,11 @@ class FileDeleteForm {
                                $logEntry->setPerformer( $user );
                                $logEntry->setTarget( $title );
                                $logEntry->setComment( $logComment );
+                               $logEntry->setTags( $tags );
                                $logid = $logEntry->insert();
                                $logEntry->publish( $logid );
+
+                               $status->value = $logid;
                        }
                } else {
                        $status = Status::newFatal( 'cannotdelete',
@@ -187,28 +192,31 @@ class FileDeleteForm {
                        );
                        $page = WikiPage::factory( $title );
                        $dbw = wfGetDB( DB_MASTER );
-                       try {
-                               // delete the associated article first
-                               $error = '';
-                               $deleteStatus = $page->doDeleteArticleReal( $reason, $suppress, 0, false, $error, $user );
-                               // doDeleteArticleReal() returns a non-fatal error status if the page
-                               // or revision is missing, so check for isOK() rather than isGood()
-                               if ( $deleteStatus->isOK() ) {
-                                       $status = $file->delete( $reason, $suppress, $user );
-                                       if ( !$status->isOK() ) {
-                                               $dbw->rollback( __METHOD__ );
-                                       }
+                       $dbw->startAtomic( __METHOD__ );
+                       // delete the associated article first
+                       $error = '';
+                       $deleteStatus = $page->doDeleteArticleReal( $reason, $suppress, 0, false, $error,
+                               $user, $tags );
+                       // doDeleteArticleReal() returns a non-fatal error status if the page
+                       // or revision is missing, so check for isOK() rather than isGood()
+                       if ( $deleteStatus->isOK() ) {
+                               $status = $file->delete( $reason, $suppress, $user );
+                               if ( $status->isOK() ) {
+                                       $status->value = $deleteStatus->value; // log id
+                                       $dbw->endAtomic( __METHOD__ );
+                               } else {
+                                       // Page deleted but file still there? rollback page delete
+                                       $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+                                       $lbFactory->rollbackMasterChanges( __METHOD__ );
                                }
-                       } catch ( Exception $e ) {
-                               // Rollback before returning to prevent UI from displaying
-                               // incorrect "View or restore N deleted edits?"
-                               $dbw->rollback( __METHOD__ );
-                               throw $e;
+                       } else {
+                               // Done; nothing changed
+                               $dbw->endAtomic( __METHOD__ );
                        }
                }
 
                if ( $status->isOK() ) {
-                       Hooks::run( 'FileDeleteComplete', array( &$file, &$oldimage, &$page, &$user, &$reason ) );
+                       Hooks::run( 'FileDeleteComplete', [ &$file, &$oldimage, &$page, &$user, &$reason ] );
                }
 
                return $status;
@@ -225,7 +233,7 @@ class FileDeleteForm {
                                        <td></td>
                                        <td class='mw-input'><strong>" .
                                                Xml::checkLabel( wfMessage( 'revdelete-suppress' )->text(),
-                                                       'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '3' ) ) .
+                                                       'wpSuppress', 'wpSuppress', false, [ 'tabindex' => '3' ] ) .
                                        "</strong></td>
                                </tr>";
                } else {
@@ -233,13 +241,13 @@ class FileDeleteForm {
                }
 
                $checkWatch = $wgUser->getBoolOption( 'watchdeletion' ) || $wgUser->isWatched( $this->title );
-               $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getAction(),
-                       'id' => 'mw-img-deleteconfirm' ) ) .
+               $form = Xml::openElement( 'form', [ 'method' => 'post', 'action' => $this->getAction(),
+                       'id' => 'mw-img-deleteconfirm' ] ) .
                        Xml::openElement( 'fieldset' ) .
                        Xml::element( 'legend', null, wfMessage( 'filedelete-legend' )->text() ) .
                        Html::hidden( 'wpEditToken', $wgUser->getEditToken( $this->oldimage ) ) .
                        $this->prepareMessage( 'filedelete-intro' ) .
-                       Xml::openElement( 'table', array( 'id' => 'mw-img-deleteconfirm-table' ) ) .
+                       Xml::openElement( 'table', [ 'id' => 'mw-img-deleteconfirm-table' ] ) .
                        "<tr>
                                <td class='mw-label'>" .
                                        Xml::label( wfMessage( 'filedelete-comment' )->text(), 'wpDeleteReasonList' ) .
@@ -261,7 +269,7 @@ class FileDeleteForm {
                                "</td>
                                <td class='mw-input'>" .
                                        Xml::input( 'wpReason', 60, $wgRequest->getText( 'wpReason' ),
-                                               array( 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ) ) .
+                                               [ 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ] ) .
                                "</td>
                        </tr>
                        {$suppress}";
@@ -271,7 +279,7 @@ class FileDeleteForm {
                                <td></td>
                                <td class='mw-input'>" .
                                        Xml::checkLabel( wfMessage( 'watchthis' )->text(),
-                                               'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) .
+                                               'wpWatch', 'wpWatch', $checkWatch, [ 'tabindex' => '3' ] ) .
                                "</td>
                        </tr>";
                }
@@ -281,11 +289,11 @@ class FileDeleteForm {
                                <td class='mw-submit'>" .
                                        Xml::submitButton(
                                                wfMessage( 'filedelete-submit' )->text(),
-                                               array(
+                                               [
                                                        'name' => 'mw-filedelete-submit',
                                                        'id' => 'mw-filedelete-submit',
                                                        'tabindex' => '4'
-                                               )
+                                               ]
                                        ) .
                                "</td>
                        </tr>" .
@@ -295,11 +303,12 @@ class FileDeleteForm {
 
                        if ( $wgUser->isAllowed( 'editinterface' ) ) {
                                $title = wfMessage( 'filedelete-reason-dropdown' )->inContentLanguage()->getTitle();
-                               $link = Linker::linkKnown(
+                               $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
+                               $link = $linkRenderer->makeKnownLink(
                                        $title,
-                                       wfMessage( 'filedelete-edit-reasonlist' )->escaped(),
-                                       array(),
-                                       array( 'action' => 'edit' )
+                                       wfMessage( 'filedelete-edit-reasonlist' )->text(),
+                                       [],
+                                       [ 'action' => 'edit' ]
                                );
                                $form .= '<p class="mw-filedelete-editreasons">' . $link . '</p>';
                        }
@@ -388,7 +397,7 @@ class FileDeleteForm {
         * @return string
         */
        private function getAction() {
-               $q = array();
+               $q = [];
                $q['action'] = 'delete';
 
                if ( $this->oldimage ) {