$lc =& LinkCache::singleton();
if ( $data ) {
- $lc->addGoodLinkObj( $data->page_id, $this->mTitle );
+ $lc->addGoodLinkObj( $data->page_id, $this->mTitle, $data->page_len, $data->page_is_redirect );
$this->mTitle->mArticleID = $data->page_id;
$remaining = $this->data;
while ( $row = $res->fetchObject() ) {
$title = Title::newFromRow( $row );
- $cache->addGoodLinkObj( $row->page_id, $title );
+ $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect );
$ids[$title->getPrefixedDBkey()] = $row->page_id;
unset( $remaining[$row->page_namespace][$row->page_title] );
}
class LinkCache {
// Increment $mClassVer whenever old serialized versions of this class
// becomes incompatible with the new version.
- /* private */ var $mClassVer = 3;
+ /* private */ var $mClassVer = 4;
/* private */ var $mPageLinks;
/* private */ var $mGoodLinks, $mBadLinks;
$this->mForUpdate = false;
$this->mPageLinks = array();
$this->mGoodLinks = array();
+ $this->mGoodLinkFields = array();
$this->mBadLinks = array();
}
return 0;
}
}
+
+ /**
+ * Get a field of a title object from cache.
+ * If this link is not good, it will return NULL.
+ * @param Title $title
+ * @param string $field ('length','redirect')
+ * @return mixed
+ */
+ function getGoodLinkFieldObj( $title, $field ) {
+ $dbkey = $title->getPrefixedDbKey();
+ if ( array_key_exists( $dbkey, $this->mGoodLinkFields ) ) {
+ return $this->mGoodLinkFields[$dbkey][$field];
+ } else {
+ return NULL;
+ }
+ }
function isBadLink( $title ) {
return array_key_exists( $title, $this->mBadLinks );
}
- function addGoodLinkObj( $id, $title ) {
+ /**
+ * Add a link for the title to the link cache
+ * @param int $id
+ * @param Title $title
+ * @param int $len
+ * @param int $redir
+ */
+ function addGoodLinkObj( $id, $title, $len = -1, $redir = NULL ) {
$dbkey = $title->getPrefixedDbKey();
$this->mGoodLinks[$dbkey] = $id;
+ $this->mGoodLinkFields[$dbkey] = array( 'length' => $len, 'redirect' => $redir );
$this->mPageLinks[$dbkey] = $title;
}
wfProfileOut( $fname );
return 0;
}
-
+ # Some fields heavily used for linking...
$id = NULL;
- if( $wgLinkCacheMemcached )
+ $len = -1;
+ $redirect = NULL;
+
+ if( $wgLinkCacheMemcached ) {
$id = $wgMemc->get( $key = $this->getKey( $title ) );
- if( ! is_integer( $id ) ) {
+ }
+ if( !is_integer( $id ) ) {
if ( $this->mForUpdate ) {
$db = wfGetDB( DB_MASTER );
if ( !( $wgAntiLockFlags & ALF_NO_LINK_LOCK ) ) {
$options = array();
}
- $id = $db->selectField( 'page', 'page_id',
- array( 'page_namespace' => $ns, 'page_title' => $t ),
- $fname, $options );
- if ( !$id ) {
- $id = 0;
- }
- if( $wgLinkCacheMemcached )
+ $s = $db->selectRow( 'page',
+ array( 'page_id', 'page_len', 'page_is_redirect' ),
+ array( 'page_namespace' => $ns, 'page_title' => $t ),
+ $fname, $options );
+ # Set fields...
+ $id = $s ? $s->page_id : 0;
+ $len = $s ? $s->page_len : -1;
+ $redirect = $s ? $s->page_is_redirect : 0;
+
+ if( $wgLinkCacheMemcached ) {
$wgMemc->add( $key, $id, 3600*24 );
+ }
}
if( 0 == $id ) {
$this->addBadLinkObj( $nt );
} else {
- $this->addGoodLinkObj( $id, $nt );
+ $this->addGoodLinkObj( $id, $nt, $len, $redirect );
}
wfProfileOut( $fname );
return $id;
function clear() {
$this->mPageLinks = array();
$this->mGoodLinks = array();
+ $this->mGoodLinkFields = array();
$this->mBadLinks = array();
}
}
while ( $s = $dbr->fetchObject($res) ) {
$title = Title::newFromRow( $s );
$pdbk = $title->getPrefixedDBkey();
- $linkCache->addGoodLinkObj( $s->page_id, $title );
+ $linkCache->addGoodLinkObj( $s->page_id, $title, $s->page_len, $s->page_is_redirect );
$this->mOutput->addLink( $title, $s->page_id );
$colours[$pdbk] = $sk->getLinkColour( $title, $threshold );
//add id to the extension todolist
$holderKeys = array();
if(isset($variantMap[$varPdbk])){
$holderKeys = $variantMap[$varPdbk];
- $linkCache->addGoodLinkObj( $s->page_id, $variantTitle );
+ $linkCache->addGoodLinkObj( $s->page_id, $variantTitle, $s->page_len, $s->page_is_redirect );
$this->mOutput->addLink( $variantTitle, $s->page_id );
}
while ( $s = $dbr->fetchObject($res) ) {
$title = Title::newFromRow( $s );
$pdbk = $title->getPrefixedDBkey();
- $linkCache->addGoodLinkObj( $s->page_id, $title );
+ $linkCache->addGoodLinkObj( $s->page_id, $title, $s->page_len, $s->page_is_redirect );
$this->mOutput->addLink( $title, $s->page_id );
$colours[$pdbk] = ( $threshold == 0 || (
$holderKeys = array();
if(isset($variantMap[$varPdbk])){
$holderKeys = $variantMap[$varPdbk];
- $linkCache->addGoodLinkObj( $s->page_id, $variantTitle );
+ $linkCache->addGoodLinkObj( $s->page_id, $variantTitle, $s->page_len, $s->page_is_redirect );
$this->mOutput->addLink( $variantTitle, $s->page_id );
}
$this->mLatestID = false;
$this->mOldRestrictions = false;
$this->mLength = -1;
- $this->mRedirect = null;
+ $this->mRedirect = NULL;
}
/**
*/
public static function newFromRow( $row ) {
$t = self::makeTitle( $row->page_namespace, $row->page_title );
-
- $t->mArticleID = isset($row->page_id) ? $row->page_id : -1;
- $t->mLength = isset($row->page_len) ? $row->page_len : -1;
- $t->mRedirect = isset($row->page_is_redirect) ? (bool)$row->page_is_redirect : null;
- $t->mLatest = isset($row->page_latest) ? $row->page_latest : 0;
-
+
+ $t->mArticleID = isset($row->page_id) ? intval($row->page_id) : -1;
+ $t->mLength = isset($row->page_len) ? intval($row->page_len) : -1;
+ $t->mRedirect = isset($row->page_is_redirect) ? intval($row->page_is_redirect) : NULL;
+ $t->mLatestID = isset($row->page_latest) ? $row->page_latest : false;
+
return $t;
}
public function isTalkPage() {
return MWNamespace::isTalk( $this->getNamespace() );
}
-
- /**
- * Is this an article that is a redirect page?
- * @return bool
- */
- public function isRedirect() {
- if( $this->mRedirect !== null )
- return $this->mRedirect;
- # Zero for special pages
- if( $this->getNamespace() == NS_SPECIAL )
- return 0;
-
- $dbr = wfGetDB( DB_SLAVE );
- $redir = $dbr->selectField( 'page', 'page_is_redirect',
- array( 'page_id' => $this->getArticleId() ),
- __METHOD__ );
-
- $this->mRedirect = (bool)$redir;
-
- return $this->mRedirect;
- }
-
- /**
- * What is the length of this page?
- * @return bool
- */
- public function getLength() {
- if( $this->mLength != -1 || $this->mArticleID == 0 )
- return $this->mLength;
- # Zero for special pages
- if( $this->getNamespace() == NS_SPECIAL )
- return 0;
-
- $dbr = wfGetDB( DB_SLAVE );
- $len = $dbr->selectField( 'page', 'page_len',
- array( 'page_id' => $this->getArticleId() ),
- __METHOD__ );
- $this->mLength = intval($len);
-
- return $this->mLength;
- }
/**
* Is this a subpage?
}
return $this->mArticleID;
}
+
+ /**
+ * Is this an article that is a redirect page?
+ * Uses link cache, adding it if necessary
+ * @param int $flags a bit field; may be GAID_FOR_UPDATE to select for update
+ * @return bool
+ */
+ public function isRedirect( $flags = 0 ) {
+ # Zero for special pages.
+ # Also, calling getArticleID() loads the field from cache!
+ if( !$this->getArticleID($flags) || $this->getNamespace() == NS_SPECIAL ) {
+ return false;
+ }
+ $linkCache =& LinkCache::singleton();
+ $this->mRedirect = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
+
+ return (bool)$this->mRedirect;
+ }
+
+ /**
+ * What is the length of this page?
+ * Uses link cache, adding it if necessary
+ * @param int $flags a bit field; may be GAID_FOR_UPDATE to select for update
+ * @return bool
+ */
+ public function getLength( $flags = 0 ) {
+ # Zero for special pages.
+ # Also, calling getArticleID() loads the field from cache!
+ if( !$this->getArticleID($flags) || $this->getNamespace() == NS_SPECIAL ) {
+ return 0;
+ }
+ $linkCache =& LinkCache::singleton();
+ $this->mLength = $linkCache->getGoodLinkFieldObj( $this, 'length' );
+
+ return intval($this->mLength);
+ }
public function getLatestRevID() {
if ($this->mLatestID !== false)
if ( $db->numRows( $res ) ) {
while ( $row = $db->fetchObject( $res ) ) {
if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
- $linkCache->addGoodLinkObj( $row->page_id, $titleObj );
+ $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect );
$retVal[] = $titleObj;
}
}
if( $title instanceof Title ) {
// Update the link cache while we're at it
if( $row->page_id ) {
- $cache->addGoodLinkObj( $row->page_id, $title );
+ $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect );
} else {
$cache->addBadLinkObj( $title );
}
if ( $db->numRows( $res ) ) {
while ( $row = $db->fetchObject( $res ) ) {
if ( $titleObj = Title::newFromRow( $row ) ) {
- $linkCache->addGoodLinkObj( $row->page_id, $titleObj );
+ $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect );
$retVal[] = $titleObj;
}
}