revert r106095, fix apparently not this simple
[lhc/web/wiklou.git] / includes / specials / SpecialWhatlinkshere.php
index 190e95d..e55374e 100644 (file)
@@ -47,15 +47,16 @@ class SpecialWhatLinksHere extends SpecialPage {
        }
 
        function execute( $par ) {
+               global $wgQueryPageDefaultLimit;
                $out = $this->getOutput();
-               
+
                $this->setHeaders();
 
                $opts = new FormOptions();
 
                $opts->add( 'target', '' );
                $opts->add( 'namespace', '', FormOptions::INTNULL );
-               $opts->add( 'limit', 50 );
+               $opts->add( 'limit', $wgQueryPageDefaultLimit );
                $opts->add( 'from', 0 );
                $opts->add( 'back', 0 );
                $opts->add( 'hideredirs', false );
@@ -82,11 +83,10 @@ class SpecialWhatLinksHere extends SpecialPage {
 
                $this->getSkin()->setRelevantTitle( $this->target );
 
-
                $this->selfTitle = $this->getTitle( $this->target->getPrefixedDBkey() );
 
-               $out->setPageTitle( wfMsg( 'whatlinkshere-title', $this->target->getPrefixedText() ) );
-               $out->setSubtitle( wfMsg( 'whatlinkshere-backlink', Linker::link( $this->target, $this->target->getPrefixedText(), array(), array( 'redirect' => 'no'  ) ) ) );
+               $out->setPageTitle( $this->msg( 'whatlinkshere-title', $this->target->getPrefixedText() ) );
+               $out->addBacklinkSubtitle( $this->target );
 
                $this->showIndirectLinks( 0, $this->target, $opts->getValue( 'limit' ),
                        $opts->getValue( 'from' ), $opts->getValue( 'back' ) );
@@ -119,9 +119,9 @@ class SpecialWhatLinksHere extends SpecialPage {
                        'pl_title' => $target->getDBkey(),
                );
                if( $hideredirs ) {
-                       $plConds['page_is_redirect'] = 0;
+                       $plConds['rd_from'] = null;
                } elseif( $hidelinks ) {
-                       $plConds['page_is_redirect'] = 1;
+                       $plConds[] = 'rd_from is NOT NULL';
                }
 
                $tlConds = array(
@@ -156,24 +156,34 @@ class SpecialWhatLinksHere extends SpecialPage {
                $options[] = 'STRAIGHT_JOIN';
 
                $options['LIMIT'] = $queryLimit;
-               $fields = array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' );
+               $fields = array( 'page_id', 'page_namespace', 'page_title', 'rd_from' );
+
+               $joinConds = array( 'redirect' => array( 'LEFT JOIN', array(
+                       'rd_from = page_id',
+                       'rd_namespace' => $target->getNamespace(),
+                       'rd_title' => $target->getDBkey(),
+                       '(rd_interwiki is NULL) or (rd_interwiki = \'\')'
+               )));
 
                if( $fetchlinks ) {
                        $options['ORDER BY'] = 'pl_from';
-                       $plRes = $dbr->select( array( 'pagelinks', 'page' ), $fields,
-                               $plConds, __METHOD__, $options );
+                       $plRes = $dbr->select( array( 'pagelinks', 'page', 'redirect' ), $fields,
+                               $plConds, __METHOD__, $options,
+                               $joinConds);
                }
 
                if( !$hidetrans ) {
                        $options['ORDER BY'] = 'tl_from';
-                       $tlRes = $dbr->select( array( 'templatelinks', 'page' ), $fields,
-                               $tlConds, __METHOD__, $options );
+                       $tlRes = $dbr->select( array( 'templatelinks', 'page', 'redirect' ), $fields,
+                               $tlConds, __METHOD__, $options,
+                               $joinConds);
                }
 
                if( !$hideimages ) {
                        $options['ORDER BY'] = 'il_from';
-                       $ilRes = $dbr->select( array( 'imagelinks', 'page' ), $fields,
-                               $ilConds, __METHOD__, $options );
+                       $ilRes = $dbr->select( array( 'imagelinks', 'page', 'redirect' ), $fields,
+                               $ilConds, __METHOD__, $options,
+                               $joinConds);
                }
 
                if( ( !$fetchlinks || !$dbr->numRows($plRes) ) && ( $hidetrans || !$dbr->numRows($tlRes) ) && ( $hideimages || !$dbr->numRows($ilRes) ) ) {
@@ -247,7 +257,7 @@ class SpecialWhatLinksHere extends SpecialPage {
                foreach ( $rows as $row ) {
                        $nt = Title::makeTitle( $row->page_namespace, $row->page_title );
 
-                       if ( $row->page_is_redirect && $level < 2 ) {
+                       if ( $row->rd_from && $level < 2 ) {
                                $out->addHTML( $this->listItem( $row, $nt, true ) );
                                $this->showIndirectLinks( $level + 1, $nt, $wgMaxRedirectLinksRetrieved );
                                $out->addHTML( Xml::closeElement( 'li' ) );
@@ -268,6 +278,8 @@ class SpecialWhatLinksHere extends SpecialPage {
        }
 
        protected function listItem( $row, $nt, $notClose = false ) {
+               $dirmark = $this->getLanguage()->getDirMark();
+
                # local message cache
                static $msgcache = null;
                if ( $msgcache === null ) {
@@ -279,7 +291,7 @@ class SpecialWhatLinksHere extends SpecialPage {
                        }
                }
 
-               if( $row->page_is_redirect ) {
+               if( $row->rd_from ) {
                        $query = array( 'redirect' => 'no' );
                } else {
                        $query = array();
@@ -295,7 +307,7 @@ class SpecialWhatLinksHere extends SpecialPage {
                // Display properties (redirect or template)
                $propsText = '';
                $props = array();
-               if ( $row->page_is_redirect )
+               if ( $row->rd_from )
                        $props[] = $msgcache['isredirect'];
                if ( $row->is_template )
                        $props[] = $msgcache['istemplate'];
@@ -311,8 +323,8 @@ class SpecialWhatLinksHere extends SpecialPage {
                $wlh = Xml::wrapClass( "($wlhLink)", 'mw-whatlinkshere-tools' );
 
                return $notClose ?
-                       Xml::openElement( 'li' ) . "$link $propsText $wlh\n" :
-                       Xml::tags( 'li', null, "$link $propsText $wlh" ) . "\n";
+                       Xml::openElement( 'li' ) . "$link $propsText $dirmark $wlh\n" :
+                       Xml::tags( 'li', null, "$link $propsText $dirmark $wlh" ) . "\n";
        }
 
        protected function listEnd() {
@@ -342,11 +354,9 @@ class SpecialWhatLinksHere extends SpecialPage {
        }
 
        function getPrevNext( $prevId, $nextId ) {
-               global $wgLang;
                $currentLimit = $this->opts->getValue( 'limit' );
-               $fmtLimit = $wgLang->formatNum( $currentLimit );
-               $prev = wfMsgExt( 'whatlinkshere-prev', array( 'parsemag', 'escape' ), $fmtLimit );
-               $next = wfMsgExt( 'whatlinkshere-next', array( 'parsemag', 'escape' ), $fmtLimit );
+               $prev = wfMessage( 'whatlinkshere-prev' )->numParams( $currentLimit )->escaped();
+               $next = wfMessage( 'whatlinkshere-next' )->numParams( $currentLimit )->escaped();
 
                $changed = $this->opts->getChangedValues();
                unset($changed['target']); // Already in the request title
@@ -361,13 +371,14 @@ class SpecialWhatLinksHere extends SpecialPage {
                }
 
                $limitLinks = array();
+               $lang = $this->getLanguage();
                foreach ( $this->limits as $limit ) {
-                       $prettyLimit = $wgLang->formatNum( $limit );
+                       $prettyLimit = htmlspecialchars( $lang->formatNum( $limit ) );
                        $overrides = array( 'limit' => $limit );
                        $limitLinks[] = $this->makeSelfLink( $prettyLimit, array_merge( $changed, $overrides ) );
                }
 
-               $nums = $wgLang->pipeList( $limitLinks );
+               $nums = $lang->pipeList( $limitLinks );
 
                return wfMsgHtml( 'viewprevnext', $prev, $next, $nums );
        }
@@ -421,7 +432,6 @@ class SpecialWhatLinksHere extends SpecialPage {
         * @return string HTML fieldset and filter panel with the show/hide links
         */
        function getFilterPanel() {
-               global $wgLang;
                $show = wfMsgHtml( 'show' );
                $hide = wfMsgHtml( 'hide' );
 
@@ -441,6 +451,6 @@ class SpecialWhatLinksHere extends SpecialPage {
                        $overrides = array( $type => !$chosen );
                        $links[] =  wfMsgHtml( "whatlinkshere-{$type}", $this->makeSelfLink( $msg, array_merge( $changed, $overrides ) ) );
                }
-               return Xml::fieldset( wfMsg( 'whatlinkshere-filters' ), $wgLang->pipeList( $links ) );
+               return Xml::fieldset( wfMsg( 'whatlinkshere-filters' ), $this->getLanguage()->pipeList( $links ) );
        }
 }