+ /**
+ * 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 .= wfMsgForContent( 'colon-separator' ) . $reason;
+ $log->addEntry( 'delete', $title, $logComment );
+ }
+ } else {
+ $id = $title->getArticleID( 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' ) && $wgUser->isLoggedIn() ) {
+ $article->doWatch();
+ } elseif( $title->userIsWatching() ) {
+ $article->doUnwatch();
+ }
+ $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() )
+ wfRunHooks('FileDeleteComplete', array( &$file, &$oldimage, &$article, &$wgUser, &$reason));
+
+ return $status;
+ }
+