Improvements for 30871:
authorAryeh Gregor <simetrical@users.mediawiki.org>
Tue, 12 Feb 2008 19:58:12 +0000 (19:58 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Tue, 12 Feb 2008 19:58:12 +0000 (19:58 +0000)
* 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
includes/Parser.php

index 30a5f18..cd9c31c 100644 (file)
@@ -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 );
                        }
index 31d0e65..41eabe4 100644 (file)
@@ -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";