From c49610741d84e383935afe8840fa9480233bf29b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Tue, 20 Sep 2011 15:19:18 +0000 Subject: [PATCH] Added LinkCache::addGoodLinkObjFromRow, since addGoodLinkObj is not going to work much longer when new parameters are added --- includes/Title.php | 2 +- includes/WikiPage.php | 3 +-- includes/cache/LinkBatch.php | 2 +- includes/cache/LinkCache.php | 32 +++++++++++++++++------------ includes/parser/LinkHolderArray.php | 6 +++--- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index c5c2d65628..14ac5ba02e 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2918,7 +2918,7 @@ class Title { foreach ( $res as $row ) { $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ); if ( $titleObj ) { - $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect, $row->page_latest ); + $linkCache->addGoodLinkObjFromRow( $titleObj, $row ); $retVal[] = $titleObj; } } diff --git a/includes/WikiPage.php b/includes/WikiPage.php index 1029d31546..b95faed429 100644 --- a/includes/WikiPage.php +++ b/includes/WikiPage.php @@ -371,8 +371,7 @@ class WikiPage extends Page { $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 ); diff --git a/includes/cache/LinkBatch.php b/includes/cache/LinkBatch.php index 0bd869fc4e..738dc2dc85 100644 --- a/includes/cache/LinkBatch.php +++ b/includes/cache/LinkBatch.php @@ -126,7 +126,7 @@ class LinkBatch { $remaining = $this->data; foreach ( $res as $row ) { $title = Title::makeTitle( $row->page_namespace, $row->page_title ); - $cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect, $row->page_latest ); + $cache->addGoodLinkObjFromRow( $title, $row ); $ids[$title->getPrefixedDBkey()] = $row->page_id; unset( $remaining[$row->page_namespace][$row->page_title] ); } diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index 1deb99794a..9362c084eb 100644 --- a/includes/cache/LinkCache.php +++ b/includes/cache/LinkCache.php @@ -95,6 +95,23 @@ class LinkCache { 'revision' => intval( $revision ) ); } + /** + * Same as above with better interface. + * @since 1.19 + * @param $title Title + * @param $row object which has the fields page_id, page_is_redirect, + * page_latest + */ + public function addGoodLinkObjFromRow( $title, $row ) { + $dbkey = $title->getPrefixedDbKey(); + $this->mGoodLinks[$dbkey] = intval( $row->page_id ); + $this->mGoodLinkFields[$dbkey] = array( + 'length' => intval( $row->page_len ), + 'redirect' => intval( $row->page_is_redirect ), + 'revision' => intval( $row->page_latest ), + ); + } + /** * @param $title Title */ @@ -182,22 +199,11 @@ class LinkCache { __METHOD__, $options ); # Set fields... if ( $s !== false ) { - $id = intval( $s->page_id ); - $len = intval( $s->page_len ); - $redirect = intval( $s->page_is_redirect ); - $revision = intval( $s->page_latest ); + $this->addGoodLinkObjFromRow( $nt, $s ); } else { - $id = 0; - $len = -1; - $redirect = 0; - $revision = 0; - } - - if ( $id == 0 ) { $this->addBadLinkObj( $nt ); - } else { - $this->addGoodLinkObj( $id, $nt, $len, $redirect, $revision ); } + wfProfileOut( __METHOD__ ); return $id; } diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index 5418b6e517..fb01304734 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -320,7 +320,7 @@ class LinkHolderArray { foreach ( $res as $s ) { $title = Title::makeTitle( $s->page_namespace, $s->page_title ); $pdbk = $title->getPrefixedDBkey(); - $linkCache->addGoodLinkObj( $s->page_id, $title, $s->page_len, $s->page_is_redirect, $s->page_latest ); + $linkCache->addGoodLinkObjFromRow( $title, $s ); $output->addLink( $title, $s->page_id ); # @todo FIXME: Convoluted data flow # The redirect status and length is passed to getLinkColour via the LinkCache @@ -490,7 +490,7 @@ class LinkHolderArray { // construct query $dbr = wfGetDB( DB_SLAVE ); $varRes = $dbr->select( 'page', - array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len' ), + array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect', 'page_len', 'page_latest' ), $linkBatch->constructSet( 'page', $dbr ), __METHOD__ ); @@ -507,7 +507,7 @@ class LinkHolderArray { $holderKeys = array(); if( isset( $variantMap[$varPdbk] ) ) { $holderKeys = $variantMap[$varPdbk]; - $linkCache->addGoodLinkObj( $s->page_id, $variantTitle, $s->page_len, $s->page_is_redirect ); + $linkCache->addGoodLinkObjFromRow( $variantTitle, $s ); $output->addLink( $variantTitle, $s->page_id ); } -- 2.20.1