Pass the user as an argument to 'isValidPassword' hook callbacks; see docs/hooks...
[lhc/web/wiklou.git] / includes / SpecialWhatlinkshere.php
index fecb180..572a805 100644 (file)
@@ -14,11 +14,17 @@ function wfSpecialWhatlinkshere($par = NULL) {
        $page->execute();
 }
 
+/**
+ * implements Special:Whatlinkshere
+ * @addtogroup SpecialPage
+ */
 class WhatLinksHerePage {
        var $request, $par;
-       var $limit, $from, $back, $target, $namespace;
+       var $limit, $from, $back, $target;
        var $selfTitle, $skin;
 
+       private $namespace;
+
        function WhatLinksHerePage( &$request, $par = null ) {
                global $wgUser;
                $this->request =& $request;
@@ -69,11 +75,12 @@ class WhatLinksHerePage {
        function showIndirectLinks( $level, $target, $limit, $from = 0, $back = 0 ) {
                global $wgOut;
                $fname = 'WhatLinksHerePage::showIndirectLinks';
-
                $dbr = wfGetDB( DB_READ );
+               $options = array();
 
-               if ( ( $ns = $this->request->getVal( 'namespace', null )) !== null && $ns !== '' ) {
-                       $options['namespace'] = intval( $ns );
+               $ns = $this->request->getIntOrNull( 'namespace' );
+               if ( isset( $ns ) ) {
+                       $options['namespace'] = $ns;
                        $this->setNamespace( $options['namespace'] );
                } else {
                        $options['namespace'] = '';
@@ -98,25 +105,29 @@ class WhatLinksHerePage {
                }
 
                if ( $from ) {
-                       $offsetCond = "page_id >= $from";
-                       $options = array( 'ORDER BY page_id' );
-               } else {
-                       $offsetCond = false;
-                       $options = array( 'ORDER BY page_id,is_template DESC' );
-               }
+                       $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
@@ -128,7 +139,7 @@ class WhatLinksHerePage {
                                $options['target'] = $this->target->getPrefixedText();
                                list( $options['limit'], $options['offset']) = wfCheckLimits();
                                $wgOut->addHTML( $this->whatlinkshereForm( $options ) );
-                               $wgOut->addWikiText( wfMsg( 'nolinkshere-ns', $this->target->getPrefixedText(), $this->namespace ) );
+                               $wgOut->addWikiText( wfMsg( 'nolinkshere-ns', $this->target->getPrefixedText() ) );
                        }
                        return;
                }
@@ -219,6 +230,14 @@ class WhatLinksHerePage {
                                $wgOut->addHTML( ' (' . implode( ', ', $props ) . ') ' );
                        }
 
+                       # Space for utilities links, with a what-links-here link provided
+                       $wlh = $this->skin->makeKnownLinkObj(
+                               SpecialPage::getTitleFor( 'Whatlinkshere' ),
+                               wfMsgHtml( 'whatlinkshere-links' ),
+                               'target=' . $nt->getPrefixedUrl()
+                       );
+                       $wgOut->addHtml( ' <span class="mw-whatlinkshere-tools">(' . $wlh . ')</span>' );                       
+                       
                        if ( $row->page_is_redirect ) {
                                if ( $level < 2 ) {
                                        $this->showIndirectLinks( $level + 1, $nt, 500 );
@@ -237,19 +256,24 @@ class WhatLinksHerePage {
                return $this->skin->makeKnownLinkObj( $this->selfTitle, $text, $query );
        }
 
-       function getPrevNext( $limit, $prevId, $nextId, $namespace ) {
+       function getPrevNext( $limit, $prevId, $nextId ) {
                global $wgLang;
                $fmtLimit = $wgLang->formatNum( $limit );
-               $prev = wfMsg( 'whatlinkshere-prev', $fmtLimit );
-               $next = wfMsg( 'whatlinkshere-next', $fmtLimit );
+               $prev = wfMsgExt( 'whatlinkshere-prev', array( 'parsemag', 'escape' ), $fmtLimit );
+               $next = wfMsgExt( 'whatlinkshere-next', array( 'parsemag', 'escape' ), $fmtLimit );
+
+               $nsText = '';
+               if( is_int($this->namespace) ) {
+                       $nsText = "&namespace={$this->namespace}";
+               }
 
                if ( 0 != $prevId ) {
-                       $prevLink = $this->makeSelfLink( $prev, "limit={$limit}&from={$this->back}&back={$fromId}&namespace={$namespace}" );
+                       $prevLink = $this->makeSelfLink( $prev, "limit={$limit}&from={$this->back}{$nsText}" );
                } else {
                        $prevLink = $prev;
                }
                if ( 0 != $nextId ) {
-                       $nextLink = $this->makeSelfLink( $next, "limit={$limit}&from={$nextId}&back={$prevId}&namespace={$namespace}" );
+                       $nextLink = $this->makeSelfLink( $next, "limit={$limit}&from={$nextId}&back={$prevId}{$nsText}" );
                } else {
                        $nextLink = $next;
                }
@@ -262,9 +286,10 @@ class WhatLinksHerePage {
                return wfMsg( 'viewprevnext', $prevLink, $nextLink, $nums );
        }
 
-       function numLink( $limit, $from ) {
+       function numLink( $limit, $from, $ns = null ) {
                global $wgLang;
                $query = "limit={$limit}&from={$from}";
+               if( is_int($this->namespace) ) { $query .= "&namespace={$this->namespace}";}
                $fmtLimit = $wgLang->formatNum( $limit );
                return $this->makeSelfLink( $fmtLimit, $query );
        }
@@ -292,10 +317,11 @@ class WhatLinksHerePage {
                return $f;
        }
 
-       function setNamespace( $ns ) {
+       /** Set the namespace we are filtering on */
+       private function setNamespace( $ns ) {
                $this->namespace = $ns;
        }
 
 }
 
-?>
+