Honestly this whatlinkshere further link looks weird to me still, but it looks less...
[lhc/web/wiklou.git] / includes / SpecialWhatlinkshere.php
index 277e279..4d0c8ac 100644 (file)
@@ -105,25 +105,29 @@ class WhatLinksHerePage {
                }
 
                if ( $from ) {
-                       $offsetCond = "page_id >= $from";
-               } else {
-                       $offsetCond = false;
-               }
-               $options['ORDER BY'] = 'page_id';
+                       $from = (int)$from; // just in case
+                       $tlConds[] = "tl_from >= $from";
+                       $plConds[] = "pl_from >= $from";
+               } 
 
                // Read an extra row as an at-end check
                $queryLimit = $limit + 1;
+               
+               // enforce join order, sometimes namespace selector may 
+               // trigger filesorts which are far less efficient than scanning many entries
+               $options[] = 'STRAIGHT_JOIN';
+               
                $options['LIMIT'] = $queryLimit;
-               if ( $offsetCond ) {
-                       $tlConds[] = $offsetCond;
-                       $plConds[] = $offsetCond;
-               }
                $fields = array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' );
 
+               $options['ORDER BY'] = 'pl_from';
                $plRes = $dbr->select( array( 'pagelinks', 'page' ), $fields,
                        $plConds, $fname, $options );
+                       
+               $options['ORDER BY'] = 'tl_from';
                $tlRes = $dbr->select( array( 'templatelinks', 'page' ), $fields,
                        $tlConds, $fname, $options );
+               
                if ( !$dbr->numRows( $plRes ) && !$dbr->numRows( $tlRes ) ) {
                        if ( 0 == $level && !isset( $this->namespace ) ) {
                                // really no links to here
@@ -226,6 +230,12 @@ class WhatLinksHerePage {
                                $wgOut->addHTML( ' (' . implode( ', ', $props ) . ') ' );
                        }
 
+                       //add whatlinkshere link
+                       $whatlink = $this->skin->makeKnownLinkObj(
+                               SpecialPage::getTitleFor( 'Whatlinkshere', $nt->getPrefixedDBkey() ),
+                               wfMsgHtml( 'whatlinkshere-links' ) );
+                       $wgOut->addHTML(" ($whatlink)" );
+
                        if ( $row->page_is_redirect ) {
                                if ( $level < 2 ) {
                                        $this->showIndirectLinks( $level + 1, $nt, 500 );