* @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;
+
/**
* @var Title
*/
*
* @param $id Int article ID to load
*
- * @return WikiPage
+ * @return WikiPage|null
*/
public static function newFromID( $id ) {
$t = Title::newFromID( $id );
/**
* Get the text of the current revision. No side-effects...
*
- * @return String|false The text of the current revision
+ * @return String|bool The text of the current revision. False on failure
*/
public function getRawText() { #FIXME: deprecated, replace usage!
return $this->getText( Revision::RAW );
if ( !$this->mTimestamp ) {
$this->loadLastEdit();
}
+
return wfTimestamp( TS_MW, $this->mTimestamp );
}
/**
* Perform the actions of a page purging
+ * @return bool
*/
public function doPurge() {
global $wgUseSquid;
if ( $wgUseSquid ) {
// Commit the transaction before the purge is sent
$dbw = wfGetDB( DB_MASTER );
- $dbw->commit();
+ $dbw->commit( __METHOD__ );
// Send purge
$update = SquidUpdate::newSimplePurge( $this->mTitle );
* @param $dbw DatabaseBase
* @param $redirectTitle Title object pointing to the redirect target,
* or NULL if this is not a redirect
- * @param $lastRevIsRedirect If given, will optimize adding and
+ * @param $lastRevIsRedirect null|bool If given, will optimize adding and
* removing rows in redirect table.
* @return bool true on success, false on failure
* @private
* If the given revision is newer than the currently set page_latest,
* update the page record. Otherwise, do nothing.
*
- * @param $dbw Database object
+ * @param $dbw DatabaseBase object
* @param $revision Revision object
* @return mixed
*/
}
/**
- * @param $section empty/null/false or a section number (0, 1, 2, T1, T2...)
+ * @param $section null|bool|int or a section number (0, 1, 2, T1, T2...)
* @param $text String: new text of the section
* @param $sectionTitle String: new section's subject, only if $section is 'new'
* @param $edittime String: revision timestamp or null to use the current revision
* edit-already-exists error will be returned. These two conditions are also possible with
* auto-detection due to MediaWiki's performance-optimised locking strategy.
*
- * @param $baseRevId the revision ID this edit was based off, if any
+ * @param $baseRevId int the revision ID this edit was based off, if any
* @param $user User the user doing the edit
*
* @return Status object. Possible errors:
$changed = !$content->equals( $old_content );
if ( $changed ) {
- $dbw->begin();
+ $dbw->begin( __METHOD__ );
$revisionId = $revision->insertOn( $dbw );
# Update page
}
$revisionId = 0;
- $dbw->rollback();
+ $dbw->rollback( __METHOD__ );
} else {
global $wgUseRCPatrol;
wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
# Log auto-patrolled edits
if ( $patrolled ) {
- PatrolLog::record( $rc, true );
+ PatrolLog::record( $rc, true, $user );
}
}
$user->incEditCount();
- $dbw->commit();
+ $dbw->commit( __METHOD__ );
}
} else {
// Bug 32948: revision ID must be set to page {{REVISIONID}} and
# Create new article
$status->value['new'] = true;
- $dbw->begin();
+ $dbw->begin( __METHOD__ );
# Add the page record; stake our claim on this title!
# This will return false if the article already exists
$newid = $this->insertOn( $dbw );
if ( $newid === false ) {
- $dbw->rollback();
+ $dbw->rollback( __METHOD__ );
$status->fatal( 'edit-already-exists' );
wfProfileOut( __METHOD__ );
# Log auto-patrolled edits
if ( $patrolled ) {
- PatrolLog::record( $rc, true );
+ PatrolLog::record( $rc, true, $user );
}
}
$user->incEditCount();
- $dbw->commit();
+ $dbw->commit( __METHOD__ );
# Update links, etc.
$this->doEditUpdates( $revision, $user, array( 'created' => true ) );
}
/**
- * 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 $suppress bitfield
+ * @param $suppress int 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 &$errors Array of errors to append to
- * @param $user User The relevant user
+ * @param &$error Array of errors to append to
+ * @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 )
+ == WikiPage::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 int 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 WikiPage::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 WikiPage::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 WikiPage::DELETE_NO_PAGE;
}
// Bitfields to further suppress the content
$bitfield = 'rev_deleted';
}
- $dbw->begin();
+ $dbw->begin( __METHOD__ );
// For now, shunt the revision data into the archive table.
// Text is *not* removed from the text table; bulk storage
// is left intact to avoid breaking block-compression or
# Now that it's safely backed up, delete it
$dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__ );
- $ok = ( $dbw->affectedRows() > 0 ); // getArticleId() uses slave, could be laggy
+ $ok = ( $dbw->affectedRows() > 0 ); // getArticleID() uses slave, could be laggy
if ( !$ok ) {
- $dbw->rollback();
- return false;
+ $dbw->rollback( __METHOD__ );
+ return WikiPage::DELETE_NO_REVISIONS;
}
$this->doDeleteUpdates( $id );
$logEntry->publish( $logid );
if ( $commit ) {
- $dbw->commit();
+ $dbw->commit( __METHOD__ );
}
wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id ) );
- return true;
+ return WikiPage::DELETE_SUCCESS;
}
/**
# Clear caches
self::onArticleDelete( $this->mTitle );
+ # Reset this object
+ $this->clear();
+
# Clear the cached article id so the interface doesn't act like we exist
$this->mTitle->resetArticleID( 0 );
}
*
* @param $resultDetails Array: contains result-specific array of additional values
* @param $guser User The user performing the rollback
+ * @return array
*/
public function commitRollback( $fromP, $summary, $bot, &$resultDetails, User $guser ) {
global $wgUseRCPatrol, $wgContLang;
}
# Get the last editor
- $current = Revision::newFromTitle( $this->mTitle );
+ $current = $this->getRevision();
if ( is_null( $current ) ) {
# Something wrong... no page?
return array( array( 'notanarticle' ) );
$handler = ContentHandler::getForTitle( $this->getTitle() );
$handler->getAutoDeleteReason( $this->getTitle(), $hasHistory );
+ global $wgContLang;
+
+ // Get the last revision
+ $rev = $this->getRevision();
+
+ if ( is_null( $rev ) ) {
+ return false;
+ }
+
+ // Get the article's contents
+ $contents = $rev->getText();
+ $blank = false;
+
+ // If the page is blank, use the text from the previous revision,
+ // which can only be blank if there's a move/import/protect dummy revision involved
+ if ( $contents == '' ) {
+ $prev = $rev->getPrevious();
+
+ if ( $prev ) {
+ $contents = $prev->getText();
+ $blank = true;
+ }
+ }
+
+ $dbw = wfGetDB( DB_MASTER );
+
+ // Find out if there was only one contributor
+ // Only scan the last 20 revisions
+ $res = $dbw->select( 'revision', 'rev_user_text',
+ array( 'rev_page' => $this->getID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ),
+ __METHOD__,
+ array( 'LIMIT' => 20 )
+ );
+
+ if ( $res === false ) {
+ // This page has no revisions, which is very weird
+ return false;
+ }
+
+ $hasHistory = ( $res->numRows() > 1 );
+ $row = $dbw->fetchObject( $res );
+
+ if ( $row ) { // $row is false if the only contributor is hidden
+ $onlyAuthor = $row->rev_user_text;
+ // Try to find a second contributor
+ foreach ( $res as $row ) {
+ if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999
+ $onlyAuthor = false;
+ break;
+ }
+ }
+ } else {
+ $onlyAuthor = false;
+ }
+
+ // Generate the summary with a '$1' placeholder
+ if ( $blank ) {
+ // The current revision is blank and the one before is also
+ // blank. It's just not our lucky day
+ $reason = wfMsgForContent( 'exbeforeblank', '$1' );
+ } else {
+ if ( $onlyAuthor ) {
+ $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
+ } else {
+ $reason = wfMsgForContent( 'excontent', '$1' );
+ }
+ }
+
+ if ( $reason == '-' ) {
+ // Allow these UI messages to be blanked out cleanly
+ return '';
+ }
+
+ // Replace newlines with spaces to prevent uglyness
+ $contents = preg_replace( "/[\n\r]/", ' ', $contents );
+ // Calculate the maximum amount of chars to get
+ // Max content length = max comment length - length of the comment (excl. $1)
+ $maxLength = 255 - ( strlen( $reason ) - 2 );
+ $contents = $wgContLang->truncate( $contents, $maxLength );
+ // Remove possible unfinished links
+ $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
+ // Now replace the '$1' placeholder
+ $reason = str_replace( '$1', $contents, $reason );
+
+ return $reason;
}
/**
/**
* @deprecated since 1.18
+ * @return bool
*/
public function useParserCache( $oldid ) {
wfDeprecated( __METHOD__, '1.18' );
private $text;
/**
- * @var ParserOutput|false
+ * @var ParserOutput|bool
*/
private $parserOutput = false;
private $isDirty = false;
/**
- * @var Status|false
+ * @var Status|bool
*/
private $error = false;
/**
* Get a Status object in case of error or false otherwise
*
- * @return Status|false
+ * @return Status|bool
*/
public function getError() {
return $this->error;
$time = - wfTime();
$this->parserOutput = $content->getParserOutput( $this->page->getTitle(), $this->revid, $this->parserOptions );
$time += wfTime();
+ $time = - microtime( true );
+ $this->parserOutput = $wgParser->parse( $text, $this->page->getTitle(),
+ $this->parserOptions, true, true, $this->revid );
+ $time += microtime( true );
# Timing hack
if ( $time > 3 ) {
/**
* @param $status Status
+ * @return bool
*/
function error( $status ) {
$this->error = $status;