/**
* Constructor
*
- * @param File $file File we're deleting
+ * @param $file File object we're deleting
*/
public function __construct( $file ) {
$this->title = $file->getTitle();
return;
}
$permission_errors = $this->title->getUserPermissionsErrors('delete', $wgUser);
- if (count($permission_errors)>0) {
+ if ( count( $permission_errors ) > 0 ) {
$wgOut->showPermissionsErrorPage( $permission_errors );
return;
}
$status = self::doDelete( $this->title, $this->file, $this->oldimage, $reason, $suppress );
- if( !$status->isGood() )
+ if( !$status->isGood() ) {
+ $wgOut->addHTML( '<h2>' . $this->prepareMessage( 'filedeleteerror-short' ) . "</h2>\n" );
+ $wgOut->addHTML( '<span class="error">' );
$wgOut->addWikiText( $status->getWikiText( 'filedeleteerror-short', 'filedeleteerror-long' ) );
+ $wgOut->addHTML( '</span>' );
+ }
if( $status->ok ) {
$wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
$wgOut->addHTML( $this->prepareMessage( 'filedelete-success' ) );
$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 ) ) {
- global $wgRequest;
- if( $wgRequest->getCheck( 'wpWatch' ) ) {
- $article->doWatch();
- } elseif( $title->userIsWatching() ) {
- $article->doUnwatch();
- }
- wfRunHooks('ArticleDeleteComplete', array(&$article, &$wgUser, $reason, $id));
+ $id = $title->getArticleID( Title::GAID_FOR_UPDATE );
+ $article = new Article( $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 );
+ }
+ $status = $file->delete( $reason, $suppress );
+ if( $status->ok ) {
+ $dbw->commit();
+ } 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() )
+ if( $status->isGood() )
wfRunHooks('FileDeleteComplete', array( &$file, &$oldimage, &$article, &$wgUser, &$reason));
return $status;
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 = '';
'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>
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'>" .
* 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',
- $this->title->getText(),
+ wfEscapeWikiText( $this->title->getText() ),
$wgLang->date( $this->getTimestamp(), true ),
$wgLang->time( $this->getTimestamp(), true ),
- wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ) ) );
+ wfExpandUrl( $this->file->getArchiveUrl( $this->oldimage ), PROTO_CURRENT ) );
} else {
return wfMsgExt(
$message,
'parse',
- $this->title->getText()
+ wfEscapeWikiText( $this->title->getText() )
);
}
}