$from = self::convertSelectType( $from );
$db = wfGetDB( $from === self::READ_LATEST ? DB_MASTER : DB_SLAVE );
- $row = $db->selectRow( 'page', self::selectFields(), array( 'page_id' => $id ), __METHOD__ );
+ $row = $db->selectRow(
+ 'page', self::selectFields(), array( 'page_id' => $id ), __METHOD__ );
if ( !$row ) {
return null;
}
* Load the object from a database row
*
* @since 1.20
- * @param object $data Database row containing at least fields returned by selectFields()
+ * @param object|bool $data DB row containing fields returned by selectFields() or false
* @param string|int $from One of the following:
* - "fromdb" or WikiPage::READ_NORMAL if the data comes from a slave DB
* - "fromdbmaster" or WikiPage::READ_LATEST if the data comes from the master DB
// SELECT. Thus we need S1 to also gets the revision row FOR UPDATE; otherwise, it
// may not find it since a page row UPDATE and revision row INSERT by S2 may have
// happened after the first S1 SELECT.
- // http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html#isolevel_repeatable-read.
+ // http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html#isolevel_repeatable-read
$flags = Revision::READ_LOCKING;
} elseif ( $this->mDataLoadedFrom == self::READ_LATEST ) {
// Bug T93976: if page_latest was loaded from the master, fetch the
$conds[] = "rev_user_text != {$dbr->addQuotes( $this->getUserText() )}";
}
- $conds[] = "{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0"; // username hidden?
+ // Username hidden?
+ $conds[] = "{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0";
$jconds = array(
'user' => array( 'LEFT JOIN', 'rev_user = user_id' ),
public function getParserOutput( ParserOptions $parserOptions, $oldid = null ) {
$useParserCache = $this->shouldCheckParserCache( $parserOptions, $oldid );
- wfDebug( __METHOD__ . ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
+ wfDebug( __METHOD__ .
+ ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
if ( $parserOptions->getStubThreshold() ) {
wfIncrStats( 'pcache.miss.stub' );
}
/**
* Do standard deferred updates after page view (existing or missing page)
* @param User $user The relevant user
- * @param int $oldid The revision id being viewed. If not given or 0, latest revision is assumed.
+ * @param int $oldid Revision id being viewed; if not given or 0, latest revision is assumed
*/
public function doViewUpdates( User $user, $oldid = 0 ) {
if ( wfReadOnly() ) {
return true;
}
-
/**
* Insert a new empty page record for this article.
* This *must* be followed up by creating a revision
* @return int|bool The newly created page_id key; false if the title already existed
*/
public function insertOn( $dbw ) {
- $page_id = $dbw->nextSequenceValue( 'page_page_id_seq' );
- $dbw->insert( 'page', array(
- 'page_id' => $page_id,
- 'page_namespace' => $this->mTitle->getNamespace(),
- 'page_title' => $this->mTitle->getDBkey(),
- 'page_restrictions' => '',
- 'page_is_redirect' => 0, // Will set this shortly...
- 'page_is_new' => 1,
- 'page_random' => wfRandom(),
- 'page_touched' => $dbw->timestamp(),
- 'page_latest' => 0, // Fill this in shortly...
- 'page_len' => 0, // Fill this in shortly...
- ), __METHOD__, 'IGNORE' );
-
- $affected = $dbw->affectedRows();
-
- if ( $affected ) {
+ $dbw->insert(
+ 'page',
+ array(
+ 'page_id' => $dbw->nextSequenceValue( 'page_page_id_seq' ),
+ 'page_namespace' => $this->mTitle->getNamespace(),
+ 'page_title' => $this->mTitle->getDBkey(),
+ 'page_restrictions' => '',
+ 'page_is_redirect' => 0, // Will set this shortly...
+ 'page_is_new' => 1,
+ 'page_random' => wfRandom(),
+ 'page_touched' => $dbw->timestamp(),
+ 'page_latest' => 0, // Fill this in shortly...
+ 'page_len' => 0, // Fill this in shortly...
+ ),
+ __METHOD__,
+ 'IGNORE'
+ );
+
+ if ( $dbw->affectedRows() > 0 ) {
$newid = $dbw->insertId();
$this->mId = $newid;
$this->mTitle->resetArticleID( $newid );
return $newid;
} else {
- return false;
+ return false; // nothing changed
}
}
$this->mLatest = $revision->getId();
$this->mIsRedirect = (bool)$rt;
// Update the LinkCache.
- LinkCache::singleton()->addGoodLinkObj( $this->getId(), $this->mTitle, $len, $this->mIsRedirect,
- $this->mLatest, $revision->getContentModel() );
+ LinkCache::singleton()->addGoodLinkObj(
+ $this->getId(),
+ $this->mTitle,
+ $len,
+ $this->mIsRedirect,
+ $this->mLatest,
+ $revision->getContentModel()
+ );
}
return $result;
* @since 1.21
* @deprecated since 1.24, use replaceSectionAtRev instead
*/
- public function replaceSectionContent( $sectionId, Content $sectionContent, $sectionTitle = '',
- $edittime = null ) {
+ public function replaceSectionContent(
+ $sectionId, Content $sectionContent, $sectionTitle = '', $edittime = null
+ ) {
$baseRevId = null;
if ( $edittime && $sectionId !== 'new' ) {
* Do not log the change in recentchanges
* EDIT_FORCE_BOT
* Mark the edit a "bot" edit regardless of user rights
- * EDIT_DEFER_UPDATES
- * Defer some of the updates until the end of index.php
* EDIT_AUTOSUMMARY
* Fill in blank summaries with generated text where possible
*
* Do not log the change in recentchanges
* EDIT_FORCE_BOT
* Mark the edit a "bot" edit regardless of user rights
- * EDIT_DEFER_UPDATES
- * Defer some of the updates until the end of index.php
* EDIT_AUTOSUMMARY
* Fill in blank summaries with generated text where possible
*
return $status;
}
- Hooks::run( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
+ Hooks::run( 'NewRevisionFromEditComplete',
+ array( $this, $revision, $baseRevId, $user ) );
// Update recentchanges
if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
Hooks::run( 'PageContentInsertComplete', $hook_args );
}
- // Do updates right now unless deferral was requested
- if ( !( $flags & EDIT_DEFER_UPDATES ) ) {
- DeferredUpdates::doUpdates();
- }
-
// Return the new revision (or null) to the caller
$status->value['revision'] = $revision;
* @since 1.21
*/
public function prepareContentForEdit(
- Content $content, $revision = null, User $user = null, $serialFormat = null, $useCache = true
+ Content $content, $revision = null, User $user = null,
+ $serialFormat = null, $useCache = true
) {
global $wgContLang, $wgUser, $wgAjaxEditStash;
// itself (such as via self-transclusion). In this case, we need to make sure
// that any such self-references refer to the newly-saved revision, and not
// to the previous one, which could otherwise happen due to slave lag.
- $oldCallback = $edit->popts->setCurrentRevisionCallback(
- function ( $title, $parser = false ) use ( $revision, &$oldCallback ) {
+ $oldCallback = $edit->popts->getCurrentRevisionCallback();
+ $edit->popts->setCurrentRevisionCallback(
+ function ( Title $title, $parser = false ) use ( $revision, &$oldCallback ) {
if ( $title->equals( $revision->getTitle() ) ) {
return $revision;
} else {
- return call_user_func(
- $oldCallback,
- $title,
- $parser
- );
+ return call_user_func( $oldCallback, $title, $parser );
}
}
);
$edit->oldContent = $this->getContent( Revision::RAW );
// NOTE: B/C for hooks! don't use these fields!
- $edit->newText = $edit->newContent ? ContentHandler::getContentText( $edit->newContent ) : '';
- $edit->oldText = $edit->oldContent ? ContentHandler::getContentText( $edit->oldContent ) : '';
+ $edit->newText = $edit->newContent
+ ? ContentHandler::getContentText( $edit->newContent )
+ : '';
+ $edit->oldText = $edit->oldContent
+ ? ContentHandler::getContentText( $edit->oldContent )
+ : '';
$edit->pst = $edit->pstContent ? $edit->pstContent->serialize( $serialFormat ) : '';
$this->mPreparedEdit = $edit;
if ( !$recipient ) {
wfDebug( __METHOD__ . ": invalid username\n" );
} else {
- // Allow extensions to prevent user notification when a new message is added to their talk page
+ // Allow extensions to prevent user notification
+ // when a new message is added to their talk page
if ( Hooks::run( 'ArticleEditUpdateNewTalk', array( &$this, $recipient ) ) ) {
if ( User::isIP( $shortTitle ) ) {
// An anonymous user
* @param bool $minor Whereas it's a minor modification
* @param string $serialFormat Format for storing the content in the database
*/
- public function doQuickEditContent( Content $content, User $user, $comment = '', $minor = false,
- $serialFormat = null
+ public function doQuickEditContent(
+ Content $content, User $user, $comment = '', $minor = false, $serialFormat = null
) {
$serialized = $content->serialize( $serialFormat );
__METHOD__
);
- Hooks::run( 'NewRevisionFromEditComplete', array( $this, $nullRevision, $latest, $user ) );
+ Hooks::run( 'NewRevisionFromEditComplete',
+ array( $this, $nullRevision, $latest, $user ) );
Hooks::run( 'ArticleProtectComplete', array( &$this, &$user, $limit, $reason ) );
} else { // Protection of non-existing page (also known as "title protection")
// Cascade protection is meaningless in this case
# with '' filtered out. All possible message keys are listed below:
# * protect-level-autoconfirmed
# * protect-level-sysop
- $restrictionsText = wfMessage( 'protect-level-' . $restrictions )->inContentLanguage()->text();
+ $restrictionsText = wfMessage( 'protect-level-' . $restrictions )
+ ->inContentLanguage()->text();
$expiryText = $this->formatExpiry( $expiry[$action] );
foreach ( array_filter( $limit ) as $action => $restrictions ) {
$expiryText = $this->formatExpiry( $expiry[$action] );
- $protectDescriptionLog .= $wgContLang->getDirMark() . "[$action=$restrictions] ($expiryText)";
+ $protectDescriptionLog .= $wgContLang->getDirMark() .
+ "[$action=$restrictions] ($expiryText)";
}
return trim( $protectDescriptionLog );
*/
protected static function flattenRestrictions( $limit ) {
if ( !is_array( $limit ) ) {
- throw new MWException( 'WikiPage::flattenRestrictions given non-array restriction set' );
+ throw new MWException( __METHOD__ . ' given non-array restriction set' );
}
$bits = array();
$status = Status::newGood();
if ( $this->mTitle->getDBkey() === '' ) {
- $status->error( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
+ $status->error( 'cannotdelete',
+ wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
return $status;
}
$user = is_null( $user ) ? $wgUser : $user;
- if ( !Hooks::run( 'ArticleDelete', array( &$this, &$user, &$reason, &$error, &$status ) ) ) {
+ if ( !Hooks::run( 'ArticleDelete',
+ array( &$this, &$user, &$reason, &$error, &$status )
+ ) ) {
if ( $status->isOK() ) {
// Hook aborted but didn't set a fatal status
$status->fatal( 'delete-hook-aborted' );
if ( $id == 0 || $this->getLatest() != $latest ) {
// Page not there or trx snapshot is stale
$dbw->rollback( __METHOD__ );
- $status->error( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
+ $status->error( 'cannotdelete',
+ wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
return $status;
}
}
if ( !$ok ) {
$dbw->rollback( __METHOD__ );
- $status->error( 'cannotdelete', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
+ $status->error( 'cannotdelete',
+ wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) );
return $status;
}
$this->doDeleteUpdates( $id, $content );
- Hooks::run( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id, $content, $logEntry ) );
+ Hooks::run( 'ArticleDeleteComplete',
+ array( &$this, &$user, $reason, $id, $content, $logEntry ) );
$status->value = $logid;
return $status;
}
// Delete pagelinks, update secondary indexes, etc
$updates = $this->getDeletionUpdates( $content );
- // Make sure an enqueued jobs run after commit so they see the deletion
- wfGetDB( DB_MASTER )->onTransactionIdle( function() use ( $updates ) {
- DataUpdate::runUpdates( $updates, 'enqueue' );
- } );
+ foreach ( $updates as $update ) {
+ DeferredUpdates::addUpdate( $update );
+ }
// Reparse any pages transcluding this page
LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' );
}
// raise error, when the edit is an edit without a new version
- if ( empty( $status->value['revision'] ) ) {
+ $statusRev = isset( $status->value['revision'] )
+ ? $status->value['revision']
+ : null;
+ if ( !( $statusRev instanceof Revision ) ) {
$resultDetails = array( 'current' => $current );
return array( array( 'alreadyrolled',
htmlspecialchars( $this->mTitle->getPrefixedText() ),
) );
}
- $revId = $status->value['revision']->getId();
+ $revId = $statusRev->getId();
Hooks::run( 'ArticleRollbackComplete', array( $this, $guser, $target, $current ) );
return;
}
- if ( !Hooks::run( 'OpportunisticLinksUpdate', array( $this, $this->mTitle, $parserOutput ) ) ) {
+ if ( !Hooks::run( 'OpportunisticLinksUpdate',
+ array( $this, $this->mTitle, $parserOutput )
+ ) ) {
return;
}
*/
public function getDeletionUpdates( Content $content = null ) {
if ( !$content ) {
- // load content object, which may be used to determine the necessary updates
- // XXX: the content may not be needed to determine the updates, then this would be overhead.
+ // load content object, which may be used to determine the necessary updates.
+ // XXX: the content may not be needed to determine the updates.
$content = $this->getContent( Revision::RAW );
}