* Really delete the file
*
* @param $title Title object
- * @param $file File object
+ * @param File $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
$log->addEntry( 'delete', $title, $logComment );
}
} else {
- $status = Status::newFatal( 'error' );
+ $status = Status::newFatal( 'cannotdelete',
+ wfEscapeWikiText( $title->getPrefixedText() )
+ );
$page = WikiPage::factory( $title );
$dbw = wfGetDB( DB_MASTER );
try {
// delete the associated article first
$error = '';
- if ( $page->doDeleteArticle( $reason, $suppress, 0, false, $error, $user ) ) {
+ if ( $page->doDeleteArticleReal( $reason, $suppress, 0, false, $error, $user ) >= Page::DELETE_SUCCESS ) {
$status = $file->delete( $reason, $suppress );
- if( $status->ok ) {
+ if( $status->isOK() ) {
$dbw->commit();
} else {
$dbw->rollback();
}
}
- if ( $status->isGood() ) {
+ if ( $status->isOK() ) {
wfRunHooks( 'FileDeleteComplete', array( &$file, &$oldimage, &$page, &$user, &$reason ) );
}
/**
* Abstract class for type hinting (accepts WikiPage, Article, ImagePage, CategoryPage)
*/
-abstract class Page {}
+abstract class Page {
+ // doDeleteArticleReal() return values. Values less than zero indicate fatal errors,
+ // values greater than zero indicate that there were non-fatal problems.
+
+ /**
+ * Delete operation aborted by hook
+ */
+ const DELETE_HOOK_ABORTED = -1;
+
+ /**
+ * Deletion successful
+ */
+ const DELETE_SUCCESS = 0;
+
+ /**
+ * Page not found
+ */
+ const DELETE_NO_PAGE = 1;
+
+ /**
+ * No revisions found to delete
+ */
+ const DELETE_NO_REVISIONS = 2;
+}
/**
* Class representing a MediaWiki article and history.
}
/**
- * Back-end article deletion
+ * Same as doDeleteArticleReal(), but returns more detailed success/failure status
* Deletes the article with database consistency, writes logs, purges caches
*
* @param $reason string delete reason for deletion log
* @param $id int article ID
* @param $commit boolean defaults to true, triggers transaction end
* @param &$error Array of errors to append to
- * @param $user User The relevant user
+ * @param $user User The deleting user
* @return boolean true if successful
*/
public function doDeleteArticle(
$reason, $suppress = false, $id = 0, $commit = true, &$error = '', User $user = null
+ ) {
+ return $this->doDeleteArticleReal( $reason, $suppress, $id, $commit, $error, $user )
+ != Page::DELETE_SUCCESS;
+ }
+
+ /**
+ * Back-end article deletion
+ * Deletes the article with database consistency, writes logs, purges caches
+ *
+ * @param $reason string delete reason for deletion log
+ * @param $suppress bitfield
+ * Revision::DELETED_TEXT
+ * Revision::DELETED_COMMENT
+ * Revision::DELETED_USER
+ * Revision::DELETED_RESTRICTED
+ * @param $id int article ID
+ * @param $commit boolean defaults to true, triggers transaction end
+ * @param &$error Array of errors to append to
+ * @param $user User The deleting user
+ * @return int: One of Page::DELETE_* constants
+ */
+ public function doDeleteArticleReal(
+ $reason, $suppress = false, $id = 0, $commit = true, &$error = '', User $user = null
) {
global $wgUser;
$user = is_null( $user ) ? $wgUser : $user;
wfDebug( __METHOD__ . "\n" );
if ( ! wfRunHooks( 'ArticleDelete', array( &$this, &$user, &$reason, &$error ) ) ) {
- return false;
+ return Page::DELETE_HOOK_ABORTED;
}
$dbw = wfGetDB( DB_MASTER );
$t = $this->mTitle->getDBkey();
$id = $id ? $id : $this->mTitle->getArticleID( Title::GAID_FOR_UPDATE );
if ( $t === '' || $id == 0 ) {
- return false;
+ return Page::DELETE_NO_PAGE;
}
// Bitfields to further suppress the content
if ( !$ok ) {
$dbw->rollback();
- return false;
+ return Page::DELETE_NO_REVISIONS;
}
$this->doDeleteUpdates( $id );
}
wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id ) );
- return true;
+ return Page::DELETE_SUCCESS;
}
/**