class WikiPage extends Page {
/**
* @var Title
- * @protected
*/
public $mTitle = null;
public $mCounter = -1; // !< Integer (-1 means "not loaded")
public $mDataLoaded = false; // !< Boolean
public $mIsRedirect = false; // !< Boolean
- public $mLatest = false; // !< Boolean
+ public $mLatest = false; // !< Integer (false means "not loaded")
public $mPreparedEdit = false; // !< Array
- public $mRedirectTarget = null; // !< Title object
- public $mLastRevision = null; // !< Revision object
- public $mTimestamp = ''; // !< String
- public $mTouched = '19700101000000'; // !< String
- /**@}}*/
/**
- * @protected
- * @var ParserOptions: ParserOptions object for $wgUser articles
+ * @var Title
+ */
+ protected $mRedirectTarget = null;
+
+ /**
+ * @var Revision
*/
- public $mParserOptions;
+ protected $mLastRevision = null;
+
+ protected $mTimestamp = ''; // !< String
+ protected $mTouched = '19700101000000'; // !< String
+ /**@}}*/
/**
* Constructor and clear the article
/**
* Constructor from a page id
*
- * Always override this for all subclasses (until we use PHP with LSB)
- *
* @param $id Int article ID to load
*
* @return WikiPage
*/
public static function newFromID( $id ) {
$t = Title::newFromID( $id );
- # @todo FIXME: Doesn't inherit right
- return $t == null ? null : new self( $t );
- # return $t == null ? null : new static( $t ); // PHP 5.3
+ if ( $t ) {
+ return self::factory( $t );
+ }
+ return null;
}
/**
* (and only when) $wgActions[$action] === true. This allows subclasses
* to override the default behavior.
*
+ * @todo: move this UI stuff somewhere else
+ *
* @return Array
*/
public function getActionOverrides() {
$dbw = wfGetDB( DB_MASTER );
$dbw->replace( 'redirect', array( 'rd_from' ),
array(
- 'rd_from' => $this->getId(),
- 'rd_namespace' => $rt->getNamespace(),
- 'rd_title' => $rt->getDBkey(),
- 'rd_fragment' => $rt->getFragment(),
- 'rd_interwiki' => $rt->getInterwiki(),
+ 'rd_from' => $this->getId(),
+ 'rd_namespace' => $rt->getNamespace(),
+ 'rd_title' => $rt->getDBkey(),
+ 'rd_fragment' => $rt->getFragment(),
+ 'rd_interwiki' => $rt->getInterwiki(),
),
__METHOD__
);
return $rt->getFullURL( 'rdfrom=' . urlencode( $source ) );
}
} else {
- if ( $rt->getNamespace() == NS_SPECIAL ) {
+ if ( $rt->isSpecialPage() ) {
// Gotta handle redirects to special pages differently:
// Fill the HTTP response "Location" header and ignore
// the rest of the page we're on.
$lc = LinkCache::singleton();
if ( $data ) {
- $lc->addGoodLinkObj( $data->page_id, $this->mTitle,
- $data->page_len, $data->page_is_redirect, $data->page_latest );
+ $lc->addGoodLinkObjFromRow( $this->mTitle, $data );
$this->mTitle->loadFromRow( $data );
* @return string MW timestamp of last article revision
*/
public function getTimestamp() {
- // Check if the field has been filled by ParserCache::get()
+ // Check if the field has been filled by WikiPage::setTimestamp()
if ( !$this->mTimestamp ) {
$this->loadLastEdit();
}
if ( $dbr->implicitGroupby() ) {
$realNameField = 'user_real_name';
} else {
- $realNameField = 'FIRST(user_real_name) AS user_real_name';
+ $realNameField = 'MIN(user_real_name) AS user_real_name';
}
$tables = array( 'revision', 'user' );
/**
* Should the parser cache be used?
*
- * @param $user User The relevant user
+ * @param $parserOptions ParserOptions to check
+ * @param $oldid int
* @return boolean
*/
- public function isParserCacheUsed( User $user, $oldid ) {
+ public function isParserCacheUsed( ParserOptions $parserOptions, $oldid ) {
global $wgEnableParserCache;
return $wgEnableParserCache
- && $user->getStubThreshold() == 0
+ && $parserOptions->getStubThreshold() == 0
&& $this->exists()
- && empty( $oldid )
- && !$this->mTitle->isCssOrJsPage()
- && !$this->mTitle->isCssJsSubpage();
+ && ( $oldid === null || $oldid === 0 || $oldid === $this->getLatest() )
+ && $this->mTitle->isWikitextPage();
+ }
+
+ /**
+ * Get a ParserOutput for the given ParserOptions and revision ID.
+ * The parser cache will be used if possible.
+ *
+ * @since 1.19
+ * @param $parserOptions ParserOptions to use for the parse operation
+ * @param $oldid Revision ID to get the text from, passing null or 0 will
+ * get the current revision (default value)
+ * @return 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" );
+ if ( $parserOptions->getStubThreshold() ) {
+ wfIncrStats( 'pcache_miss_stub' );
+ }
+
+ if ( $useParserCache ) {
+ $parserOutput = ParserCache::singleton()->get( $this, $parserOptions );
+ if ( $parserOutput !== false ) {
+ wfProfileOut( __METHOD__ );
+ return $parserOutput;
+ }
+ }
+
+ if ( $oldid === null || $oldid === 0 ) {
+ $oldid = $this->getLatest();
+ }
+
+ $pool = new PoolWorkArticleView( $this, $parserOptions, $oldid, $useParserCache );
+ $pool->execute();
+
+ wfProfileOut( __METHOD__ );
+
+ return $pool->getParserOutput();
}
/**
MessageCache::singleton()->replace( $this->mTitle->getDBkey(), $text );
}
+ return true;
}
/**
*
* @param $dbw DatabaseBase
* @return int The newly created page_id key, or false if the title already existed
- * @private
*/
public function insertOn( $dbw ) {
wfProfileIn( __METHOD__ );
*
* @param $dbw DatabaseBase: object
* @param $revision Revision: For ID number, and text used to set
- length and redirect status fields
+ * length and redirect status fields
* @param $lastRevision Integer: if given, will not overwrite the page field
* when different from the currently set value.
* Giving 0 indicates the new page flag should be set
wfProfileIn( __METHOD__ );
$text = $revision->getText();
+ $len = strlen( $text );
$rt = Title::newFromRedirectRecurse( $text );
$conditions = array( 'page_id' => $this->getId() );
'page_touched' => $dbw->timestamp( $now ),
'page_is_new' => ( $lastRevision === 0 ) ? 1 : 0,
'page_is_redirect' => $rt !== null ? 1 : 0,
- 'page_len' => strlen( $text ),
+ 'page_len' => $len,
),
$conditions,
__METHOD__ );
$result = $dbw->affectedRows() != 0;
if ( $result ) {
$this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect );
+ $this->setLastEdit( $revision );
$this->setCachedLastEditTime( $now );
+ $this->mLatest = $revision->getId();
+ $this->mIsRedirect = (bool)$rt;
+ # Update the LinkCache.
+ LinkCache::singleton()->addGoodLinkObj( $this->getId(), $this->mTitle, $len, $this->mIsRedirect, $this->mLatest );
}
wfProfileOut( __METHOD__ );
}
/**
- * Get the cached timestamp for the last time the page changed
+ * 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() {
}
/**
- * Set the cached timestamp for the last time the page changed
+ * 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 $timestamp string
* @return void
*/
- protected function setCachedLastEditTime( $timestamp ) {
+ public function setCachedLastEditTime( $timestamp ) {
global $wgMemc;
$key = wfMemcKey( 'page-lastedit', md5( $this->mTitle->getPrefixedDBkey() ) );
$wgMemc->set( $key, wfTimestamp( TS_MW, $timestamp ), 60*15 );
if ( $section == 'new' ) {
# Inserting a new section
$subject = $summary ? wfMsgForContent( 'newsectionheaderdefaultlevel', $summary ) . "\n\n" : '';
- $text = strlen( trim( $oldtext ) ) > 0
+ if ( wfRunHooks( 'PlaceNewSection', array( $this, $oldtext, $subject, &$text ) ) ) {
+ $text = strlen( trim( $oldtext ) ) > 0
? "{$oldtext}\n\n{$subject}{$text}"
: "{$subject}{$text}";
+ }
} else {
# Replacing an existing section; roll out the big guns
global $wgParser;
* Fill in blank summaries with generated text where possible
*
* If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected.
- * If EDIT_UPDATE is specified and the article doesn't exist, the function will an
+ * If EDIT_UPDATE is specified and the article doesn't exist, the function will return an
* edit-gone-missing error. If EDIT_NEW is specified and the article does exist, an
* edit-already-exists error will be returned. These two conditions are also possible with
* auto-detection due to MediaWiki's performance-optimised locking strategy.
$status = Status::newGood( array() );
# Load $this->mTitle->getArticleID() and $this->mLatest if it's not already
- $this->loadPageData();
+ $this->loadPageData( 'fromdbmaster' );
$flags = $this->checkFlags( $flags );
$oldtext = $this->getRawText(); // current revision
$oldsize = strlen( $oldtext );
+ $oldid = $this->getLatest();
+ $oldIsRedirect = $this->isRedirect();
$oldcountable = $this->isCountable();
# Provide autosummaries if one is not provided and autosummaries are enabled.
if ( $wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '' ) {
- $summary = $this->getAutosummary( $oldtext, $text, $flags );
+ $summary = self::getAutosummary( $oldtext, $text, $flags );
}
$editInfo = $this->prepareTextForEdit( $text, null, $user );
'comment' => $summary,
'minor_edit' => $isminor,
'text' => $text,
- 'parent_id' => $this->mLatest,
+ 'parent_id' => $oldid,
'user' => $user->getId(),
'user_text' => $user->getName(),
'timestamp' => $now
# edit conflicts reliably, either by $ok here, or by $article->getTimestamp()
# before this function is called. A previous function used a separate query, this
# creates a window where concurrent edits can cause an ignored edit conflict.
- $ok = $this->updateRevisionOn( $dbw, $revision, $this->mLatest );
+ $ok = $this->updateRevisionOn( $dbw, $revision, $oldid, $oldIsRedirect );
if ( !$ok ) {
/* Belated edit conflict! Run away!! */
$this->mTitle->getUserPermissionsErrors( 'autopatrol', $user ) );
# Add RC row to the DB
$rc = RecentChange::notifyEdit( $now, $this->mTitle, $isminor, $user, $summary,
- $this->mLatest, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
+ $oldid, $this->getTimestamp(), $bot, '', $oldsize, $newsize,
$revisionId, $patrolled
);
) );
$revisionId = $revision->insertOn( $dbw );
- $this->mTitle->resetArticleID( $newid );
- # Update the LinkCache. Resetting the Title ArticleID means it will rely on having that already cached
- # @todo FIXME?
- LinkCache::singleton()->addGoodLinkObj( $newid, $this->mTitle, strlen( $text ), (bool)Title::newFromRedirect( $text ), $revisionId );
-
# Update the page record with revision data
$this->updateRevisionOn( $dbw, $revision, 0 );
# Do updates right now unless deferral was requested
if ( !( $flags & EDIT_DEFER_UPDATES ) ) {
- wfDoUpdates();
+ DeferredUpdates::doUpdates();
}
// Return the new revision (or null) to the caller
/**
* Update the article's restriction field, and leave a log entry.
*
+ * @todo: seperate the business/permission stuff out from backend code
+ *
* @param $limit Array: set of restriction keys
* @param $reason String
* @param &$cascade Integer. Set to false if cascading protection isn't allowed.
$encodedExpiry[$action] = $dbw->encodeExpiry( $expiry[$action] );
if ( $restrictions != '' ) {
- $protect_description .= "[$action=$restrictions] (";
+ $protect_description .= $wgContLang->getDirMark() . "[$action=$restrictions] (";
if ( $encodedExpiry[$action] != 'infinity' ) {
$protect_description .= wfMsgForContent( 'protect-expiring',
$wgContLang->timeanddate( $expiry[$action], false, false ) ,
*/
public function estimateRevisionCount() {
$dbr = wfGetDB( DB_SLAVE );
-
- // For an exact count...
- // return $dbr->selectField( 'revision', 'COUNT(*)',
- // array( 'rev_page' => $this->getId() ), __METHOD__ );
return $dbr->estimateRowCount( 'revision', '*',
array( 'rev_page' => $this->getId() ), __METHOD__ );
}
* Deletes the article with database consistency, writes logs, purges caches
*
* @param $reason string delete reason for deletion log
- * @param suppress bitfield
+ * @param $suppress bitfield
* Revision::DELETED_TEXT
* Revision::DELETED_COMMENT
* Revision::DELETED_USER
public function doDeleteArticle(
$reason, $suppress = false, $id = 0, $commit = true, &$error = '', User $user = null
) {
- global $wgDeferredUpdateList, $wgUseTrackbacks, $wgUser;
+ global $wgUser;
$user = is_null( $user ) ? $wgUser : $user;
wfDebug( __METHOD__ . "\n" );
return false;
}
- $u = new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 );
- array_push( $wgDeferredUpdateList, $u );
+ DeferredUpdates::addUpdate(
+ new SiteStatsUpdate( 0, 1, - (int)$this->isCountable(), -1 )
+ );
// Bitfields to further suppress the content
if ( $suppress ) {
'ar_flags' => '\'\'', // MySQL's "strict mode"...
'ar_len' => 'rev_len',
'ar_page_id' => 'page_id',
- 'ar_deleted' => $bitfield
+ 'ar_deleted' => $bitfield,
+ 'ar_sha1' => 'rev_sha1'
), array(
'page_id' => $id,
'page_id = rev_page'
if ( !$dbw->cascadingDeletes() ) {
$dbw->delete( 'revision', array( 'rev_page' => $id ), __METHOD__ );
- if ( $wgUseTrackbacks )
- $dbw->delete( 'trackbacks', array( 'tb_page' => $id ), __METHOD__ );
-
# Delete outgoing links
- $dbw->delete( 'pagelinks', array( 'pl_from' => $id ) );
- $dbw->delete( 'imagelinks', array( 'il_from' => $id ) );
- $dbw->delete( 'categorylinks', array( 'cl_from' => $id ) );
- $dbw->delete( 'templatelinks', array( 'tl_from' => $id ) );
- $dbw->delete( 'externallinks', array( 'el_from' => $id ) );
- $dbw->delete( 'langlinks', array( 'll_from' => $id ) );
- $dbw->delete( 'iwlinks', array( 'iwl_from' => $id ) );
- $dbw->delete( 'redirect', array( 'rd_from' => $id ) );
+ $dbw->delete( 'pagelinks', array( 'pl_from' => $id ), __METHOD__ );
+ $dbw->delete( 'imagelinks', array( 'il_from' => $id ), __METHOD__ );
+ $dbw->delete( 'categorylinks', array( 'cl_from' => $id ), __METHOD__ );
+ $dbw->delete( 'templatelinks', array( 'tl_from' => $id ), __METHOD__ );
+ $dbw->delete( 'externallinks', array( 'el_from' => $id ), __METHOD__ );
+ $dbw->delete( 'langlinks', array( 'll_from' => $id ), __METHOD__ );
+ $dbw->delete( 'iwlinks', array( 'iwl_from' => $id ), __METHOD__ );
+ $dbw->delete( 'redirect', array( 'rd_from' => $id ), __METHOD__ );
+ $dbw->delete( 'page_props', array( 'pp_page' => $id ), __METHOD__ );
}
# If using cleanup triggers, we can skip some manual deletes
# Log the deletion, if the page was suppressed, log it at Oversight instead
$logtype = $suppress ? 'suppress' : 'delete';
- $log = new LogPage( $logtype );
- # Make sure logging got through
- $log->addEntry( 'delete', $this->mTitle, $reason, array() );
+ $logEntry = new ManualLogEntry( $logtype, 'delete' );
+ $logEntry->setPerformer( $user );
+ $logEntry->setTarget( $this->mTitle );
+ $logEntry->setComment( $reason );
+ $logid = $logEntry->insert();
+ $logEntry->publish( $logid );
if ( $commit ) {
$dbw->commit();
* roll back to, e.g. user is the sole contributor. This function
* performs permissions checks on $user, then calls commitRollback()
* to do the dirty work
+ *
+ * @todo: seperate the business/permission stuff out from backend code
*
* @param $fromP String: Name of the user whose edits to rollback.
* @param $summary String: Custom summary. Set to default summary if empty.
* and return value documentation
*
* NOTE: This function does NOT check ANY permissions, it just commits the
- * rollback to the DB Therefore, you should only call this function direct-
+ * rollback to the DB. Therefore, you should only call this function direct-
* ly if you want to use custom permissions checks. If you don't, use
* doRollback() instead.
* @param $fromP String: Name of the user whose edits to rollback.
* @param $user User The relevant user
*/
public function doViewUpdates( User $user ) {
- global $wgDeferredUpdateList, $wgDisableCounters;
+ global $wgDisableCounters;
if ( wfReadOnly() ) {
return;
}
# Don't update page view counters on views from bot users (bug 14044)
if ( !$wgDisableCounters && !$user->isAllowed( 'bot' ) && $this->getId() ) {
- $wgDeferredUpdateList[] = new ViewCountUpdate( $this->getId() );
- $wgDeferredUpdateList[] = new SiteStatsUpdate( 1, 0, 0 );
+ DeferredUpdates::addUpdate( new ViewCountUpdate( $this->getId() ) );
+ DeferredUpdates::addUpdate( new SiteStatsUpdate( 1, 0, 0 ) );
}
# Update newtalk / watchlist notification status
* Returns a stdclass with source, pst and output members
*/
public function prepareTextForEdit( $text, $revid = null, User $user = null ) {
- global $wgParser, $wgUser;
+ global $wgParser, $wgContLang, $wgUser;
$user = is_null( $user ) ? $wgUser : $user;
// @TODO fixme: check $user->getId() here???
if ( $this->mPreparedEdit
return $this->mPreparedEdit;
}
- $popts = ParserOptions::newFromUser( $user );
+ $popts = ParserOptions::newFromUserAndLang( $user, $wgContLang );
wfRunHooks( 'ArticlePrepareTextForEdit', array( $this, $popts ) );
$edit = (object)array();
$edit->revid = $revid;
$edit->newText = $text;
- $edit->pst = $this->preSaveTransform( $text, $user, $popts );
- $edit->popts = $this->getParserOptions( true );
- $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
+ $edit->pst = $wgParser->preSaveTransform( $text, $this->mTitle, $user, $popts );
+ $edit->popts = $this->makeParserOptions( 'canonical' );
+
+ // Bug 32858: For a CSS/JS page, put a blank parser output into the
+ // prepared edit, so that links etc. won't be registered in the
+ // database. We could have set $edit->output to false or something if
+ // we thought of this bug earlier, but now that would break the
+ // interface with AbuseFilter etc.
+ if ( $this->mTitle->isCssOrJsPage() || $this->getTitle()->isCssJsSubpage() ) {
+ $input = '';
+ } else {
+ $input = $edit->pst;
+ }
+ $edit->output = $wgParser->parse( $input, $this->mTitle, $edit->popts, true, true, $revid );
$edit->oldText = $this->getRawText();
$this->mPreparedEdit = $edit;
* - null: don't change the article count
*/
public function doEditUpdates( Revision $revision, User $user, array $options = array() ) {
- global $wgDeferredUpdateList, $wgEnableParserCache;
+ global $wgEnableParserCache;
wfProfileIn( __METHOD__ );
$total = 0;
}
- $wgDeferredUpdateList[] = new SiteStatsUpdate( 0, 1, $good, $total );
- $wgDeferredUpdateList[] = new SearchUpdate( $id, $title, $text );
+ DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 1, $good, $total ) );
+ DeferredUpdates::addUpdate( new SearchUpdate( $id, $title, $text ) );
# If this is another user's talk page, update newtalk.
# Don't do this if $options['changed'] = false (null-edits) nor if
* This function is called right before saving the wikitext,
* so we can do things like signatures and links-in-context.
*
+ * @deprecated in 1.19; use Parser::preSaveTransform() instead
* @param $text String article contents
* @param $user User object: user doing the edit
* @param $popts ParserOptions object: parser options, default options for
*/
public function preSaveTransform( $text, User $user = null, ParserOptions $popts = null ) {
global $wgParser, $wgUser;
+
+ wfDeprecated( __METHOD__ );
+
$user = is_null( $user ) ? $wgUser : $user;
if ( $popts === null ) {
# User talk pages
if ( $title->getNamespace() == NS_USER_TALK ) {
$user = User::newFromName( $title->getText(), false );
- $user->setNewtalk( false );
+ if ( $user ) {
+ $user->setNewtalk( false );
+ }
}
# Image redirects
* @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 ) {
- global $wgDeferredUpdateList;
-
// Invalidate caches of articles which include this page
- $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'templatelinks' );
+ DeferredUpdates::addHTMLCacheUpdate( $title, 'templatelinks' );
+
// Invalidate the caches of all pages which redirect here
- $wgDeferredUpdateList[] = new HTMLCacheUpdate( $title, 'redirect' );
+ DeferredUpdates::addHTMLCacheUpdate( $title, 'redirect' );
# Purge squid for this page only
$title->purgeSquid();
}
/**
- * Get parser options suitable for rendering the primary article wikitext
- * @param $canonical boolean Determines that the generated options must not depend on user preferences (see bug 14404)
- * @return mixed ParserOptions object or boolean false
+ * Auto-generates a deletion reason
+ *
+ * @param &$hasHistory Boolean: whether the page has a history
+ * @return mixed String containing deletion reason or empty string, or boolean false
+ * if no revision occurred
*/
- public function getParserOptions( $canonical = false ) {
- global $wgUser, $wgLanguageCode;
+ public function getAutoDeleteReason( &$hasHistory ) {
+ global $wgContLang;
+
+ $dbw = wfGetDB( DB_MASTER );
+ // Get the last revision
+ $rev = Revision::newFromTitle( $this->getTitle() );
+
+ if ( is_null( $rev ) ) {
+ return false;
+ }
- if ( !$this->mParserOptions || $canonical ) {
- $user = !$canonical ? $wgUser : new User;
- $parserOptions = new ParserOptions( $user );
- $parserOptions->setTidy( true );
- $parserOptions->enableLimitReport();
+ // Get the article's contents
+ $contents = $rev->getText();
+ $blank = false;
- if ( $canonical ) {
- $parserOptions->setUserLang( $wgLanguageCode ); # Must be set explicitely
- return $parserOptions;
+ // 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;
}
- $this->mParserOptions = $parserOptions;
}
- // Clone to allow modifications of the return value without affecting cache
- return clone $this->mParserOptions;
+
+ // 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;
}
/**
* Get parser options suitable for rendering the primary article wikitext
- * @param User $user
+ * @param User|string $user User object or 'canonical'
* @return ParserOptions
*/
- public function makeParserOptions( User $user ) {
- $options = ParserOptions::newFromUser( $user );
+ public function makeParserOptions( $user ) {
+ global $wgContLang;
+ if ( $user instanceof User ) { // settings per user (even anons)
+ $options = ParserOptions::newFromUser( $user );
+ } else { // canonical settings
+ $options = ParserOptions::newFromUserAndLang( new User, $wgContLang );
+ }
$options->enableLimitReport(); // show inclusion/loop reports
$options->setTidy( true ); // fix bad HTML
return $options;
* Updates cascading protections
*
* @param $parserOutput ParserOutput object for the current version
- **/
+ */
public function doCascadeProtectionUpdates( ParserOutput $parserOutput ) {
if ( wfReadOnly() || !$this->mTitle->areRestrictionsCascading() ) {
return;
}
}
- /*
- * @deprecated since 1.18
- */
+ /**
+ * @deprecated since 1.18
+ */
public function quickEdit( $text, $comment = '', $minor = 0 ) {
global $wgUser;
return $this->doQuickEdit( $text, $wgUser, $comment, $minor );
}
- /*
- * @deprecated since 1.18
- */
+ /**
+ * @deprecated since 1.18
+ */
public function viewUpdates() {
global $wgUser;
return $this->doViewUpdates( $wgUser );
}
- /*
- * @deprecated since 1.18
- */
+ /**
+ * @deprecated since 1.18
+ */
public function useParserCache( $oldid ) {
global $wgUser;
- return $this->isParserCacheUsed( $wgUser, $oldid );
+ return $this->isParserCacheUsed( ParserOptions::newFromUser( $wgUser ), $oldid );
+ }
+}
+
+class PoolWorkArticleView extends PoolCounterWork {
+
+ /**
+ * @var Page
+ */
+ private $page;
+
+ /**
+ * @var string
+ */
+ private $cacheKey;
+
+ /**
+ * @var integer
+ */
+ private $revid;
+
+ /**
+ * @var ParserOptions
+ */
+ private $parserOptions;
+
+ /**
+ * @var string|null
+ */
+ private $text;
+
+ /**
+ * @var ParserOutput|false
+ */
+ private $parserOutput = false;
+
+ /**
+ * @var bool
+ */
+ private $isDirty = false;
+
+ /**
+ * @var Status|false
+ */
+ private $error = false;
+
+ /**
+ * Constructor
+ *
+ * @param $page Page
+ * @param $revid Integer: ID of the revision being parsed
+ * @param $useParserCache Boolean: whether to use the parser cache
+ * @param $parserOptions parserOptions to use for the parse operation
+ * @param $text String: text to parse or null to load it
+ */
+ function __construct( Page $page, ParserOptions $parserOptions, $revid, $useParserCache, $text = null ) {
+ $this->page = $page;
+ $this->revid = $revid;
+ $this->cacheable = $useParserCache;
+ $this->parserOptions = $parserOptions;
+ $this->text = $text;
+ $this->cacheKey = ParserCache::singleton()->getKey( $page, $parserOptions );
+ parent::__construct( 'ArticleView', $this->cacheKey . ':revid:' . $revid );
+ }
+
+ /**
+ * Get the ParserOutput from this object, or false in case of failure
+ *
+ * @return ParserOutput
+ */
+ public function getParserOutput() {
+ return $this->parserOutput;
+ }
+
+ /**
+ * Get whether the ParserOutput is a dirty one (i.e. expired)
+ *
+ * @return bool
+ */
+ public function getIsDirty() {
+ return $this->isDirty;
+ }
+
+ /**
+ * Get a Status object in case of error or false otherwise
+ *
+ * @return Status|false
+ */
+ public function getError() {
+ return $this->error;
+ }
+
+ /**
+ * @return bool
+ */
+ function doWork() {
+ global $wgParser, $wgUseFileCache;
+
+ $isCurrent = $this->revid === $this->page->getLatest();
+
+ if ( $this->text !== null ) {
+ $text = $this->text;
+ } elseif ( $isCurrent ) {
+ $text = $this->page->getRawText();
+ } else {
+ $rev = Revision::newFromTitle( $this->page->getTitle(), $this->revid );
+ if ( $rev === null ) {
+ return false;
+ }
+ $text = $rev->getText();
+ }
+
+ $time = - wfTime();
+ $this->parserOutput = $wgParser->parse( $text, $this->page->getTitle(),
+ $this->parserOptions, true, true, $this->revid );
+ $time += wfTime();
+
+ # Timing hack
+ if ( $time > 3 ) {
+ wfDebugLog( 'slow-parse', sprintf( "%-5.2f %s", $time,
+ $this->page->getTitle()->getPrefixedDBkey() ) );
+ }
+
+ if ( $this->cacheable && $this->parserOutput->isCacheable() ) {
+ ParserCache::singleton()->save( $this->parserOutput, $this->page, $this->parserOptions );
+ }
+
+ // Make sure file cache is not used on uncacheable content.
+ // Output that has magic words in it can still use the parser cache
+ // (if enabled), though it will generally expire sooner.
+ if ( !$this->parserOutput->isCacheable() || $this->parserOutput->containsOldMagic() ) {
+ $wgUseFileCache = false;
+ }
+
+ if ( $isCurrent ) {
+ $this->page->doCascadeProtectionUpdates( $this->parserOutput );
+ }
+
+ return true;
+ }
+
+ /**
+ * @return bool
+ */
+ function getCachedWork() {
+ $this->parserOutput = ParserCache::singleton()->get( $this->page, $this->parserOptions );
+
+ if ( $this->parserOutput === false ) {
+ wfDebug( __METHOD__ . ": parser cache miss\n" );
+ return false;
+ } else {
+ wfDebug( __METHOD__ . ": parser cache hit\n" );
+ return true;
+ }
+ }
+
+ /**
+ * @return bool
+ */
+ function fallback() {
+ $this->parserOutput = ParserCache::singleton()->getDirty( $this->page, $this->parserOptions );
+
+ if ( $this->parserOutput === false ) {
+ wfDebugLog( 'dirty', "dirty missing\n" );
+ wfDebug( __METHOD__ . ": no dirty cache\n" );
+ return false;
+ } else {
+ wfDebug( __METHOD__ . ": sending dirty output\n" );
+ wfDebugLog( 'dirty', "dirty output {$this->cacheKey}\n" );
+ $this->isDirty = true;
+ return true;
+ }
+ }
+
+ /**
+ * @param $status Status
+ */
+ function error( $status ) {
+ $this->error = $status;
+ return false;
}
}