* @package MediaWiki
* @subpackage Cache
*/
-class LinkCache {
+class LinkCache {
// Increment $mClassVer whenever old serialized versions of this class
// becomes incompatible with the new version.
/* private */ var $mClassVer = 3;
global $wgDBname;
return $wgDBname.':lc:title:'.$title;
}
-
+
function LinkCache() {
$this->mActive = true;
$this->mPreFilled = false;
/**
* General accessor to get/set whether SELECT FOR UPDATE should be used
*/
- function forUpdate( $update = NULL ) {
+ function forUpdate( $update = NULL ) {
return wfSetVar( $this->mForUpdate, $update );
}
-
+
function getGoodLinkID( $title ) {
if ( array_key_exists( $title, $this->mGoodLinks ) ) {
return $this->mGoodLinks[$title];
}
function isBadLink( $title ) {
- return array_key_exists( $title, $this->mBadLinks );
+ return array_key_exists( $title, $this->mBadLinks );
}
function addGoodLinkObj( $id, $title ) {
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 );
}
unset( $this->mBadLinks[$title] );
$this->clearLink( $title );
}
-
+
function clearLink( $title ) {
global $wgMemc, $wgLinkCacheMemcached;
if( $wgLinkCacheMemcached )
return 0;
}
}
-
+
function addLinkObj( &$nt ) {
global $wgMemc, $wgLinkCacheMemcached, $wgAntiLockFlags;
$title = $nt->getPrefixedDBkey();
- if ( $this->isBadLink( $title ) ) { return 0; }
+ if ( $this->isBadLink( $title ) ) { return 0; }
$id = $this->getGoodLinkID( $title );
if ( 0 != $id ) { return $id; }
$ns = $nt->getNamespace();
$t = $nt->getDBkey();
- if ( '' == $title ) {
+ if ( '' == $title ) {
wfProfileOut( $fname );
- return 0;
+ return 0;
}
-
+
$id = NULL;
if( $wgLinkCacheMemcached )
$id = $wgMemc->get( $key = $this->getKey( $title ) );
$options = array();
}
- $id = $db->selectField( 'page', 'page_id', array( 'page_namespace' => $ns, 'page_title' => $t ), $fname, $options );
+ $id = $db->selectField( 'page', 'page_id',
+ array( 'page_namespace' => $ns, 'page_title' => $t ),
+ $fname, $options );
+wfdebug("link cache: id=$id\n");
if ( !$id ) {
$id = 0;
}
if( $wgLinkCacheMemcached )
$wgMemc->add( $key, $id, 3600*24 );
}
-
+
if( 0 == $id ) {
$this->addBadLinkObj( $nt );
} else {
$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 ) ) {
function getImageDeletions() {
return array_diff_assoc( $this->mOldImageLinks, $this->mImageLinks );
}
-
+
function getPageAdditions() {
$set = array_diff( array_keys( $this->mPageLinks ), array_keys( $this->mOldPageLinks ) );
$out = array();
}
return $out;
}
-
+
function getPageDeletions() {
$set = array_diff( array_keys( $this->mOldPageLinks ), array_keys( $this->mPageLinks ) );
$out = array();
$add = $this->getPageAdditions();
break;
default: # LINKCACHE_IMAGE
- return false;
+ return false;
}
-
+
return true;
}
/**
- * Clears cache
+ * Clears cache
*/
function clear() {
$this->mPageLinks = array();
* @subpackage Cache
*/
class LinkBatch {
- /**
+ /**
* 2-d array, first index namespace, second index dbkey, value arbitrary
*/
var $data = array();
$this->addObj( $item );
}
}
-
+
function addObj( $title ) {
$this->add( $title->getNamespace(), $title->getDBkey() );
}
$page = $dbr->tableName( 'page' );
$sql = "SELECT page_id, page_namespace, page_title FROM $page WHERE "
. $this->constructSet( 'page', $dbr );
-
+
// Do query
$res = $dbr->query( $sql, $fname );
wfProfileOut( $fname );
}
-
+
/**
* Construct a WHERE clause which will match all the given titles.
* Give the appropriate table's field name prefix ('page', 'pl', etc).