* @internal documentation reviewed 15 Mar 2010
*/
class WikiPage extends Page {
- // doDeleteArticleReal() return values. Values less than zero indicate fatal errors,
- // values greater than zero indicate that there were problems not resulting in page
- // not being deleted
-
- /**
- * 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;
-
// Constants for $mDataLoadedFrom and related
/**
}
/**
- * Same as doDeleteArticleReal(), but returns more detailed success/failure status
+ * Same as doDeleteArticleReal(), but returns a simple boolean. This is kept around for
+ * backwards compatibility, if you care about error reporting you should use
+ * doDeleteArticleReal() instead.
+ *
* Deletes the article with database consistency, writes logs, purges caches
*
* @param $reason string delete reason for deletion log
public function doDeleteArticle(
$reason, $suppress = false, $id = 0, $commit = true, &$error = '', User $user = null
) {
- return $this->doDeleteArticleReal( $reason, $suppress, $id, $commit, $error, $user )
- == WikiPage::DELETE_SUCCESS;
+ $status = $this->doDeleteArticleReal( $reason, $suppress, $id, $commit, $error, $user );
+ return $status->isGood();
}
/**
* @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 WikiPage::DELETE_* constants
+ * @return Status: Status object; if successful, $status->value is the log_id of the
+ * deletion log entry. If the page couldn't be deleted because it wasn't
+ * found, $status is a non-fatal 'cannotdelete' error
*/
public function doDeleteArticleReal(
$reason, $suppress = false, $id = 0, $commit = true, &$error = '', User $user = null
wfDebug( __METHOD__ . "\n" );
+ $status = Status::newGood();
+
if ( $this->mTitle->getDBkey() === '' ) {
- return WikiPage::DELETE_NO_PAGE;
+ $status->error( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
+ return $status;
}
$user = is_null( $user ) ? $wgUser : $user;
- if ( ! wfRunHooks( 'ArticleDelete', array( &$this, &$user, &$reason, &$error ) ) ) {
- return WikiPage::DELETE_HOOK_ABORTED;
+ if ( ! wfRunHooks( 'ArticleDelete', array( &$this, &$user, &$reason, &$error, &$status ) ) ) {
+ if ( $status->isOK() ) {
+ // Hook aborted but didn't set a fatal status
+ $status->fatal( 'delete-hook-aborted' );
+ }
+ return $status;
}
if ( $id == 0 ) {
$this->loadPageData( 'forupdate' );
$id = $this->getID();
if ( $id == 0 ) {
- return WikiPage::DELETE_NO_PAGE;
+ $status->error( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
+ return $status;
}
}
if ( !$ok ) {
$dbw->rollback( __METHOD__ );
- return WikiPage::DELETE_NO_REVISIONS;
+ $status->error( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
+ return $status;
}
$this->doDeleteUpdates( $id );
}
wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id ) );
- return WikiPage::DELETE_SUCCESS;
+ $status->value = $logid;
+ return $status;
}
/**