$wgArticle
Article object corresponding to $wgTitle.
-$wgLinkCache
- LinkCache object.
-
$wgParser
Parser object. Parser extensions register their
hooks here.
* This is mostly copied from Title::getLinksTo()
*/
function getLinksTo( $options = '' ) {
- global $wgLinkCache;
$fname = 'Image::getLinksTo';
wfProfileIn( $fname );
} else {
$db =& wfGetDB( DB_SLAVE );
}
+ $linkCache =& LinkCache::singleton();
extract( $db->tableNames( 'page', 'imagelinks' ) );
$encName = $db->addQuotes( $this->name );
if ( $db->numRows( $res ) ) {
while ( $row = $db->fetchObject( $res ) ) {
if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
- $wgLinkCache->addGoodLinkObj( $row->page_id, $titleObj );
+ $linkCache->addGoodLinkObj( $row->page_id, $titleObj );
$retVal[] = $titleObj;
}
}
function setArray( $array ) {
$this->data = $array;
}
+
+ /**
+ * Do the query and add the results to the LinkCache object
+ * Return an array mapping PDBK to ID
+ */
+ function execute() {
+ $linkCache =& LinkCache::singleton();
+ $this->executeInto( $linkCache );
+ }
/**
- * Do the query and add the results to a LinkCache object
+ * Do the query and add the results to a given LinkCache object
* Return an array mapping PDBK to ID
*/
- function execute( &$cache ) {
+ function executeInto( &$cache ) {
$fname = 'LinkBatch::execute';
wfProfileIn( $fname );
// Do query
* @subpackage Cache
*/
-/**
- *
- */
-# These are used in incrementalSetup()
-define ('LINKCACHE_GOOD', 0);
-define ('LINKCACHE_BAD', 1);
-define ('LINKCACHE_IMAGE', 2);
-define ('LINKCACHE_PAGE', 3);
-
/**
* @package MediaWiki
* @subpackage Cache
/* private */ var $mClassVer = 3;
/* private */ var $mPageLinks;
- /* private */ var $mGoodLinks, $mBadLinks, $mActive;
- /* private */ var $mImageLinks, $mCategoryLinks;
- /* private */ var $mPreFilled, $mOldGoodLinks, $mOldBadLinks;
+ /* private */ var $mGoodLinks, $mBadLinks;
/* private */ var $mForUpdate;
- /* private */ function getKey( $title ) {
- global $wgDBname;
- return $wgDBname.':lc:title:'.$title;
+ /**
+ * Get an instance of this class
+ */
+ function &singleton() {
+ static $instance;
+ if ( !isset( $instance ) ) {
+ $instance = new LinkCache;
+ }
+ return $instance;
}
function LinkCache() {
- $this->mActive = true;
- $this->mPreFilled = false;
$this->mForUpdate = false;
$this->mPageLinks = array();
$this->mGoodLinks = array();
$this->mBadLinks = array();
- $this->mImageLinks = array();
- $this->mCategoryLinks = array();
- $this->mOldGoodLinks = array();
- $this->mOldBadLinks = array();
- $this->mOldPageLinks = array();
+ }
+
+ /* private */ function getKey( $title ) {
+ global $wgDBname;
+ return $wgDBname.':lc:title:'.$title;
}
/**
}
function addGoodLinkObj( $id, $title ) {
- if ( $this->mActive ) {
- $dbkey = $title->getPrefixedDbKey();
- $this->mGoodLinks[$dbkey] = $id;
- $this->mPageLinks[$dbkey] = $title;
- }
+ $dbkey = $title->getPrefixedDbKey();
+ $this->mGoodLinks[$dbkey] = $id;
+ $this->mPageLinks[$dbkey] = $title;
}
function addBadLinkObj( $title ) {
$dbkey = $title->getPrefixedDbKey();
- if ( $this->mActive && ( ! $this->isBadLink( $dbkey ) ) ) {
+ if ( ! $this->isBadLink( $dbkey ) ) {
$this->mBadLinks[$dbkey] = 1;
$this->mPageLinks[$dbkey] = $title;
}
}
- function addImageLink( $title ) {
- if ( $this->mActive ) { $this->mImageLinks[$title] = 1; }
- }
-
- function addImageLinkObj( $nt ) {
- if ( $this->mActive ) { $this->mImageLinks[$nt->getDBkey()] = 1; }
- }
-
- function addCategoryLink( $title, $sortkey ) {
- if ( $this->mActive ) { $this->mCategoryLinks[$title] = $sortkey; }
- }
-
- function addCategoryLinkObj( &$nt, $sortkey ) {
- $this->addCategoryLink( $nt->getDBkey(), $sortkey );
- }
-
function clearBadLink( $title ) {
unset( $this->mBadLinks[$title] );
$this->clearLink( $title );
$wgMemc->delete( $this->getKey( $title ) );
}
- /** @deprecated */
- function suspend() { $this->mActive = false; }
- /** @deprecated */
- function resume() { $this->mActive = true; }
-
function getPageLinks() { return $this->mPageLinks; }
function getGoodLinks() { return $this->mGoodLinks; }
function getBadLinks() { return array_keys( $this->mBadLinks ); }
- function getImageLinks() { return $this->mImageLinks; }
- function getCategoryLinks() { return $this->mCategoryLinks; }
-
+
/**
* Add a title to the link cache, return the page_id or zero if non-existent
* @param string $title Title to add
return $id;
}
- /**
- * Bulk-check the pagelinks and page arrays for existence info.
- * @param Title $fromtitle
- * @deprecated
- */
- function preFill( &$fromtitle ) {
- global $wgAntiLockFlags;
- $fname = 'LinkCache::preFill';
- wfProfileIn( $fname );
-
- $this->suspend();
- $id = $fromtitle->getArticleID();
- $this->resume();
-
- if( $id == 0 ) {
- wfDebug( "$fname - got id 0 for title '" . $fromtitle->getPrefixedDBkey() . "'\n" );
- wfProfileOut( $fname );
- return;
- }
-
- if ( $this->mForUpdate ) {
- $db =& wfGetDB( DB_MASTER );
- if ( !( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) ) {
- $options = 'FOR UPDATE';
- } else {
- $options = '';
- }
- } else {
- $db =& wfGetDB( DB_SLAVE );
- $options = '';
- }
-
- $page = $db->tableName( 'page' );
- $pagelinks = $db->tableName( 'pagelinks' );
-
- $sql = "SELECT page_id,pl_namespace,pl_title
- FROM $pagelinks
- LEFT JOIN $page
- ON pl_namespace=page_namespace AND pl_title=page_title
- WHERE pl_from=$id $options";
- $res = $db->query( $sql, $fname );
- while( $s = $db->fetchObject( $res ) ) {
- $title = Title::makeTitle( $s->pl_namespace, $s->pl_title );
- if( $s->page_id ) {
- $this->addGoodLinkObj( $s->page_id, $title );
- } else {
- $this->addBadLinkObj( $title );
- }
- }
- $this->mPreFilled = true;
-
- wfProfileOut( $fname );
- }
-
/**
* Clears cache
*/
$this->mPageLinks = array();
$this->mGoodLinks = array();
$this->mBadLinks = array();
- $this->mImageLinks = array();
- $this->mCategoryLinks = array();
- $this->mOldGoodLinks = array();
- $this->mOldBadLinks = array();
- $this->mOldPageLinks = array();
- }
-
- /**
- * Swaps old and current link registers
- * @deprecated
- */
- function swapRegisters() {
- swap( $this->mGoodLinks, $this->mOldGoodLinks );
- swap( $this->mBadLinks, $this->mOldBadLinks );
- swap( $this->mImageLinks, $this->mOldImageLinks );
- swap( $this->mPageLinks, $this->mOldPageLinks );
}
}
?>
* Add an array of categories, with names in the keys
*/
function addCategoryLinks($categories) {
- global $wgUser, $wgLinkCache, $wgContLang;
+ global $wgUser, $wgContLang;
# Add the links to the link cache in a batch
$arr = array( NS_CATEGORY => $categories );
$lb = new LinkBatch;
$lb->setArray( $arr );
- $lb->execute( $wgLinkCache );
+ $lb->execute();
$sk =& $wgUser->getSkin();
foreach ( $categories as $category => $arbitrary ) {
* performs brace substitution on MediaWiki messages
*
* Globals used:
- * objects: $wgLang, $wgLinkCache
+ * objects: $wgLang
*
* NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
*
* @access private
*/
function replaceInternalLinks( $s ) {
- global $wgContLang, $wgLinkCache;
+ global $wgContLang;
static $fname = 'Parser::replaceInternalLinks' ;
wfProfileIn( $fname );
* $options is a bit field, RLH_FOR_UPDATE to select for update
*/
function replaceLinkHolders( &$text, $options = 0 ) {
- global $wgUser, $wgLinkCache;
+ global $wgUser;
global $wgOutputReplace;
$fname = 'Parser::replaceLinkHolders';
$pdbks = array();
$colours = array();
- $sk = $this->mOptions->getSkin();
+ $sk =& $this->mOptions->getSkin();
+ $linkCache =& LinkCache::singleton();
if ( !empty( $this->mLinkHolders['namespaces'] ) ) {
wfProfileIn( $fname.'-check' );
# Check if it's a static known link, e.g. interwiki
if ( $title->isAlwaysKnown() ) {
$colours[$pdbk] = 1;
- } elseif ( ( $id = $wgLinkCache->getGoodLinkID( $pdbk ) ) != 0 ) {
+ } elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) {
$colours[$pdbk] = 1;
$this->mOutput->addLink( $title, $id );
- } elseif ( $wgLinkCache->isBadLink( $pdbk ) ) {
+ } elseif ( $linkCache->isBadLink( $pdbk ) ) {
$colours[$pdbk] = 0;
} else {
# Not in the link cache, add it to the query
while ( $s = $dbr->fetchObject($res) ) {
$title = Title::makeTitle( $s->page_namespace, $s->page_title );
$pdbk = $title->getPrefixedDBkey();
- $wgLinkCache->addGoodLinkObj( $s->page_id, $title );
+ $linkCache->addGoodLinkObj( $s->page_id, $title );
$this->mOutput->addLink( $title, $s->page_id );
if ( $threshold > 0 ) {
$searchkey = "<!--LINK $key-->";
$title = $this->mLinkHolders['titles'][$key];
if ( empty( $colours[$pdbk] ) ) {
- $wgLinkCache->addBadLinkObj( $title );
+ $linkCache->addBadLinkObj( $title );
$colours[$pdbk] = 0;
$this->mOutput->addLink( $title, 0 );
$wgOutputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title,
$wgDeferredUpdateList = array();
$wgPostCommitUpdateList = array();
-$wgLinkCache = new LinkCache();
$wgMagicWords = array();
$wgMwRedir =& MagicWord::get( MAG_REDIRECT );
$wgParserCache = new ParserCache( $messageMemc );
}
function dateLink() {
- global $wgLinkCache;
$t1 = Title::newFromText( gmdate( 'F j' ) );
$t2 = Title::newFromText( gmdate( 'Y' ) );
- $wgLinkCache->suspend();
$id = $t1->getArticleID();
- $wgLinkCache->resume();
if ( 0 == $id ) {
$s = $this->makeBrokenLink( $t1->getText() );
}
$s .= ', ';
- $wgLinkCache->suspend();
$id = $t2->getArticleID();
- $wgLinkCache->resume();
if ( 0 == $id ) {
$s .= $this->makeBrokenLink( $t2->getText() );
}
function talkLink() {
- global $wgTitle, $wgLinkCache;
+ global $wgTitle;
if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
# No discussion links for special pages
$text = wfMsg( 'talkpage' );
}
- $wgLinkCache->suspend();
$s = $this->makeLinkObj( $link, $text );
- $wgLinkCache->resume();
return $s;
}
function commentLink() {
- global $wgContLang, $wgTitle, $wgLinkCache;
+ global $wgContLang, $wgTitle;
if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
return '';
}
// avoid memory leak...?
- global $wgLinkCache;
- $wgLinkCache->clear();
+ $linkCache =& LinkCache::singleton();
+ $linkCache->clear();
$article = new Article( $this->title );
$pageId = $article->getId();
* Fetch user page links and cache their existence
*/
function preprocessResults( &$db, &$res ) {
- global $wgLinkCache;
-
$batch = new LinkBatch;
while ( $row = $db->fetchObject( $res ) ) {
$batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
}
- $batch->execute( $wgLinkCache );
+ $batch->execute();
// Back to start for display
if( $db->numRows( $res ) > 0 ) {
* @return object database result set
*/
function getLogRows() {
- global $wgLinkCache;
$result = $this->reader->getRows();
$this->numResults = 0;
}
++$this->numResults;
}
- $batch->execute( $wgLinkCache );
+ $batch->execute();
return $result;
}
* @private
*/
function logLine( $s ) {
- global $wgLang, $wgLinkCache;
+ global $wgLang;
$title = Title::makeTitle( $s->log_namespace, $s->log_title );
$user = Title::makeTitleSafe( NS_USER, $s->user_name );
$time = $wgLang->timeanddate( wfTimestamp(TS_MW, $s->log_timestamp), true );
// Enter the existence or non-existence of this page into the link cache,
// for faster makeLinkObj() in LogPage::actionText()
+ $linkCache =& LinkCache::singleton();
if( $s->page_id ) {
- $wgLinkCache->addGoodLinkObj( $s->page_id, $title );
+ $linkCache->addGoodLinkObj( $s->page_id, $title );
} else {
- $wgLinkCache->addBadLinkObj( $title );
+ $linkCache->addBadLinkObj( $title );
}
$userLink = $this->skin->makeLinkObj( $user, htmlspecialchars( $s->user_name ) );
* Fetch user page links and cache their existence
*/
function preprocessResults( &$db, &$res ) {
- global $wgLinkCache;
-
$batch = new LinkBatch;
while ( $row = $db->fetchObject( $res ) )
$batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
- $batch->execute( $wgLinkCache );
+ $batch->execute();
// Back to start for display
if ( $db->numRows( $res ) > 0 )
function wfSpecialRecentchanges( $par, $specialPage ) {
global $wgUser, $wgOut, $wgRequest, $wgUseRCPatrol;
global $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
- global $wgLinkCache;
$fname = 'wfSpecialRecentchanges';
# Get query parameters
# Web output...
// Run existence checks
- $batch->execute( $wgLinkCache );
+ $batch->execute();
// Output header
if ( !$specialPage->including() ) {
* Fetch user page links and cache their existence
*/
function preprocessResults( &$db, &$res ) {
- global $wgLinkCache;
-
$batch = new LinkBatch;
while ( $row = $db->fetchObject( $res ) )
$batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
- $batch->execute( $wgLinkCache );
+ $batch->execute();
// Back to start for display
if ( $db->numRows( $res ) > 0 )
* Fetch user page links and cache their existence
*/
function preprocessResults( &$db, &$res ) {
- global $wgLinkCache;
-
$batch = new LinkBatch;
while ( $row = $db->fetchObject( $res ) )
$batch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
- $batch->execute( $wgLinkCache );
+ $batch->execute();
// Back to start for display
if ( $db->numRows( $res ) > 0 )
* @access public
*/
function getArticleID( $flags = 0 ) {
- global $wgLinkCache;
+ $linkCache =& LinkCache::singleton();
if ( $flags & GAID_FOR_UPDATE ) {
- $oldUpdate = $wgLinkCache->forUpdate( true );
- $this->mArticleID = $wgLinkCache->addLinkObj( $this );
- $wgLinkCache->forUpdate( $oldUpdate );
+ $oldUpdate = $linkCache->forUpdate( true );
+ $this->mArticleID = $linkCache->addLinkObj( $this );
+ $linkCache->forUpdate( $oldUpdate );
} else {
if ( -1 == $this->mArticleID ) {
- $this->mArticleID = $wgLinkCache->addLinkObj( $this );
+ $this->mArticleID = $linkCache->addLinkObj( $this );
}
}
return $this->mArticleID;
/**
* This clears some fields in this object, and clears any associated
- * keys in the "bad links" section of $wgLinkCache.
+ * keys in the "bad links" section of the link cache.
*
* - This is called from Article::insertNewArticle() to allow
* loading of the new page_id. It's also called from
* @access public
*/
function resetArticleID( $newid ) {
- global $wgLinkCache;
- $wgLinkCache->clearBadLink( $this->getPrefixedDBkey() );
+ $linkCache =& LinkCache::singleton();
+ $linkCache->clearBadLink( $this->getPrefixedDBkey() );
if ( 0 == $newid ) { $this->mArticleID = -1; }
else { $this->mArticleID = $newid; }
* @access public
*/
function getLinksTo( $options = '', $table = 'pagelinks', $prefix = 'pl' ) {
- global $wgLinkCache;
+ $linkCache =& LinkCache::singleton();
$id = $this->getArticleID();
if ( $options ) {
if ( $db->numRows( $res ) ) {
while ( $row = $db->fetchObject( $res ) ) {
if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
- $wgLinkCache->addGoodLinkObj( $row->page_id, $titleObj );
+ $linkCache->addGoodLinkObj( $row->page_id, $titleObj );
$retVal[] = $titleObj;
}
}
* @access public
*/
function getBrokenLinksFrom( $options = '' ) {
- global $wgLinkCache;
-
if ( $options ) {
$db =& wfGetDB( DB_MASTER );
} else {
* @access private
*/
function moveOverExistingRedirect( &$nt, $reason = '' ) {
- global $wgUser, $wgLinkCache, $wgUseSquid, $wgMwRedir;
+ global $wgUser, $wgUseSquid, $wgMwRedir;
$fname = 'Title::moveOverExistingRedirect';
$comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
$newid = $nt->getArticleID();
$oldid = $this->getArticleID();
$dbw =& wfGetDB( DB_MASTER );
+ $linkCache =& LinkCache::singleton();
# Delete the old redirect. We don't save it to history since
# by definition if we've got here it's rather uninteresting.
/* WHERE */ array( 'page_id' => $oldid ),
$fname
);
- $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
+ $linkCache->clearLink( $nt->getPrefixedDBkey() );
# Recreate the redirect, this time in the other direction.
$redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
'text' => $redirectText ) );
$revid = $redirectRevision->insertOn( $dbw );
$redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
- $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
+ $linkCache->clearLink( $this->getPrefixedDBkey() );
# Log the move
$log = new LogPage( 'move' );
* @access private
*/
function moveToNewTitle( &$nt, &$newid, $reason = '' ) {
- global $wgUser, $wgLinkCache, $wgUseSquid;
+ global $wgUser, $wgUseSquid;
global $wgMwRedir;
$fname = 'MovePageForm::moveToNewTitle';
$comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
$oldid = $this->getArticleID();
$dbw =& wfGetDB( DB_MASTER );
$now = $dbw->timestamp();
- wfSeedRandom();
$rand = wfRandom();
+ $linkCache =& LinkCache::singleton();
# Save a null revision in the page's history notifying of the move
$nullRevision = Revision::newNullRevision( $dbw, $oldid,
$fname
);
- $wgLinkCache->clearLink( $nt->getPrefixedDBkey() );
+ $linkCache->clearLink( $nt->getPrefixedDBkey() );
# Insert redirect
$redirectText = $wgMwRedir->getSynonym( 0 ) . ' [[' . $nt->getPrefixedText() . "]]\n";
'text' => $redirectText ) );
$revid = $redirectRevision->insertOn( $dbw );
$redirectArticle->updateRevisionOn( $dbw, $redirectRevision, 0 );
- $wgLinkCache->clearLink( $this->getPrefixedDBkey() );
+ $linkCache->clearLink( $this->getPrefixedDBkey() );
# Log the move
$log = new LogPage( 'move' );
),
array( 'page_id' => $row->page_id ),
'cleanupTitles::moveInconsistentPage' );
- global $wgLinkCache;
- $wgLinkCache->clear();
+ $linkCache =& LinkCache::singleton();
+ $linkCache->clear();
}
}
}
function doRedirects() {
- global $wgLinkCache;
-
print "Doing redirects...\n";
$fname = 'DumpHTML::doRedirects';
$this->setupGlobals();
/** Reads the content of a title object, executes the skin and captures the result */
function getArticleHTML( &$title ) {
- global $wgOut, $wgTitle, $wgArticle, $wgUser, $wgLinkCache;
+ global $wgOut, $wgTitle, $wgArticle, $wgUser;
+ $linkCache =& LinkCache::singleton();
+ $linkCache->clear();
$wgTitle = $title;
if ( is_null( $wgTitle ) ) {
return false;
if ( $ns == NS_SPECIAL ) {
$wgOut = new OutputPage;
$wgOut->setParserOptions( new ParserOptions );
- $wgLinkCache = new LinkCache;
SpecialPage::executePath( $wgTitle );
} else {
if ( $ns == NS_IMAGE ) {
} else {
$wgOut = new OutputPage;
$wgOut->setParserOptions( new ParserOptions );
- $wgLinkCache = new LinkCache;
$wgArticle->view();
}