X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FFileDeleteForm.php;h=f284d924a06e4e395dd84f7b0bade6bdc3d82508;hb=17eda64357834fa847126d8d7f49f6f5b42c4d89;hp=5e7f5b2635f6302de5bdb7b898b16c588e9e5238;hpb=27dfd0aff41243e35b31ecbfe4ed34cbbe6f57a6;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index 5e7f5b2635..f284d924a0 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -21,6 +21,7 @@ * @author Rob Church * @ingroup Media */ +use MediaWiki\MediaWikiServices; /** * File deletion user interface @@ -125,7 +126,7 @@ class FileDeleteForm { $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' ) . '' ); } - 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,6 +180,7 @@ class FileDeleteForm { $logEntry->setPerformer( $user ); $logEntry->setTarget( $title ); $logEntry->setComment( $logComment ); + $logEntry->setTags( $tags ); $logid = $logEntry->insert(); $logEntry->publish( $logid ); @@ -189,31 +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->commit( __METHOD__ ); - $status->value = $deleteStatus->value; // log id - } else { - $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; @@ -230,7 +233,7 @@ class FileDeleteForm { " . Xml::checkLabel( wfMessage( 'revdelete-suppress' )->text(), - 'wpSuppress', 'wpSuppress', false, array( 'tabindex' => '3' ) ) . + 'wpSuppress', 'wpSuppress', false, [ 'tabindex' => '3' ] ) . " "; } else { @@ -238,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' ] ) . " " . Xml::label( wfMessage( 'filedelete-comment' )->text(), 'wpDeleteReasonList' ) . @@ -266,7 +269,7 @@ class FileDeleteForm { " " . Xml::input( 'wpReason', 60, $wgRequest->getText( 'wpReason' ), - array( 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ) ) . + [ 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ] ) . " {$suppress}"; @@ -276,7 +279,7 @@ class FileDeleteForm { " . Xml::checkLabel( wfMessage( 'watchthis' )->text(), - 'wpWatch', 'wpWatch', $checkWatch, array( 'tabindex' => '3' ) ) . + 'wpWatch', 'wpWatch', $checkWatch, [ 'tabindex' => '3' ] ) . " "; } @@ -286,11 +289,11 @@ class FileDeleteForm { " . Xml::submitButton( wfMessage( 'filedelete-submit' )->text(), - array( + [ 'name' => 'mw-filedelete-submit', 'id' => 'mw-filedelete-submit', 'tabindex' => '4' - ) + ] ) . " " . @@ -300,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 .= '

' . $link . '

'; } @@ -393,7 +397,7 @@ class FileDeleteForm { * @return string */ private function getAction() { - $q = array(); + $q = []; $q['action'] = 'delete'; if ( $this->oldimage ) {