summaryrefslogtreecommitdiff
path: root/includes/page/WikiPage.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/page/WikiPage.php')
-rw-r--r--includes/page/WikiPage.php476
1 files changed, 214 insertions, 262 deletions
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 9ade16e5..7c789249 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -31,8 +31,6 @@ interface Page {
*
* Some fields are public only for backwards-compatibility. Use accessors.
* In the past, this class was part of Article.php and everything was public.
- *
- * @internal documentation reviewed 15 Mar 2010
*/
class WikiPage implements Page, IDBAccessObject {
// Constants for $mDataLoadedFrom and related
@@ -50,7 +48,7 @@ class WikiPage implements Page, IDBAccessObject {
public $mLatest = false; // !< Integer (false means "not loaded")
/**@}}*/
- /** @var stdclass Map of cache fields (text, parser output, ect) for a proposed/new edit */
+ /** @var stdClass Map of cache fields (text, parser output, ect) for a proposed/new edit */
public $mPreparedEdit = false;
/**
@@ -89,11 +87,6 @@ class WikiPage implements Page, IDBAccessObject {
protected $mLinksUpdated = '19700101000000';
/**
- * @var int|null
- */
- protected $mCounter = null;
-
- /**
* Constructor and clear the article
* @param Title $title Reference to a Title object.
*/
@@ -247,7 +240,6 @@ class WikiPage implements Page, IDBAccessObject {
*/
protected function clearCacheFields() {
$this->mId = null;
- $this->mCounter = null;
$this->mRedirectTarget = null; // Title object if set
$this->mLastRevision = null; // Latest revision
$this->mTouched = '19700101000000';
@@ -284,7 +276,6 @@ class WikiPage implements Page, IDBAccessObject {
'page_namespace',
'page_title',
'page_restrictions',
- 'page_counter',
'page_is_redirect',
'page_is_new',
'page_random',
@@ -315,11 +306,11 @@ class WikiPage implements Page, IDBAccessObject {
protected function pageData( $dbr, $conditions, $options = array() ) {
$fields = self::selectFields();
- wfRunHooks( 'ArticlePageDataBefore', array( &$this, &$fields ) );
+ Hooks::run( 'ArticlePageDataBefore', array( &$this, &$fields ) );
$row = $dbr->selectRow( 'page', $fields, $conditions, __METHOD__, $options );
- wfRunHooks( 'ArticlePageDataAfter', array( &$this, &$row ) );
+ Hooks::run( 'ArticlePageDataAfter', array( &$this, &$row ) );
return $row;
}
@@ -352,8 +343,7 @@ class WikiPage implements Page, IDBAccessObject {
}
/**
- * Set the general counter, title etc data loaded from
- * some source.
+ * Load the object from a given source by title
*
* @param object|string|int $from One of the following:
* - A DB query result object.
@@ -377,14 +367,12 @@ class WikiPage implements Page, IDBAccessObject {
$data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle );
} elseif ( $from === self::READ_NORMAL ) {
$data = $this->pageDataFromTitle( wfGetDB( DB_SLAVE ), $this->mTitle );
- // Use a "last rev inserted" timestamp key to diminish the issue of slave lag.
- // Note that DB also stores the master position in the session and checks it.
- $touched = $this->getCachedLastEditTime();
- if ( $touched ) { // key set
- if ( !$data || $touched > wfTimestamp( TS_MW, $data->page_touched ) ) {
- $from = self::READ_LATEST;
- $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle );
- }
+ if ( !$data
+ && wfGetLB()->getServerCount() > 1
+ && wfGetLB()->hasOrMadeRecentMasterChanges()
+ ) {
+ $from = self::READ_LATEST;
+ $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle );
}
} else {
// No idea from where the caller got this data, assume slave database.
@@ -403,7 +391,7 @@ class WikiPage implements Page, IDBAccessObject {
* @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
- * - "forupdate" or WikiPage::READ_LOCKING if the data comes from from
+ * - "forupdate" or WikiPage::READ_LOCKING if the data comes from
* the master DB using SELECT FOR UPDATE
*/
public function loadFromRow( $data, $from ) {
@@ -419,7 +407,6 @@ class WikiPage implements Page, IDBAccessObject {
$this->mTitle->loadRestrictions( $data->page_restrictions );
$this->mId = intval( $data->page_id );
- $this->mCounter = intval( $data->page_counter );
$this->mTouched = wfTimestamp( TS_MW, $data->page_touched );
$this->mLinksUpdated = wfTimestampOrNull( TS_MW, $data->page_links_updated );
$this->mIsRedirect = intval( $data->page_is_redirect );
@@ -477,17 +464,6 @@ class WikiPage implements Page, IDBAccessObject {
}
/**
- * @return int The view count for the page
- */
- public function getCount() {
- if ( !$this->mDataLoaded ) {
- $this->loadPageData();
- }
-
- return $this->mCounter;
- }
-
- /**
* Tests if the article content represents a redirect
*
* @return bool
@@ -577,7 +553,6 @@ class WikiPage implements Page, IDBAccessObject {
* @return Revision|null
*/
public function getOldestRevision() {
- wfProfileIn( __METHOD__ );
// Try using the slave database first, then try the master
$continue = 2;
@@ -608,7 +583,6 @@ class WikiPage implements Page, IDBAccessObject {
}
}
- wfProfileOut( __METHOD__ );
return $row ? Revision::newFromRow( $row ) : null;
}
@@ -626,13 +600,23 @@ class WikiPage implements Page, IDBAccessObject {
return; // page doesn't exist or is missing page_latest info
}
- // Bug 37225: if session S1 loads the page row FOR UPDATE, the result always includes the
- // latest changes committed. This is true even within REPEATABLE-READ transactions, where
- // S1 normally only sees changes committed before the first S1 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.
- $flags = ( $this->mDataLoadedFrom == self::READ_LOCKING ) ? Revision::READ_LOCKING : 0;
+ if ( $this->mDataLoadedFrom == self::READ_LOCKING ) {
+ // Bug 37225: if session S1 loads the page row FOR UPDATE, the result always
+ // includes the latest changes committed. This is true even within REPEATABLE-READ
+ // transactions, where S1 normally only sees changes committed before the first S1
+ // 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.
+ $flags = Revision::READ_LOCKING;
+ } elseif ( $this->mDataLoadedFrom == self::READ_LATEST ) {
+ // Bug T93976: if page_latest was loaded from the master, fetch the
+ // revision from there as well, as it may not exist yet on a slave DB.
+ // Also, this keeps the queries in the same REPEATABLE-READ snapshot.
+ $flags = Revision::READ_LATEST;
+ } else {
+ $flags = 0;
+ }
$revision = Revision::newFromPageId( $this->getId(), $latest, $flags );
if ( $revision ) { // sanity
$this->setLastEdit( $revision );
@@ -825,29 +809,6 @@ class WikiPage implements Page, IDBAccessObject {
}
/**
- * Get the cached timestamp for the last time the page changed.
- * This is only used to help handle slave lag by comparing to page_touched.
- * @return string MW timestamp
- */
- protected function getCachedLastEditTime() {
- global $wgMemc;
- $key = wfMemcKey( 'page-lastedit', md5( $this->mTitle->getPrefixedDBkey() ) );
- return $wgMemc->get( $key );
- }
-
- /**
- * Set the cached timestamp for the last time the page changed.
- * This is only used to help handle slave lag by comparing to page_touched.
- * @param string $timestamp
- * @return void
- */
- public function setCachedLastEditTime( $timestamp ) {
- global $wgMemc;
- $key = wfMemcKey( 'page-lastedit', md5( $this->mTitle->getPrefixedDBkey() ) );
- $wgMemc->set( $key, wfTimestamp( TS_MW, $timestamp ), 60 * 15 );
- }
-
- /**
* Determine whether a page would be suitable for being counted as an
* article in the site_stats table based on the title & its content
*
@@ -995,7 +956,7 @@ class WikiPage implements Page, IDBAccessObject {
$source = $this->mTitle->getFullURL( 'redirect=no' );
return $rt->getFullURL( array( 'rdfrom' => $source ) );
} else {
- // External pages pages without "local" bit set are not valid
+ // External pages without "local" bit set are not valid
// redirect targets
return false;
}
@@ -1075,7 +1036,6 @@ class WikiPage implements Page, IDBAccessObject {
* @return array Array of authors, duplicates not removed
*/
public function getLastNAuthors( $num, $revLatest = 0 ) {
- wfProfileIn( __METHOD__ );
// First try the slave
// If that doesn't have the latest revision, try the master
$continue = 2;
@@ -1096,7 +1056,6 @@ class WikiPage implements Page, IDBAccessObject {
);
if ( !$res ) {
- wfProfileOut( __METHOD__ );
return array();
}
@@ -1116,7 +1075,6 @@ class WikiPage implements Page, IDBAccessObject {
$authors[] = $row->rev_user_text;
}
- wfProfileOut( __METHOD__ );
return $authors;
}
@@ -1149,7 +1107,6 @@ class WikiPage implements Page, IDBAccessObject {
* @return ParserOutput|bool ParserOutput or false if the revision was not found
*/
public function getParserOutput( ParserOptions $parserOptions, $oldid = null ) {
- wfProfileIn( __METHOD__ );
$useParserCache = $this->isParserCacheUsed( $parserOptions, $oldid );
wfDebug( __METHOD__ . ': using parser cache: ' . ( $useParserCache ? 'yes' : 'no' ) . "\n" );
@@ -1160,7 +1117,6 @@ class WikiPage implements Page, IDBAccessObject {
if ( $useParserCache ) {
$parserOutput = ParserCache::singleton()->get( $this, $parserOptions );
if ( $parserOutput !== false ) {
- wfProfileOut( __METHOD__ );
return $parserOutput;
}
}
@@ -1172,8 +1128,6 @@ class WikiPage implements Page, IDBAccessObject {
$pool = new PoolWorkArticleView( $this, $parserOptions, $oldid, $useParserCache );
$pool->execute();
- wfProfileOut( __METHOD__ );
-
return $pool->getParserOutput();
}
@@ -1183,17 +1137,11 @@ class WikiPage implements Page, IDBAccessObject {
* @param int $oldid The revision id being viewed. If not given or 0, latest revision is assumed.
*/
public function doViewUpdates( User $user, $oldid = 0 ) {
- global $wgDisableCounters;
if ( wfReadOnly() ) {
return;
}
- // Don't update page view counters on views from bot users (bug 14044)
- if ( !$wgDisableCounters && !$user->isAllowed( 'bot' ) && $this->exists() ) {
- DeferredUpdates::addUpdate( new ViewCountUpdate( $this->getId() ) );
- DeferredUpdates::addUpdate( new SiteStatsUpdate( 1, 0, 0 ) );
- }
-
+ Hooks::run( 'PageViewUpdates', array( $this, $user ) );
// Update newtalk / watchlist notification status
$user->clearNotification( $this->mTitle, $oldid );
}
@@ -1205,7 +1153,7 @@ class WikiPage implements Page, IDBAccessObject {
public function doPurge() {
global $wgUseSquid;
- if ( !wfRunHooks( 'ArticlePurge', array( &$this ) ) ) {
+ if ( !Hooks::run( 'ArticlePurge', array( &$this ) ) ) {
return false;
}
@@ -1255,14 +1203,12 @@ class WikiPage implements Page, IDBAccessObject {
* @return int The newly created page_id key, or false if the title already existed
*/
public function insertOn( $dbw ) {
- wfProfileIn( __METHOD__ );
$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_counter' => 0,
'page_restrictions' => '',
'page_is_redirect' => 0, // Will set this shortly...
'page_is_new' => 1,
@@ -1279,7 +1225,6 @@ class WikiPage implements Page, IDBAccessObject {
$this->mId = $newid;
$this->mTitle->resetArticleID( $newid );
}
- wfProfileOut( __METHOD__ );
return $affected ? $newid : false;
}
@@ -1302,7 +1247,12 @@ class WikiPage implements Page, IDBAccessObject {
) {
global $wgContentHandlerUseDB;
- wfProfileIn( __METHOD__ );
+ // Assertion to try to catch T92046
+ if ( (int)$revision->getId() === 0 ) {
+ throw new InvalidArgumentException(
+ __METHOD__ . ': Revision has ID ' . var_export( $revision->getId(), 1 )
+ );
+ }
$content = $revision->getContent();
$len = $content ? $content->getSize() : 0;
@@ -1337,7 +1287,6 @@ class WikiPage implements Page, IDBAccessObject {
if ( $result ) {
$this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect );
$this->setLastEdit( $revision );
- $this->setCachedLastEditTime( $now );
$this->mLatest = $revision->getId();
$this->mIsRedirect = (bool)$rt;
// Update the LinkCache.
@@ -1345,7 +1294,6 @@ class WikiPage implements Page, IDBAccessObject {
$this->mLatest, $revision->getContentModel() );
}
- wfProfileOut( __METHOD__ );
return $result;
}
@@ -1370,7 +1318,6 @@ class WikiPage implements Page, IDBAccessObject {
return true;
}
- wfProfileIn( __METHOD__ );
if ( $isRedirect ) {
$this->insertRedirectEntry( $redirectTitle );
} else {
@@ -1382,7 +1329,6 @@ class WikiPage implements Page, IDBAccessObject {
if ( $this->getTitle()->getNamespace() == NS_FILE ) {
RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $this->getTitle() );
}
- wfProfileOut( __METHOD__ );
return ( $dbw->affectedRows() != 0 );
}
@@ -1398,7 +1344,6 @@ class WikiPage implements Page, IDBAccessObject {
* @return bool
*/
public function updateIfNewerOn( $dbw, $revision ) {
- wfProfileIn( __METHOD__ );
$row = $dbw->selectRow(
array( 'revision', 'page' ),
@@ -1410,7 +1355,6 @@ class WikiPage implements Page, IDBAccessObject {
if ( $row ) {
if ( wfTimestamp( TS_MW, $row->rev_timestamp ) >= $revision->getTimestamp() ) {
- wfProfileOut( __METHOD__ );
return false;
}
$prev = $row->rev_id;
@@ -1423,7 +1367,6 @@ class WikiPage implements Page, IDBAccessObject {
$ret = $this->updateRevisionOn( $dbw, $revision, $prev, $lastRevIsRedirect );
- wfProfileOut( __METHOD__ );
return $ret;
}
@@ -1542,18 +1485,26 @@ class WikiPage implements Page, IDBAccessObject {
*/
public function replaceSectionContent( $sectionId, Content $sectionContent, $sectionTitle = '',
$edittime = null ) {
- wfProfileIn( __METHOD__ );
$baseRevId = null;
if ( $edittime && $sectionId !== 'new' ) {
- $dbw = wfGetDB( DB_MASTER );
- $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
+ $dbr = wfGetDB( DB_SLAVE );
+ $rev = Revision::loadFromTimestamp( $dbr, $this->mTitle, $edittime );
+ // Try the master if this thread may have just added it.
+ // This could be abstracted into a Revision method, but we don't want
+ // to encourage loading of revisions by timestamp.
+ if ( !$rev
+ && wfGetLB()->getServerCount() > 1
+ && wfGetLB()->hasOrMadeRecentMasterChanges()
+ ) {
+ $dbw = wfGetDB( DB_MASTER );
+ $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
+ }
if ( $rev ) {
$baseRevId = $rev->getId();
}
}
- wfProfileOut( __METHOD__ );
return $this->replaceSectionAtRev( $sectionId, $sectionContent, $sectionTitle, $baseRevId );
}
@@ -1573,14 +1524,12 @@ class WikiPage implements Page, IDBAccessObject {
public function replaceSectionAtRev( $sectionId, Content $sectionContent,
$sectionTitle = '', $baseRevId = null
) {
- wfProfileIn( __METHOD__ );
if ( strval( $sectionId ) === '' ) {
// Whole-page edit; let the whole text through
$newContent = $sectionContent;
} else {
if ( !$this->supportsSections() ) {
- wfProfileOut( __METHOD__ );
throw new MWException( "sections not supported for content model " .
$this->getContentHandler()->getModelID() );
}
@@ -1589,14 +1538,10 @@ class WikiPage implements Page, IDBAccessObject {
if ( is_null( $baseRevId ) || $sectionId === 'new' ) {
$oldContent = $this->getContent();
} else {
- // TODO: try DB_SLAVE first
- $dbw = wfGetDB( DB_MASTER );
- $rev = Revision::loadFromId( $dbw, $baseRevId );
-
+ $rev = Revision::newFromId( $baseRevId );
if ( !$rev ) {
wfDebug( __METHOD__ . " asked for bogus section (page: " .
$this->getId() . "; section: $sectionId)\n" );
- wfProfileOut( __METHOD__ );
return null;
}
@@ -1605,14 +1550,12 @@ class WikiPage implements Page, IDBAccessObject {
if ( !$oldContent ) {
wfDebug( __METHOD__ . ": no page text\n" );
- wfProfileOut( __METHOD__ );
return null;
}
$newContent = $oldContent->replaceSection( $sectionId, $sectionContent, $sectionTitle );
}
- wfProfileOut( __METHOD__ );
return $newContent;
}
@@ -1662,7 +1605,9 @@ class WikiPage implements Page, IDBAccessObject {
* error will be returned. These two conditions are also possible with
* auto-detection due to MediaWiki's performance-optimised locking strategy.
*
- * @param bool|int $baseRevId The revision ID this edit was based off, if any
+ * @param bool|int $baseRevId The revision ID this edit was based off, if any.
+ * This is not the parent revision ID, rather the revision ID for older
+ * content used as the source for a rollback, for example.
* @param User $user The user doing the edit
*
* @throws MWException
@@ -1722,9 +1667,11 @@ class WikiPage implements Page, IDBAccessObject {
* error will be returned. These two conditions are also possible with
* auto-detection due to MediaWiki's performance-optimised locking strategy.
*
- * @param bool|int $baseRevId The revision ID this edit was based off, if any
+ * @param bool|int $baseRevId The revision ID this edit was based off, if any.
+ * This is not the parent revision ID, rather the revision ID for older
+ * content used as the source for a rollback, for example.
* @param User $user The user doing the edit
- * @param string $serialisation_format Format for storing the content in the
+ * @param string $serialFormat Format for storing the content in the
* database.
*
* @throws MWException
@@ -1745,7 +1692,7 @@ class WikiPage implements Page, IDBAccessObject {
* @since 1.21
*/
public function doEditContent( Content $content, $summary, $flags = 0, $baseRevId = false,
- User $user = null, $serialisation_format = null
+ User $user = null, $serialFormat = null
) {
global $wgUser, $wgUseAutomaticEditSummaries, $wgUseRCPatrol, $wgUseNPPatrol;
@@ -1754,10 +1701,7 @@ class WikiPage implements Page, IDBAccessObject {
throw new MWException( 'Something is trying to edit an article with an empty title' );
}
- wfProfileIn( __METHOD__ );
-
if ( !$content->getContentHandler()->canBeUsedOn( $this->getTitle() ) ) {
- wfProfileOut( __METHOD__ );
return Status::newFatal( 'content-not-allowed-here',
ContentHandler::getLocalizedName( $content->getModel() ),
$this->getTitle()->getPrefixedText() );
@@ -1777,7 +1721,7 @@ class WikiPage implements Page, IDBAccessObject {
$hook_args = array( &$this, &$user, &$content, &$summary,
$flags & EDIT_MINOR, null, null, &$flags, &$status );
- if ( !wfRunHooks( 'PageContentSave', $hook_args )
+ if ( !Hooks::run( 'PageContentSave', $hook_args )
|| !ContentHandler::runLegacyHooks( 'ArticleSave', $hook_args ) ) {
wfDebug( __METHOD__ . ": ArticleSave or ArticleSaveContent hook aborted save!\n" );
@@ -1786,7 +1730,6 @@ class WikiPage implements Page, IDBAccessObject {
$status->fatal( 'edit-hook-aborted' );
}
- wfProfileOut( __METHOD__ );
return $status;
}
@@ -1811,7 +1754,7 @@ class WikiPage implements Page, IDBAccessObject {
$summary = $handler->getAutosummary( $old_content, $content, $flags );
}
- $editInfo = $this->prepareContentForEdit( $content, null, $user, $serialisation_format );
+ $editInfo = $this->prepareContentForEdit( $content, null, $user, $serialFormat );
$serialized = $editInfo->pst;
/**
@@ -1833,11 +1776,9 @@ class WikiPage implements Page, IDBAccessObject {
wfDebug( __METHOD__ . ": EDIT_UPDATE specified but article doesn't exist\n" );
$status->fatal( 'edit-gone-missing' );
- wfProfileOut( __METHOD__ );
return $status;
} elseif ( !$old_content ) {
// Sanity check for bug 37225
- wfProfileOut( __METHOD__ );
throw new MWException( "Could not find text for current revision {$oldid}." );
}
@@ -1853,27 +1794,21 @@ class WikiPage implements Page, IDBAccessObject {
'user_text' => $user->getName(),
'timestamp' => $now,
'content_model' => $content->getModel(),
- 'content_format' => $serialisation_format,
+ 'content_format' => $serialFormat,
) ); // XXX: pass content object?!
$changed = !$content->equals( $old_content );
if ( $changed ) {
- if ( !$content->isValid() ) {
- wfProfileOut( __METHOD__ );
- throw new MWException( "New content failed validity check!" );
- }
-
$dbw->begin( __METHOD__ );
try {
- $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
+ $prepStatus = $content->prepareSave( $this, $flags, $oldid, $user );
$status->merge( $prepStatus );
if ( !$status->isOK() ) {
$dbw->rollback( __METHOD__ );
- wfProfileOut( __METHOD__ );
return $status;
}
$revisionId = $revision->insertOn( $dbw );
@@ -1889,11 +1824,10 @@ class WikiPage implements Page, IDBAccessObject {
$dbw->rollback( __METHOD__ );
- wfProfileOut( __METHOD__ );
return $status;
}
- wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
+ Hooks::run( 'NewRevisionFromEditComplete', array( $this, $revision, $baseRevId, $user ) );
// Update recentchanges
if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
// Mark as patrolled if the user can do so
@@ -1911,7 +1845,7 @@ class WikiPage implements Page, IDBAccessObject {
}
}
$user->incEditCount();
- } catch ( MWException $e ) {
+ } catch ( Exception $e ) {
$dbw->rollback( __METHOD__ );
// Question: Would it perhaps be better if this method turned all
// exceptions into $status's?
@@ -1948,13 +1882,12 @@ class WikiPage implements Page, IDBAccessObject {
$dbw->begin( __METHOD__ );
try {
- $prepStatus = $content->prepareSave( $this, $flags, $baseRevId, $user );
+ $prepStatus = $content->prepareSave( $this, $flags, $oldid, $user );
$status->merge( $prepStatus );
if ( !$status->isOK() ) {
$dbw->rollback( __METHOD__ );
- wfProfileOut( __METHOD__ );
return $status;
}
@@ -1968,7 +1901,6 @@ class WikiPage implements Page, IDBAccessObject {
$dbw->rollback( __METHOD__ );
$status->fatal( 'edit-already-exists' );
- wfProfileOut( __METHOD__ );
return $status;
}
@@ -1984,7 +1916,7 @@ class WikiPage implements Page, IDBAccessObject {
'user_text' => $user->getName(),
'timestamp' => $now,
'content_model' => $content->getModel(),
- 'content_format' => $serialisation_format,
+ 'content_format' => $serialFormat,
) );
$revisionId = $revision->insertOn( $dbw );
@@ -1998,7 +1930,7 @@ class WikiPage implements Page, IDBAccessObject {
// Update the page record with revision data
$this->updateRevisionOn( $dbw, $revision, 0 );
- wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
+ Hooks::run( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
// Update recentchanges
if ( !( $flags & EDIT_SUPPRESS_RC ) ) {
@@ -2016,7 +1948,7 @@ class WikiPage implements Page, IDBAccessObject {
}
$user->incEditCount();
- } catch ( MWException $e ) {
+ } catch ( Exception $e ) {
$dbw->rollback( __METHOD__ );
throw $e;
}
@@ -2029,7 +1961,7 @@ class WikiPage implements Page, IDBAccessObject {
$flags & EDIT_MINOR, null, null, &$flags, $revision );
ContentHandler::runLegacyHooks( 'ArticleInsertComplete', $hook_args );
- wfRunHooks( 'PageContentInsertComplete', $hook_args );
+ Hooks::run( 'PageContentInsertComplete', $hook_args );
}
// Do updates right now unless deferral was requested
@@ -2044,14 +1976,14 @@ class WikiPage implements Page, IDBAccessObject {
$flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId );
ContentHandler::runLegacyHooks( 'ArticleSaveComplete', $hook_args );
- wfRunHooks( 'PageContentSaveComplete', $hook_args );
+ Hooks::run( 'PageContentSaveComplete', $hook_args );
// Promote user to any groups they meet the criteria for
$dbw->onTransactionIdle( function () use ( $user ) {
$user->addAutopromoteOnceGroups( 'onEdit' );
+ $user->addAutopromoteOnceGroups( 'onView' ); // b/c
} );
- wfProfileOut( __METHOD__ );
return $status;
}
@@ -2083,7 +2015,7 @@ class WikiPage implements Page, IDBAccessObject {
/**
* Prepare text which is about to be saved.
- * Returns a stdclass with source, pst and output members
+ * Returns a stdClass with source, pst and output members
*
* @deprecated since 1.21: use prepareContentForEdit instead.
* @return object
@@ -2096,54 +2028,109 @@ class WikiPage implements Page, IDBAccessObject {
/**
* Prepare content which is about to be saved.
- * Returns a stdclass with source, pst and output members
+ * Returns a stdClass with source, pst and output members
*
* @param Content $content
- * @param int|null $revid
+ * @param Revision|int|null $revision Revision object. For backwards compatibility, a
+ * revision ID is also accepted, but this is deprecated.
* @param User|null $user
- * @param string|null $serialization_format
+ * @param string|null $serialFormat
+ * @param bool $useCache Check shared prepared edit cache
*
- * @return bool|object
+ * @return object
*
* @since 1.21
*/
- public function prepareContentForEdit( Content $content, $revid = null, User $user = null,
- $serialization_format = null
+ public function prepareContentForEdit(
+ Content $content, $revision = null, User $user = null, $serialFormat = null, $useCache = true
) {
- global $wgContLang, $wgUser;
+ global $wgContLang, $wgUser, $wgAjaxEditStash;
+
+ if ( is_object( $revision ) ) {
+ $revid = $revision->getId();
+ } else {
+ $revid = $revision;
+ // This code path is deprecated, and nothing is known to
+ // use it, so performance here shouldn't be a worry.
+ if ( $revid !== null ) {
+ $revision = Revision::newFromId( $revid, Revision::READ_LATEST );
+ } else {
+ $revision = null;
+ }
+ }
+
$user = is_null( $user ) ? $wgUser : $user;
//XXX: check $user->getId() here???
- // Use a sane default for $serialization_format, see bug 57026
- if ( $serialization_format === null ) {
- $serialization_format = $content->getContentHandler()->getDefaultFormat();
+ // Use a sane default for $serialFormat, see bug 57026
+ if ( $serialFormat === null ) {
+ $serialFormat = $content->getContentHandler()->getDefaultFormat();
}
if ( $this->mPreparedEdit
&& $this->mPreparedEdit->newContent
&& $this->mPreparedEdit->newContent->equals( $content )
&& $this->mPreparedEdit->revid == $revid
- && $this->mPreparedEdit->format == $serialization_format
+ && $this->mPreparedEdit->format == $serialFormat
// XXX: also check $user here?
) {
// Already prepared
return $this->mPreparedEdit;
}
+ // The edit may have already been prepared via api.php?action=stashedit
+ $cachedEdit = $useCache && $wgAjaxEditStash
+ ? ApiStashEdit::checkCache( $this->getTitle(), $content, $user )
+ : false;
+
$popts = ParserOptions::newFromUserAndLang( $user, $wgContLang );
- wfRunHooks( 'ArticlePrepareTextForEdit', array( $this, $popts ) );
+ Hooks::run( 'ArticlePrepareTextForEdit', array( $this, $popts ) );
$edit = (object)array();
+ if ( $cachedEdit ) {
+ $edit->timestamp = $cachedEdit->timestamp;
+ } else {
+ $edit->timestamp = wfTimestampNow();
+ }
+ // @note: $cachedEdit is not used if the rev ID was referenced in the text
$edit->revid = $revid;
- $edit->timestamp = wfTimestampNow();
- $edit->pstContent = $content ? $content->preSaveTransform( $this->mTitle, $user, $popts ) : null;
+ if ( $cachedEdit ) {
+ $edit->pstContent = $cachedEdit->pstContent;
+ } else {
+ $edit->pstContent = $content
+ ? $content->preSaveTransform( $this->mTitle, $user, $popts )
+ : null;
+ }
- $edit->format = $serialization_format;
+ $edit->format = $serialFormat;
$edit->popts = $this->makeParserOptions( 'canonical' );
- $edit->output = $edit->pstContent
- ? $edit->pstContent->getParserOutput( $this->mTitle, $revid, $edit->popts )
- : null;
+ if ( $cachedEdit ) {
+ $edit->output = $cachedEdit->output;
+ } else {
+ if ( $revision ) {
+ // We get here if vary-revision is set. This means that this page references
+ // 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 ) {
+ if ( $title->equals( $revision->getTitle() ) ) {
+ return $revision;
+ } else {
+ return call_user_func(
+ $oldCallback,
+ $title,
+ $parser
+ );
+ }
+ }
+ );
+ }
+ $edit->output = $edit->pstContent
+ ? $edit->pstContent->getParserOutput( $this->mTitle, $revid, $edit->popts )
+ : null;
+ }
$edit->newContent = $content;
$edit->oldContent = $this->getContent( Revision::RAW );
@@ -2151,7 +2138,7 @@ class WikiPage implements Page, IDBAccessObject {
// 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->pst = $edit->pstContent ? $edit->pstContent->serialize( $serialization_format ) : '';
+ $edit->pst = $edit->pstContent ? $edit->pstContent->serialize( $serialFormat ) : '';
$this->mPreparedEdit = $edit;
return $edit;
@@ -2168,17 +2155,23 @@ class WikiPage implements Page, IDBAccessObject {
* @param array $options Array of options, following indexes are used:
* - changed: boolean, whether the revision changed the content (default true)
* - created: boolean, whether the revision created the page (default false)
- * - oldcountable: boolean or null (default null):
+ * - moved: boolean, whether the page was moved (default false)
+ * - oldcountable: boolean, null, or string 'no-change' (default null):
* - boolean: whether the page was counted as an article before that
* revision, only used in changed is true and created is false
- * - null: don't change the article count
+ * - null: if created is false, don't update the article count; if created
+ * is true, do update the article count
+ * - 'no-change': don't update the article count, ever
*/
public function doEditUpdates( Revision $revision, User $user, array $options = array() ) {
global $wgEnableParserCache;
- wfProfileIn( __METHOD__ );
-
- $options += array( 'changed' => true, 'created' => false, 'oldcountable' => null );
+ $options += array(
+ 'changed' => true,
+ 'created' => false,
+ 'moved' => false,
+ 'oldcountable' => null
+ );
$content = $revision->getContent();
// Parse the text
@@ -2186,7 +2179,7 @@ class WikiPage implements Page, IDBAccessObject {
// already pre-save transformed once.
if ( !$this->mPreparedEdit || $this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) {
wfDebug( __METHOD__ . ": No prepared edit or vary-revision is set...\n" );
- $editInfo = $this->prepareContentForEdit( $content, $revision->getId(), $user );
+ $editInfo = $this->prepareContentForEdit( $content, $revision, $user );
} else {
wfDebug( __METHOD__ . ": No vary-revision, using prepared edit...\n" );
$editInfo = $this->mPreparedEdit;
@@ -2208,18 +2201,18 @@ class WikiPage implements Page, IDBAccessObject {
DataUpdate::runUpdates( $updates );
}
- wfRunHooks( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
+ Hooks::run( 'ArticleEditUpdates', array( &$this, &$editInfo, $options['changed'] ) );
- if ( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
- if ( 0 == mt_rand( 0, 99 ) ) {
- // Flush old entries from the `recentchanges` table; we do this on
- // random requests so as to avoid an increase in writes for no good reason
- RecentChange::purgeExpiredChanges();
- }
+ if ( Hooks::run( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
+ JobQueueGroup::singleton()->push( array(
+ // Flush old entries from the `recentchanges` table
+ RecentChangesUpdateJob::newPurgeJob(),
+ // Update the cached list of active users
+ RecentChangesUpdateJob::newCacheUpdateJob()
+ ) );
}
if ( !$this->exists() ) {
- wfProfileOut( __METHOD__ );
return;
}
@@ -2227,7 +2220,9 @@ class WikiPage implements Page, IDBAccessObject {
$title = $this->mTitle->getPrefixedDBkey();
$shortTitle = $this->mTitle->getDBkey();
- if ( !$options['changed'] ) {
+ if ( $options['oldcountable'] === 'no-change' ||
+ ( !$options['changed'] && !$options['moved'] )
+ ) {
$good = 0;
} elseif ( $options['created'] ) {
$good = (int)$this->isCountable( $editInfo );
@@ -2255,7 +2250,7 @@ class WikiPage implements Page, IDBAccessObject {
wfDebug( __METHOD__ . ": invalid username\n" );
} else {
// Allow extensions to prevent user notification when a new message is added to their talk page
- if ( wfRunHooks( 'ArticleEditUpdateNewTalk', array( &$this, $recipient ) ) ) {
+ if ( Hooks::run( 'ArticleEditUpdateNewTalk', array( &$this, $recipient ) ) ) {
if ( User::isIP( $shortTitle ) ) {
// An anonymous user
$recipient->setNewtalk( true, $revision );
@@ -2284,7 +2279,6 @@ class WikiPage implements Page, IDBAccessObject {
self::onArticleEdit( $this->mTitle );
}
- wfProfileOut( __METHOD__ );
}
/**
@@ -2315,14 +2309,13 @@ class WikiPage implements Page, IDBAccessObject {
* @param User $user The relevant user
* @param string $comment Comment submitted
* @param bool $minor Whereas it's a minor modification
- * @param string $serialisation_format Format for storing the content in the database
+ * @param string $serialFormat Format for storing the content in the database
*/
public function doQuickEditContent( Content $content, User $user, $comment = '', $minor = false,
- $serialisation_format = null
+ $serialFormat = null
) {
- wfProfileIn( __METHOD__ );
- $serialized = $content->serialize( $serialisation_format );
+ $serialized = $content->serialize( $serialFormat );
$dbw = wfGetDB( DB_MASTER );
$revision = new Revision( array(
@@ -2338,9 +2331,8 @@ class WikiPage implements Page, IDBAccessObject {
$revision->insertOn( $dbw );
$this->updateRevisionOn( $dbw, $revision );
- wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
+ Hooks::run( 'NewRevisionFromEditComplete', array( $this, $revision, false, $user ) );
- wfProfileOut( __METHOD__ );
}
/**
@@ -2437,7 +2429,7 @@ class WikiPage implements Page, IDBAccessObject {
$logRelationsField = null;
if ( $id ) { // Protection of existing page
- if ( !wfRunHooks( 'ArticleProtect', array( &$this, &$user, $limit, $reason ) ) ) {
+ if ( !Hooks::run( 'ArticleProtect', array( &$this, &$user, $limit, $reason ) ) ) {
return Status::newGood();
}
@@ -2517,8 +2509,8 @@ class WikiPage implements Page, IDBAccessObject {
__METHOD__
);
- wfRunHooks( 'NewRevisionFromEditComplete', array( $this, $nullRevision, $latest, $user ) );
- wfRunHooks( 'ArticleProtectComplete', array( &$this, &$user, $limit, $reason ) );
+ 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
$cascade = false;
@@ -2780,7 +2772,7 @@ class WikiPage implements Page, IDBAccessObject {
}
$user = is_null( $user ) ? $wgUser : $user;
- if ( !wfRunHooks( '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' );
@@ -2896,7 +2888,7 @@ class WikiPage implements Page, IDBAccessObject {
$this->doDeleteUpdates( $id, $content );
- wfRunHooks( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id, $content, $logEntry ) );
+ Hooks::run( 'ArticleDeleteComplete', array( &$this, &$user, $reason, $id, $content, $logEntry ) );
$status->value = $logid;
return $status;
}
@@ -3031,8 +3023,8 @@ class WikiPage implements Page, IDBAccessObject {
// Get the last edit not by this guy...
// Note: these may not be public values
- $user = intval( $current->getRawUser() );
- $user_text = $dbw->addQuotes( $current->getRawUserText() );
+ $user = intval( $current->getUser( Revision::RAW ) );
+ $user_text = $dbw->addQuotes( $current->getUserText( Revision::RAW ) );
$s = $dbw->selectRow( 'revision',
array( 'rev_id', 'rev_timestamp', 'rev_deleted' ),
array( 'rev_page' => $current->getPage(),
@@ -3075,7 +3067,7 @@ class WikiPage implements Page, IDBAccessObject {
}
// Generate the edit summary if necessary
- $target = Revision::newFromId( $s->rev_id );
+ $target = Revision::newFromId( $s->rev_id, Revision::READ_LATEST );
if ( empty( $summary ) ) {
if ( $from == '' ) { // no public user name
$summary = wfMessage( 'revertpage-nouser' );
@@ -3138,7 +3130,7 @@ class WikiPage implements Page, IDBAccessObject {
$revId = $status->value['revision']->getId();
- wfRunHooks( 'ArticleRollbackComplete', array( $this, $guser, $target, $current ) );
+ Hooks::run( 'ArticleRollbackComplete', array( $this, $guser, $target, $current ) );
$resultDetails = array(
'summary' => $summary,
@@ -3161,13 +3153,9 @@ class WikiPage implements Page, IDBAccessObject {
*
* @param Title $title
*/
- public static function onArticleCreate( $title ) {
+ public static function onArticleCreate( Title $title ) {
// Update existence markers on article/talk tabs...
- if ( $title->isTalkPage() ) {
- $other = $title->getSubjectPage();
- } else {
- $other = $title->getTalkPage();
- }
+ $other = $title->getOtherPage();
$other->invalidateCache();
$other->purgeSquid();
@@ -3182,13 +3170,9 @@ class WikiPage implements Page, IDBAccessObject {
*
* @param Title $title
*/
- public static function onArticleDelete( $title ) {
+ public static function onArticleDelete( Title $title ) {
// Update existence markers on article/talk tabs...
- if ( $title->isTalkPage() ) {
- $other = $title->getSubjectPage();
- } else {
- $other = $title->getTalkPage();
- }
+ $other = $title->getOtherPage();
$other->invalidateCache();
$other->purgeSquid();
@@ -3227,10 +3211,8 @@ class WikiPage implements Page, IDBAccessObject {
* Purge caches on page update etc
*
* @param Title $title
- * @todo Verify that $title is always a Title object (and never false or
- * null), add Title hint to parameter $title.
*/
- public static function onArticleEdit( $title ) {
+ public static function onArticleEdit( Title $title ) {
// Invalidate caches of articles which include this page
DeferredUpdates::addHTMLCacheUpdate( $title, 'templatelinks' );
@@ -3390,82 +3372,52 @@ class WikiPage implements Page, IDBAccessObject {
foreach ( $added as $catName ) {
$cat = Category::newFromName( $catName );
- wfRunHooks( 'CategoryAfterPageAdded', array( $cat, $that ) );
+ Hooks::run( 'CategoryAfterPageAdded', array( $cat, $that ) );
}
foreach ( $deleted as $catName ) {
$cat = Category::newFromName( $catName );
- wfRunHooks( 'CategoryAfterPageRemoved', array( $cat, $that ) );
+ Hooks::run( 'CategoryAfterPageRemoved', array( $cat, $that ) );
}
}
);
}
/**
- * Updates cascading protections
+ * Opportunistically enqueue link update jobs given fresh parser output if useful
*
- * @param ParserOutput $parserOutput ParserOutput object for the current version
+ * @param ParserOutput $parserOutput Current version page output
+ * @since 1.25
*/
- public function doCascadeProtectionUpdates( ParserOutput $parserOutput ) {
- if ( wfReadOnly() || !$this->mTitle->areRestrictionsCascading() ) {
+ public function triggerOpportunisticLinksUpdate( ParserOutput $parserOutput ) {
+ if ( wfReadOnly() ) {
return;
}
- // templatelinks or imagelinks tables may have become out of sync,
- // especially if using variable-based transclusions.
- // For paranoia, check if things have changed and if
- // so apply updates to the database. This will ensure
- // that cascaded protections apply as soon as the changes
- // are visible.
-
- // Get templates from templatelinks and images from imagelinks
- $id = $this->getId();
-
- $dbLinks = array();
-
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( array( 'templatelinks' ),
- array( 'tl_namespace', 'tl_title' ),
- array( 'tl_from' => $id ),
- __METHOD__
- );
-
- foreach ( $res as $row ) {
- $dbLinks["{$row->tl_namespace}:{$row->tl_title}"] = true;
+ if ( !Hooks::run( 'OpportunisticLinksUpdate', array( $this, $this->mTitle, $parserOutput ) ) ) {
+ return;
}
- $dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( array( 'imagelinks' ),
- array( 'il_to' ),
- array( 'il_from' => $id ),
- __METHOD__
- );
-
- foreach ( $res as $row ) {
- $dbLinks[NS_FILE . ":{$row->il_to}"] = true;
+ if ( $this->mTitle->areRestrictionsCascading() ) {
+ // If the page is cascade protecting, the links should really be up-to-date
+ $params = array( 'prioritize' => true );
+ } elseif ( $parserOutput->hasDynamicContent() ) {
+ // Assume the output contains time/random based magic words
+ $params = array();
+ } else {
+ // If the inclusions are deterministic, the edit-triggered link jobs are enough
+ return;
}
- // Get templates and images from parser output.
- $poLinks = array();
- foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
- foreach ( $templates as $dbk => $id ) {
- $poLinks["$ns:$dbk"] = true;
- }
- }
- foreach ( $parserOutput->getImages() as $dbk => $id ) {
- $poLinks[NS_FILE . ":$dbk"] = true;
+ // Check if the last link refresh was before page_touched
+ if ( $this->getLinksTimestamp() < $this->getTouched() ) {
+ JobQueueGroup::singleton()->push( EnqueueJob::newFromLocalJobs(
+ new JobSpecification( 'refreshLinks', $params, array(), $this->mTitle )
+ ) );
+ return;
}
- // Get the diff
- $links_diff = array_diff_key( $poLinks, $dbLinks );
-
- if ( count( $links_diff ) > 0 ) {
- // Whee, link updates time.
- // Note: we are only interested in links here. We don't need to get
- // other DataUpdate items from the parser output.
- $u = new LinksUpdate( $this->mTitle, $parserOutput, false );
- $u->doUpdate();
- }
+ return;
}
/**
@@ -3548,7 +3500,7 @@ class WikiPage implements Page, IDBAccessObject {
$updates = $content->getDeletionUpdates( $this );
}
- wfRunHooks( 'WikiPageDeletionUpdates', array( $this, $content, &$updates ) );
+ Hooks::run( 'WikiPageDeletionUpdates', array( $this, $content, &$updates ) );
return $updates;
}
}