* (bug 4624) Namespace selection for Special:Whatlinkshere
authorRaimond Spekking <raymond@users.mediawiki.org>
Thu, 22 Mar 2007 09:22:24 +0000 (09:22 +0000)
committerRaimond Spekking <raymond@users.mediawiki.org>
Thu, 22 Mar 2007 09:22:24 +0000 (09:22 +0000)
  Based on a patch of Suisui
Found another bug: scrolling backwards at Special:Whatlinkshere was broken since ?
'previous' shows always the first page in reversed order but not the real previous page.
Fixed now by changing backwards scrolling mechanism.

* (bug 4777) Separate prev/next messages for Special:Whatlinkshere

RELEASE-NOTES
includes/SpecialWhatlinkshere.php
languages/messages/MessagesDe.php
languages/messages/MessagesEn.php
maintenance/language/messages.inc

index 5512214..fce8e9f 100644 (file)
@@ -30,10 +30,9 @@ lighter making things easier to read.
 
 == Changes since 1.9 ==
 
-* (bug 5142) Fixed call of hook ArticleViewHeader
 * (bug 7292) Fix site statistics when moving pages in/out of content namespaces
 * (bug 6937) Introduce "statistics-footer" message, appended to Special:Statistics
-* (bug 8531) Correct local name of Lingála (patch by Raymond)
+* (bug 8531) Correct local name of Lingála
 * (bug 6638) List block flags in block log entries
 * New script maintenance/language/checkExtensioni18n.php used to check i18n
   progress in the extension repository.
@@ -284,6 +283,10 @@ lighter making things easier to read.
   Warning on upload of images with uppercase extension if image with lowercase
   extension exists
 * (bug 9363) Fix Postgres error on Recentchangeslinked
+* (bug 5142) Fixed call of hook ArticleViewHeader
+* (bug 4624) Namespace selection for Special:Whatlinkshere
+  Scrolling backwards at Special:Whatlinkshere fixed
+* (bug 4777) Separate prev/next messages for Special:Whatlinkshere
 
 == Languages updated ==
 
