* Add newFromRow() function for Titles to optionally avoid some queries on accessor use
* Make linkbatch and some things that directly use linkcache select len/redirect fields along with the rest all in one query. This avoids query spam for link coloring.
/**
* Add a ResultWrapper containing IDs and titles to a LinkCache object
+ * Title are initialized here and they will go to the static title cache
+ * field of the Title class.
*/
function addResultToCache( $cache, $res ) {
if ( !$res ) {
$ids = array();
$remaining = $this->data;
while ( $row = $res->fetchObject() ) {
- $title = Title::makeTitle( $row->page_namespace, $row->page_title );
+ $title = Title::newFromRow( $row );
$cache->addGoodLinkObj( $row->page_id, $title );
$ids[$title->getPrefixedDBkey()] = $row->page_id;
unset( $remaining[$row->page_namespace][$row->page_title] );
wfProfileOut( __METHOD__ );
return false;
}
- $sql = "SELECT page_id, page_namespace, page_title FROM $page WHERE $set";
+ $sql = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect FROM $page WHERE $set";
// Do query
$res = new ResultWrapper( $dbr, $dbr->query( $sql, __METHOD__ ) );
/**
* Return the CSS colour of a known link
*
- * @param mixed $s
+ * @param Title $t
* @param integer $threshold user defined threshold
* @return string CSS class
*/
- function getLinkColour( $s, $threshold ) {
- if( $s === false ) {
- return '';
- }
-
+ function getLinkColour( $t, $threshold ) {
$colour = '';
- if ( !empty( $s->page_is_redirect ) ) {
+ if ( $t->isRedirect() ) {
# Page is a redirect
$colour = 'mw-redirect';
- } elseif ( $threshold > 0 && $s->page_len < $threshold && MWNamespace::isContent( $s->page_namespace ) ) {
+ } elseif ( $threshold > 0 && $t->getLength() < $threshold && MWNamespace::isContent( $t->getNamespace() ) ) {
# Page is a stub
$colour = 'stub';
}
} else {
$colour = '';
if ( $nt->isContentPage() ) {
- # FIXME: This is stupid, we should combine this query with
- # the Title::getArticleID() query above.
$threshold = $wgUser->getOption('stubthreshold');
- $dbr = wfGetDB( DB_SLAVE );
- $s = $dbr->selectRow(
- array( 'page' ),
- array( 'page_len', 'page_is_redirect', 'page_namespace' ),
- array( 'page_id' => $aid ), __METHOD__ ) ;
- $colour = $this->getLinkColour( $s, $threshold );
+ $colour = $this->getLinkColour( $nt, $threshold );
}
$retVal = $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix );
}
# Not in the link cache, add it to the query
if ( !isset( $current ) ) {
$current = $ns;
- $query = "SELECT page_id, page_namespace, page_title, page_is_redirect";
- if ( $threshold > 0 ) {
- $query .= ', page_len';
- }
+ $query = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len";
$query .= " FROM $page WHERE (page_namespace=$ns AND page_title IN(";
} elseif ( $current != $ns ) {
$current = $ns;
# Fetch data and form into an associative array
# non-existent = broken
while ( $s = $dbr->fetchObject($res) ) {
- $title = Title::makeTitle( $s->page_namespace, $s->page_title );
+ $title = Title::newFromRow( $s );
$pdbk = $title->getPrefixedDBkey();
$linkCache->addGoodLinkObj( $s->page_id, $title );
$this->mOutput->addLink( $title, $s->page_id );
// construct query
$titleClause = $linkBatch->constructSet('page', $dbr);
- $variantQuery = "SELECT page_id, page_namespace, page_title, page_is_redirect";
- if ( $threshold > 0 ) {
- $variantQuery .= ', page_len';
- }
+ $variantQuery = "SELECT page_id, page_namespace, page_title, page_is_redirect, page_len";
$variantQuery .= " FROM $page WHERE $titleClause";
if ( $options & RLH_FOR_UPDATE ) {
// for each found variants, figure out link holders and replace
while ( $s = $dbr->fetchObject($varRes) ) {
- $variantTitle = Title::makeTitle( $s->page_namespace, $s->page_title );
+ $variantTitle = Title::newFromRow( $s );
$varPdbk = $variantTitle->getPrefixedDBkey();
$vardbk = $variantTitle->getDBkey();
# Not in the link cache, add it to the query
if ( !isset( $current ) ) {
$current = $ns;
- $query = "SELECT page_id, page_namespace, page_title";
- if ( $threshold > 0 ) {
- $query .= ', page_len, page_is_redirect';
+ $query = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect";
}
$query .= " FROM $page WHERE (page_namespace=$ns AND page_title IN(";
} elseif ( $current != $ns ) {
# 1 = known
# 2 = stub
while ( $s = $dbr->fetchObject($res) ) {
- $title = Title::makeTitle( $s->page_namespace, $s->page_title );
+ $title = Title::newFromRow( $s );
$pdbk = $title->getPrefixedDBkey();
$linkCache->addGoodLinkObj( $s->page_id, $title );
$this->mOutput->addLink( $title, $s->page_id );
wfProfileOut( $fname.'-check' );
# Do a second query for different language variants of links and categories
- if($wgContLang->hasVariants()){
+ if( $wgContLang->hasVariants() ){
$linkBatch = new LinkBatch();
$variantMap = array(); // maps $pdbkey_Variant => $keys (of link holders)
$categoryMap = array(); // maps $category_variant => $category (dbkeys)
}
- if(!$linkBatch->isEmpty()){
+ if ( !$linkBatch->isEmpty() ){
// construct query
$titleClause = $linkBatch->constructSet('page', $dbr);
- $variantQuery = "SELECT page_id, page_namespace, page_title";
- if ( $threshold > 0 ) {
- $variantQuery .= ', page_len, page_is_redirect';
+ $variantQuery = "SELECT page_id, page_namespace, page_title, page_len, page_is_redirect";
}
$variantQuery .= " FROM $page WHERE $titleClause";
// for each found variants, figure out link holders and replace
while ( $s = $dbr->fetchObject($varRes) ) {
- $variantTitle = Title::makeTitle( $s->page_namespace, $s->page_title );
+ $variantTitle = Title::newFromRow( $s );
$varPdbk = $variantTitle->getPrefixedDBkey();
$vardbk = $variantTitle->getDBkey();
function __construct( $target, $namespace = false, $year = false, $month = false ) {
parent::__construct();
- foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist minoreditletter' ) as $msg ) {
+ foreach( explode( ' ', 'uctop diff newarticle rollbacklink diff hist newpageletter minoreditletter' ) as $msg ) {
$this->messages[$msg] = wfMsgExt( $msg, array( 'escape') );
}
$this->target = $target;
'fields' => array(
'page_namespace', 'page_title', 'page_is_new', 'page_latest', 'rev_id', 'rev_page',
'rev_text_id', 'rev_timestamp', 'rev_comment', 'rev_minor_edit', 'rev_user',
- 'rev_user_text', 'rev_deleted'
+ 'rev_user_text', 'rev_parent_id', 'rev_deleted'
),
'conds' => $conds,
'options' => array( 'USE INDEX' => $index )
if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
$d = '<span class="history-deleted">' . $d . '</span>';
}
+
+ if( $rev->getParentId() === 0 ) {
+ $nflag = '<span class="newpage">' . $this->messages['newpageletter'] . '</span>';
+ } else {
+ $nflag = '';
+ }
if( $row->rev_minor_edit ) {
$mflag = '<span class="minor">' . $this->messages['minoreditletter'] . '</span> ';
$mflag = '';
}
- $ret = "{$d} {$histlink} {$difftext} {$mflag} {$link}{$userlink}{$comment} {$topmarktext}";
+ $ret = "{$d} {$histlink} {$difftext} {$nflag}{$mflag} {$link}{$userlink}{$comment} {$topmarktext}";
if( $rev->isDeleted( Revision::DELETED_TEXT ) ) {
$ret .= ' ' . wfMsgHtml( 'deletedrev' );
}
var $mDefaultNamespace; # Namespace index when there is no namespace
# Zero except in {{transclusion}} tags
var $mWatched; # Is $wgUser watching this page? NULL if unfilled, accessed through userIsWatching()
+ var $mLength; # The page length, 0 for special pages
+ var $mRedirect; # Is the article at this title a redirect?
/**#@-*/
$this->mWatched = NULL;
$this->mLatestID = false;
$this->mOldRestrictions = false;
+ $this->mLength = -1;
+ $this->mRedirect = null;
}
/**
}
return $titles;
}
+
+ /**
+ * Make a Title object from a DB row
+ * @param Row $row (needs at least page_title,page_namespace)
+ */
+ 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) ? $row->page_is_redirect : -1;
+ $t->mLatest = isset($row->page_latest) ? $row->page_latest : 0;
+
+ return $t;
+ }
/**
* Create a new Title from a namespace index and a DB key.
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->mArticleID <= 0 )
+ return 0;
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $redir = $dbr->selectField( 'page', 'page_is_redirect',
+ array( 'page_id' => $this->mArticleID ),
+ __METHOD__ );
+
+ $this->mRedirect = $redir ? true : false;
+
+ return $this->mRedirect;
+ }
+
+ /**
+ * What is the length of this page (-1 for special pages)?
+ * @return bool
+ */
+ public function getLength() {
+ if( $this->mLength != -1 || $this->mArticleID == 0 )
+ return $this->mLength;
+ # Zero for special pages
+ if( $this->mArticleID <= 0 )
+ return -1;
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $len = $dbr->selectField( 'page', 'page_len',
+ array( 'page_id' => $this->mArticleID ),
+ __METHOD__ );
+ $this->mLength = intval($len);
+
+ return $this->mLength;
+ }
/**
* Is this a subpage?
}
$res = $db->select( array( 'page', $table ),
- array( 'page_namespace', 'page_title', 'page_id' ),
+ array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect' ),
array(
"{$prefix}_from=page_id",
"{$prefix}_namespace" => $this->getNamespace(),
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_redir );
$retVal[] = $titleObj;
}
}
$dbr = wfGetDB( DB_MASTER );
$uid = intval( $user->getId() );
list( $watchlist, $page ) = $dbr->tableNamesN( 'watchlist', 'page' );
- $sql = "SELECT wl_namespace, wl_title, page_id, page_is_redirect
+ $sql = "SELECT wl_namespace, wl_title, page_id, page_len, page_is_redirect,
+ page_namespace, page_title
FROM {$watchlist} LEFT JOIN {$page} ON ( wl_namespace = page_namespace
AND wl_title = page_title ) WHERE wl_user = {$uid}";
$res = $dbr->query( $sql, __METHOD__ );
if( $res && $dbr->numRows( $res ) > 0 ) {
$cache = LinkCache::singleton();
while( $row = $dbr->fetchObject( $res ) ) {
- $title = Title::makeTitleSafe( $row->wl_namespace, $row->wl_title );
+ $title = Title::newFromRow( $row );
if( $title instanceof Title ) {
// Update the link cache while we're at it
if( $row->page_id ) {
list( $page, $imagelinks ) = $db->tableNamesN( 'page', 'imagelinks' );
$encName = $db->addQuotes( $this->getName() );
- $sql = "SELECT page_namespace,page_title,page_id FROM $page,$imagelinks WHERE page_id=il_from AND il_to=$encName $options";
+ $sql = "SELECT page_namespace,page_title,page_id,page_len,page_is_redirect,
+ FROM $page,$imagelinks WHERE page_id=il_from AND il_to=$encName $options";
$res = $db->query( $sql, __METHOD__ );
$retVal = array();
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 );
+ if ( $titleObj = Title::newFromRow( $row ) ) {
+ $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect );
$retVal[] = $titleObj;
}
}