From 8bf5159e4d3375093cb95f36c26a8d6bb9a25081 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Tue, 12 Feb 2008 19:58:12 +0000 Subject: [PATCH] Improvements for 30871: * Use !empty() to avoid notices if $s->page_is_redirect isn't set. * Enable unconditionally. This causes some extra queries, but only if makeLinkObj() is being used, which for typical article links it's not. (The previous version didn't add page_is_redirect to the parameter even when it would have caused no extra queries, in two places in Parser.php.) If the extra makeLinkObj() queries are a problem, they can be combined with the existence check query. Or failing that, it can just be reverted for that method only, which will still allow the feature to work with standard in-article links. --- includes/Linker.php | 22 +++++++++++----------- includes/Parser.php | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 30a5f18f89..cd9c31c70a 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -77,7 +77,7 @@ class Linker { * * @param mixed $s * @param integer $threshold user defined threshold - * @return string $colour CSS class + * @return string CSS class */ function getLinkColour( $s, $threshold ) { if( $s == false ) { @@ -85,7 +85,7 @@ class Linker { } $colour = ''; - if ( $s->page_is_redirect ) { + if ( !empty( $s->page_is_redirect ) ) { # Page is a redirect $colour = 'mw-redirect'; } elseif ( $threshold > 0 && $s->page_len < $threshold && Namespace::isContent( $s->page_namespace ) ) { @@ -233,7 +233,7 @@ class Linker { } else { wfProfileIn( __METHOD__.'-immediate' ); - # Handles links to special pages wich do not exist in the database: + # Handles links to special pages which do not exist in the database: if( $nt->getNamespace() == NS_SPECIAL ) { if( SpecialPage::exists( $nt->getDBkey() ) ) { $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix ); @@ -252,15 +252,15 @@ class Linker { } else { $colour = ''; if ( $nt->isContentPage() ) { + # FIXME: This is stupid, we should combine this query with + # the Title::getArticleID() query above. $threshold = $wgUser->getOption('stubthreshold'); - if ( $threshold > 0 ) { - $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 ); - } + $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 ); } $retVal = $this->makeColouredLinkObj( $nt, $colour, $text, $query, $trail, $prefix ); } diff --git a/includes/Parser.php b/includes/Parser.php index 31d0e65b30..41eabe4f54 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -4015,9 +4015,9 @@ class Parser # Not in the link cache, add it to the query if ( !isset( $current ) ) { $current = $ns; - $query = "SELECT page_id, page_namespace, page_title"; + $query = "SELECT page_id, page_namespace, page_title, page_is_redirect"; if ( $threshold > 0 ) { - $query .= ', page_len, page_is_redirect'; + $query .= ', page_len'; } $query .= " FROM $page WHERE (page_namespace=$ns AND page_title IN("; } elseif ( $current != $ns ) { @@ -4106,9 +4106,9 @@ class Parser // construct query $titleClause = $linkBatch->constructSet('page', $dbr); - $variantQuery = "SELECT page_id, page_namespace, page_title"; + $variantQuery = "SELECT page_id, page_namespace, page_title, page_is_redirect"; if ( $threshold > 0 ) { - $variantQuery .= ', page_len, page_is_redirect'; + $variantQuery .= ', page_len'; } $variantQuery .= " FROM $page WHERE $titleClause"; -- 2.20.1