index c131c00..fecb180 100644 (file)
@@ -16,7 +16,7 @@ function wfSpecialWhatlinkshere($par = NULL) {
 
 class WhatLinksHerePage {
        var $request, $par;
-       var $limit, $from, $dir, $target;
+       var $limit, $from, $back, $target, $namespace;
        var $selfTitle, $skin;
 
        function WhatLinksHerePage( &$request, $par = null ) {
@@ -34,10 +34,7 @@ class WhatLinksHerePage {
                        $this->limit = 50;
                }
                $this->from = $this->request->getInt( 'from' );
-               $this->dir = $this->request->getText( 'dir', 'next' );
-               if ( $this->dir != 'prev' ) {
-                       $this->dir = 'next';
-               }
+               $this->back = $this->request->getInt( 'back' );
 
                $targetString = isset($this->par) ? $this->par : $this->request->getVal( 'target' );
 
@@ -58,7 +55,7 @@ class WhatLinksHerePage {
 
                $wgOut->addHTML( wfMsg( 'whatlinkshere-barrow' ) . ' '  .$this->skin->makeLinkObj($this->target, '', 'redirect=no' )."<br />\n");
 
-               $this->showIndirectLinks( 0, $this->target, $this->limit, $this->from, $this->dir );
+               $this->showIndirectLinks( 0, $this->target, $this->limit, $this->from, $this->back );
        }
 
        /**
@@ -66,20 +63,20 @@ class WhatLinksHerePage {
         * @param Title     $target     Target title
         * @param int       $limit      Number of entries to display
         * @param Title     $from       Display from this article ID
-        * @param string    $dir        'next' or 'prev', whether $fromTitle is the start or end of the list
+        * @param Title     $back       Display from this article ID at backwards scrolling
         * @private
         */
-       function showIndirectLinks( $level, $target, $limit, $from = 0, $dir = 'next' ) {
+       function showIndirectLinks( $level, $target, $limit, $from = 0, $back = 0 ) {
                global $wgOut;
                $fname = 'WhatLinksHerePage::showIndirectLinks';
 
                $dbr = wfGetDB( DB_READ );
 
-               // Some extra validation
-               $from = intval( $from );
-               if ( !$from && $dir == 'prev' ) {
-                       // Before start? No make sense
-                       $dir = 'next';
+               if ( ( $ns = $this->request->getVal( 'namespace', null )) !== null && $ns !== '' ) {
+                       $options['namespace'] = intval( $ns );
+                       $this->setNamespace( $options['namespace'] );
+               } else {
+                       $options['namespace'] = '';
                }
 
                // Make the query
@@ -95,14 +92,14 @@ class WhatLinksHerePage {
                        'tl_title' => $target->getDBkey(),
                );
 
+               if ( $this->namespace !== null ){
+                       $plConds['page_namespace'] = (int)$this->namespace;
+                       $tlConds['page_namespace'] = (int)$this->namespace;
+               }
+
                if ( $from ) {
-                       if ( 'prev' == $dir ) {
-                               $offsetCond = "page_id < $from";
-                               $options = array( 'ORDER BY page_id DESC' );
-                       } else {
-                               $offsetCond = "page_id >= $from";
-                               $options = array( 'ORDER BY page_id' );
-                       }
+                       $offsetCond = "page_id >= $from";
+                       $options = array( 'ORDER BY page_id' );
                } else {
                        $offsetCond = false;
                        $options = array( 'ORDER BY page_id,is_template DESC' );
@@ -120,14 +117,37 @@ class WhatLinksHerePage {
                        $plConds, $fname, $options );
                $tlRes = $dbr->select( array( 'templatelinks', 'page' ), $fields,
                        $tlConds, $fname, $options );
-
                if ( !$dbr->numRows( $plRes ) && !$dbr->numRows( $tlRes ) ) {
-                       if ( 0 == $level ) {
+                       if ( 0 == $level && !isset( $this->namespace ) ) {
+                               // really no links to here
                                $wgOut->addWikiText( wfMsg( 'nolinkshere', $this->target->getPrefixedText() ) );
+                       } elseif ( 0 == $level && isset( $this->namespace ) ) {
+                               // no links from requested namespace to here
+                               $options = array(); // reinitialize for a further namespace search
+                               $options['namespace'] = $this->namespace;
+                               $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 ) );
                        }
                        return;
                }
 
+               $options = array();
+               list( $options['limit'], $options['offset']) = wfCheckLimits();
+               if ( ( $ns = $this->request->getVal( 'namespace', null ) ) !== null && $ns !== '' && ctype_digit($ns) ) {
+                       $options['namespace'] = intval( $ns );
+                       $this->setNamespace( $options['namespace'] );
+               } else {
+                       $options['namespace'] = '';
+                       $this->setNamespace( null );
+               }
+               $options['offset'] = $this->request->getVal( 'offset' );
+               /* Offset must be an integral. */
+               if ( !strlen( $options['offset'] ) || !preg_match( '/^[0-9]+$/', $options['offset'] ) )
+               $options['offset'] = '';
+               $options['target'] = $this->target->getPrefixedDBkey();
+
                // Read the rows into an array and remove duplicates
                // templatelinks comes second so that the templatelinks row overwrites the
                // pagelinks row, so we get (inclusion) rather than nothing
@@ -149,46 +169,27 @@ class WhatLinksHerePage {
                $numRows = count( $rows );
 
                // Work out the start and end IDs, for prev/next links
-               if ( $dir == 'prev' ) {
-                       // Descending order
-                       if ( $numRows > $limit ) {
-                               // More rows available before these ones
-                               // Get the ID from the next row past the end of the displayed set
-                               $prevId = $rows[$limit]->page_id;
-                               // Remove undisplayed rows
-                               $rows = array_slice( $rows, 0, $limit );
-                       } else {
-                               // No more rows available before
-                               $prevId = 0;
-                       }
-                       // Assume that the ID specified in $from exists, so there must be another page
-                       $nextId = $from;
-
-                       // Reverse order ready for display
-                       $rows = array_reverse( $rows );
+               if ( $numRows > $limit ) {
+                       // More rows available after these ones
+                       // Get the ID from the last row in the result set
+                       $nextId = $rows[$limit]->page_id;
+                       // Remove undisplayed rows
+                       $rows = array_slice( $rows, 0, $limit );
                } else {
-                       // Ascending
-                       if ( $numRows > $limit ) {
-                               // More rows available after these ones
-                               // Get the ID from the last row in the result set
-                               $nextId = $rows[$limit]->page_id;
-                               // Remove undisplayed rows
-                               $rows = array_slice( $rows, 0, $limit );
-                       } else {
-                               // No more rows after
-                               $nextId = false;
-                       }
-                       $prevId = $from;
+                       // No more rows after
+                       $nextId = false;
                }
+               $prevId = $from;
 
-               if ( 0 == $level ) {
+               if ( $level == 0 ) {
+                       $wgOut->addHTML( $this->whatlinkshereForm( $options ) );
                        $wgOut->addWikiText( wfMsg( 'linkshere', $this->target->getPrefixedText() ) );
                }
                $isredir = wfMsg( 'isredirect' );
                $istemplate = wfMsg( 'istemplate' );
 
                if( $level == 0 ) {
-                       $prevnext = $this->getPrevNext( $limit, $prevId, $nextId );
+                       $prevnext = $this->getPrevNext( $limit, $prevId, $nextId, $options['namespace'] );
                        $wgOut->addHTML( $prevnext );
                }
 
@@ -236,19 +237,19 @@ class WhatLinksHerePage {
                return $this->skin->makeKnownLinkObj( $this->selfTitle, $text, $query );
        }
 
-       function getPrevNext( $limit, $prevId, $nextId ) {
+       function getPrevNext( $limit, $prevId, $nextId, $namespace ) {
                global $wgLang;
                $fmtLimit = $wgLang->formatNum( $limit );
-               $prev = wfMsg( 'prevn', $fmtLimit );
-               $next = wfMsg( 'nextn', $fmtLimit );
+               $prev = wfMsg( 'whatlinkshere-prev', $fmtLimit );
+               $next = wfMsg( 'whatlinkshere-next', $fmtLimit );
 
                if ( 0 != $prevId ) {
-                       $prevLink = $this->makeSelfLink( $prev, "limit={$limit}&from={$prevId}&dir=prev" );
+                       $prevLink = $this->makeSelfLink( $prev, "limit={$limit}&from={$this->back}&back={$fromId}&namespace={$namespace}" );
                } else {
                        $prevLink = $prev;
                }
                if ( 0 != $nextId ) {
-                       $nextLink = $this->makeSelfLink( $next, "limit={$limit}&from={$nextId}" );
+                       $nextLink = $this->makeSelfLink( $next, "limit={$limit}&from={$nextId}&back={$prevId}&namespace={$namespace}" );
                } else {
                        $nextLink = $next;
                }
@@ -267,6 +268,34 @@ class WhatLinksHerePage {
                $fmtLimit = $wgLang->formatNum( $limit );
                return $this->makeSelfLink( $fmtLimit, $query );
        }
+
+       function whatlinkshereForm( $options ) {
+               global $wgScript, $wgTitle;
+
+               $options['title'] = $wgTitle->getPrefixedText();
+
+               $f = Xml::openElement( 'form', array( 'method' => 'get', 'action' => "$wgScript" ) ) .
+                       '<fieldset>' .
+                       Xml::element( 'legend', array(), wfMsg( 'whatlinkshere' ) );
+
+               foreach ( $options as $name => $value ) {
+                       if( $name === 'namespace') continue;
+                       $f .= "\t" . Xml::hidden( $name, $value ). "\n";
+               }
+
+               $f .= Xml::label( wfMsg( 'namespace' ), 'namespace' ) . ' ' .
+                       Xml::namespaceSelector( $options['namespace'], '' ) .
+                       Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
+                       '</fieldset>' .
+                       Xml::closeElement( 'form' ) . "\n";
+
+               return $f;
+       }
+
+       function setNamespace( $ns ) {
+               $this->namespace = $ns;
+       }
+
 }
 
 ?>
index e0a7e03..26b1669 100644 (file)
@@ -1479,10 +1479,13 @@ Im [[Special:Log/delete|Lösch-Logbuch]] finden Sie eine Übersicht der kürzlic
 'notargettitle'         => 'Keine Seite angegeben',
 'notargettext'          => 'Sie haben nicht angegeben, auf welche Seite diese Funktion angewendet werden soll.',
 'linklistsub'           => '(Liste der Verweise)',
-'linkshere'             => "Die folgenden Seiten verweisen auf '''[[:$1]]''':",
-'nolinkshere'           => "Keine Seite verweist auf '''[[:$1]]'''.",
+'linkshere'             => "Die folgenden Seiten verweisen auf '''„[[:$1]]“''':",
+'nolinkshere'           => "Keine Seite verweist auf '''„[[:$1]]“'''.",
+'nolinkshere-ns'        => "Keine Seite verweist auf '''„[[:$1]]“''' im Namensraum „{{ns:$2}}“.",
 'isredirect'            => 'Weiterleitungsseite',
 'istemplate'            => 'Vorlageneinbindung',
+'whatlinkshere-prev'    => 'vorherige $1',
+'whatlinkshere-next'    => 'nächste $1',
 
 # Block/unblock
 'blockip'                     => 'IP-Adresse/Benutzer sperren',
index dd07425..be3b103 100644 (file)
@@ -1897,17 +1897,20 @@ Consult the [[Special:Log/delete|deletion log]] for a record of recent deletions
 
 # What links here
 #
-'whatlinkshere'        => 'What links here',
+'whatlinkshere'         => 'What links here',
 'whatlinkshere-summary'        => '',
-'whatlinkshere-barrow' => '&lt;',
-'notargettitle' => 'No target',
-'notargettext' => 'You have not specified a target page or user
+'whatlinkshere-barrow'  => '&lt;',
+'notargettitle'         => 'No target',
+'notargettext'          => 'You have not specified a target page or user
 to perform this function on.',
-'linklistsub'  => '(List of links)',
-'linkshere' => "The following pages link to '''[[:$1]]''':",
-'nolinkshere' => "No pages link to '''[[:$1]]'''.",
-'isredirect'   => 'redirect page',
-'istemplate'   => 'inclusion',
+'linklistsub'           => '(List of links)',
+'linkshere'             => "The following pages link to '''[[:$1]]''':",
+'nolinkshere'           => "No pages link to '''[[:$1]]'''.",
+'nolinkshere-ns'        => "No pages link to '''[[:$1]]''' at namespace {{ns:$2}}.",
+'isredirect'            => 'redirect page',
+'istemplate'            => 'inclusion',
+'whatlinkshere-prev'    => 'previous $1',
+'whatlinkshere-next'    => 'next $1',
 
 # Block/unblock IP
 #
index b7ef9b7..3e554d9 100644 (file)
@@ -1233,8 +1233,11 @@ $wgMessageStructure = array(
                'linklistsub',
                'linkshere',
                'nolinkshere',
+               'nolinkshere-ns',
                'isredirect',
                'istemplate',
+               'whatlinkshere-prev',
+               'whatlinkshere-next',
        ),
        'block' => array(
                'blockip',