(bug 30963) Option to hide redirects in Allpages and Prefixindex
authormrbluesky <mrbluesky@wikipedia.be>
Wed, 28 Mar 2012 20:28:31 +0000 (22:28 +0200)
committermrbluesky <mrbluesky@wikipedia.be>
Wed, 28 Mar 2012 20:28:31 +0000 (22:28 +0200)
Add an option to SpecialAllpages and SpecialPrefixindex to hide
redirects.

Change-Id: I335c54f31ef841dd0c2e51a2ec8b17f234308b0e

RELEASE-NOTES-1.20
includes/specials/SpecialAllpages.php
includes/specials/SpecialPrefixindex.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php

index d300541..6fa5ff4 100644 (file)
@@ -24,6 +24,7 @@ production.
 * (bug 23795) Add parser itself to ParserMakeImageParams hook.
 * Introduce a cryptographic random number generator source api for use when
   generating various tokens.
+* (bug 30963) Option on Special:Prefixindex and Special:Allpages to not show redirects.
 
 === Bug fixes in 1.20 ===
 * (bug 30245) Use the correct way to construct a log page title.
index 619f23d..bf30dc8 100644 (file)
@@ -30,24 +30,37 @@ class SpecialAllpages extends IncludableSpecialPage {
 
        /**
         * Maximum number of pages to show on single subpage.
+        *
+        * @var int $maxPerPage
         */
        protected $maxPerPage = 345;
 
        /**
         * Maximum number of pages to show on single index subpage.
+        *
+        * @var int $maxLineCount
         */
        protected $maxLineCount = 100;
 
        /**
         * Maximum number of chars to show for an entry.
+        *
+        * @var int $maxPageLength
         */
        protected $maxPageLength = 70;
 
        /**
         * Determines, which message describes the input field 'nsfrom'.
+        *
+        * @var string $nsfromMsg
         */
        protected $nsfromMsg = 'allpagesfrom';
 
+       /**
+        * Constructor
+        *
+        * @param $name string: name of the special page, as seen in links and URLs (default: 'Allpages')
+        */
        function __construct( $name = 'Allpages' ){
                parent::__construct( $name );
        }
@@ -70,6 +83,7 @@ class SpecialAllpages extends IncludableSpecialPage {
                $from = $request->getVal( 'from', null );
                $to = $request->getVal( 'to', null );
                $namespace = $request->getInt( 'namespace' );
+               $hideredirects = $request->getBool( 'hideredirects', false );
 
                $namespaces = $wgContLang->getNamespaces();
 
@@ -81,11 +95,11 @@ class SpecialAllpages extends IncludableSpecialPage {
                $out->addModuleStyles( 'mediawiki.special' );
 
                if( $par !== null ) {
-                       $this->showChunk( $namespace, $par, $to );
+                       $this->showChunk( $namespace, $par, $to, $hideredirects );
                } elseif( $from !== null && $to === null ) {
-                       $this->showChunk( $namespace, $from, $to );
+                       $this->showChunk( $namespace, $from, $to, $hideredirects );
                } else {
-                       $this->showToplevel( $namespace, $from, $to );
+                       $this->showToplevel( $namespace, $from, $to, $hideredirects );
                }
        }
 
@@ -95,9 +109,10 @@ class SpecialAllpages extends IncludableSpecialPage {
         * @param $namespace Integer: a namespace constant (default NS_MAIN).
         * @param $from String: dbKey we are starting listing at.
         * @param $to String: dbKey we are ending listing at.
+        * @param $hideredirects Bool: dont show redirects  (default FALSE)
         * @return string
         */
-       function namespaceForm( $namespace = NS_MAIN, $from = '', $to = '' ) {
+       function namespaceForm( $namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false ) {
                global $wgScript;
                $t = $this->getTitle();
 
@@ -132,6 +147,12 @@ class SpecialAllpages extends IncludableSpecialPage {
                                array( 'selected' => $namespace ),
                                array( 'name' => 'namespace', 'id' => 'namespace' )
                        ) . ' ' .
+                       Xml::checkLabel(
+                               wfMsg( 'allpages-hide-redirects' ),
+                               'hideredirects',
+                               'hideredirects',
+                               $hideredirects
+                       ) . ' ' .
                        Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) .
                        "       </td>
 </tr>";
@@ -146,8 +167,9 @@ class SpecialAllpages extends IncludableSpecialPage {
         * @param $namespace Integer (default NS_MAIN)
         * @param $from String: list all pages from this name
         * @param $to String: list all pages to this name
+        * @param $hideredirects Bool: dont show redirects (default FALSE)
         */
-       function showToplevel( $namespace = NS_MAIN, $from = '', $to = '' ) {
+       function showToplevel( $namespace = NS_MAIN, $from = '', $to = '', $hideredirects = false ) {
                $output = $this->getOutput();
 
                # TODO: Either make this *much* faster or cache the title index points
@@ -157,6 +179,10 @@ class SpecialAllpages extends IncludableSpecialPage {
                $out = "";
                $where = array( 'page_namespace' => $namespace );
 
+               if ( $hideredirects ) {
+                       $where[ 'page_is_redirect' ] = 0;
+               }
+
                $from = Title::makeTitleSafe( $namespace, $from );
                $to = Title::makeTitleSafe( $namespace, $to );
                $from = ( $from && $from->isLocal() ) ? $from->getDBkey() : null;
@@ -225,9 +251,9 @@ class SpecialAllpages extends IncludableSpecialPage {
                // Instead, display the first section directly.
                if( count( $lines ) <= 2 ) {
                        if( !empty($lines) ) {
-                               $this->showChunk( $namespace, $from, $to );
+                               $this->showChunk( $namespace, $from, $to, $hideredirects );
                        } else {
-                               $output->addHTML( $this->namespaceForm( $namespace, $from, $to ) );
+                               $output->addHTML( $this->namespaceForm( $namespace, $from, $to, $hideredirects ) );
                        }
                        return;
                }
@@ -237,10 +263,10 @@ class SpecialAllpages extends IncludableSpecialPage {
                while( count ( $lines ) > 0 ) {
                        $inpoint = array_shift( $lines );
                        $outpoint = array_shift( $lines );
-                       $out .= $this->showline( $inpoint, $outpoint, $namespace );
+                       $out .= $this->showline( $inpoint, $outpoint, $namespace, $hideredirects );
                }
                $out .= Xml::closeElement( 'table' );
-               $nsForm = $this->namespaceForm( $namespace, $from, $to );
+               $nsForm = $this->namespaceForm( $namespace, $from, $to, $hideredirects );
 
                # Is there more?
                if( $this->including() ) {
@@ -271,9 +297,10 @@ class SpecialAllpages extends IncludableSpecialPage {
         * @param $inpoint String: lower limit of pagenames
         * @param $outpoint String: upper limit of pagenames
         * @param $namespace Integer (Default NS_MAIN)
+        * @param $hideredirects Bool: dont show redirects (default FALSE)
         * @return string
         */
-       function showline( $inpoint, $outpoint, $namespace = NS_MAIN ) {
+       function showline( $inpoint, $outpoint, $namespace = NS_MAIN, $hideredirects ) {
                global $wgContLang;
                $inpointf = htmlspecialchars( str_replace( '_', ' ', $inpoint ) );
                $outpointf = htmlspecialchars( str_replace( '_', ' ', $outpoint ) );
@@ -282,8 +309,14 @@ class SpecialAllpages extends IncludableSpecialPage {
                $outpointf = $wgContLang->truncate( $outpointf, $this->maxPageLength );
 
                $queryparams = $namespace ? "namespace=$namespace&" : '';
+
+               $queryhideredirects = array();
+               if ($hideredirects) {
+                       $queryhideredirects[ 'hideredirects' ] = 1;
+               }
+
                $special = $this->getTitle();
-               $link = htmlspecialchars( $special->getLocalUrl( $queryparams . 'from=' . urlencode($inpoint) . '&to=' . urlencode($outpoint) ) );
+               $link = htmlspecialchars( $special->getLocalUrl( $queryparams . 'from=' . urlencode($inpoint) . '&to=' . urlencode($outpoint), $queryhideredirects ) );
 
                $out = $this->msg( 'alphaindexline' )->rawParams(
                        "<a href=\"$link\">$inpointf</a></td><td>",
@@ -296,8 +329,9 @@ class SpecialAllpages extends IncludableSpecialPage {
         * @param $namespace Integer (Default NS_MAIN)
         * @param $from String: list all pages from this name (default FALSE)
         * @param $to String: list all pages to this name (default FALSE)
+        * @param $hideredirects Bool: dont show redirects (default FALSE)
         */
-       function showChunk( $namespace = NS_MAIN, $from = false, $to = false ) {
+       function showChunk( $namespace = NS_MAIN, $from = false, $to = false, $hideredirects = false ) {
                global $wgContLang;
                $output = $this->getOutput();
 
@@ -321,6 +355,11 @@ class SpecialAllpages extends IncludableSpecialPage {
                                'page_namespace' => $namespace,
                                'page_title >= ' . $dbr->addQuotes( $fromKey )
                        );
+
+                       if ( $hideredirects ) {
+                               $conds[ 'page_is_redirect' ] = 0;
+                       }
+
                        if( $toKey !== "" ) {
                                $conds[] = 'page_title <= ' . $dbr->addQuotes( $toKey );
                        }
@@ -408,7 +447,7 @@ class SpecialAllpages extends IncludableSpecialPage {
 
                        $self = $this->getTitle();
 
-                       $nsForm = $this->namespaceForm( $namespace, $from, $to );
+                       $nsForm = $this->namespaceForm( $namespace, $from, $to, $hideredirects );
                        $out2 = Xml::openElement( 'table', array( 'class' => 'mw-allpages-table-form' ) ).
                                                '<tr>
                                                        <td>' .
@@ -424,6 +463,9 @@ class SpecialAllpages extends IncludableSpecialPage {
                                if( $namespace )
                                        $query['namespace'] = $namespace;
 
+                               if( $hideredirects )
+                                       $query['hideredirects'] = $hideredirects;
+
                                $prevLink = Linker::linkKnown(
                                        $self,
                                        $this->msg( 'prevpage', $pt )->escaped(),
@@ -441,6 +483,9 @@ class SpecialAllpages extends IncludableSpecialPage {
                                if( $namespace )
                                        $query['namespace'] = $namespace;
 
+                               if( $hideredirects )
+                                       $query['hideredirects'] = $hideredirects;
+
                                $nextLink = Linker::linkKnown(
                                        $self,
                                        $this->msg( 'nextpage', $t->getText() )->escaped(),
index 3202c00..fca1748 100644 (file)
@@ -52,6 +52,7 @@ class SpecialPrefixindex extends SpecialAllpages {
                $prefix = $request->getVal( 'prefix', '' );
                $ns = $request->getIntOrNull( 'namespace' );
                $namespace = (int)$ns; // if no namespace given, use 0 (NS_MAIN).
+               $hideredirects = $request->getBool( 'hideredirects', false );
 
                $namespaces = $wgContLang->getNamespaces();
                $out->setPageTitle(
@@ -73,19 +74,20 @@ class SpecialPrefixindex extends SpecialAllpages {
 
                // Bug 27864: if transcluded, show all pages instead of the form.
                if ( $this->including() || $showme != '' || $ns !== null ) {
-                       $this->showPrefixChunk( $namespace, $showme, $from );
+                       $this->showPrefixChunk( $namespace, $showme, $from, $hideredirects );
                } else {
-                       $out->addHTML( $this->namespacePrefixForm( $namespace, null ) );
+                       $out->addHTML( $this->namespacePrefixForm( $namespace, null, $hideredirects ) );
                }
        }
 
        /**
-       * HTML for the top form
-       * @param $namespace Integer: a namespace constant (default NS_MAIN).
-       * @param $from String: dbKey we are starting listing at.
+        * HTML for the top form
+        * @param $namespace Integer: a namespace constant (default NS_MAIN).
+        * @param $from String: dbKey we are starting listing at.
+        * @param $hideredirects Bool: hide redirects (default FALSE)
         * @return string
         */
-       function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
+       function namespacePrefixForm( $namespace = NS_MAIN, $from = '', $hideredirects = false ) {
                global $wgScript;
 
                $out  = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
@@ -107,16 +109,22 @@ class SpecialPrefixindex extends SpecialAllpages {
                                        Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
                                "</td>
                                <td class='mw-input'>" .
-                                       Html::namespaceSelector( array(
+                               Html::namespaceSelector( array(
                                                'selected' => $namespace,
                                        ), array(
                                                'name'  => 'namespace',
                                                'id'    => 'namespace',
                                                'class' => 'namespaceselector',
-                                       ) ) .
-                                       Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
+                               ) ) .
+                               Xml::checkLabel(
+                                       wfMsg( 'allpages-hide-redirects' ),
+                                       'hideredirects',
+                                       'hideredirects',
+                                       $hideredirects
+                               ) . ' ' .
+                               Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
                                "</td>
-                               </tr>";
+                       </tr>";
                $out .= Xml::closeElement( 'table' );
                $out .= Xml::closeElement( 'fieldset' );
                $out .= Xml::closeElement( 'form' );
@@ -128,8 +136,9 @@ class SpecialPrefixindex extends SpecialAllpages {
         * @param $namespace Integer, default NS_MAIN
         * @param $prefix String
         * @param $from String: list all pages from this name (default FALSE)
+        * @param $hideredirects Bool: hide redirects (default FALSE)
         */
-       function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null ) {
+       function showPrefixChunk( $namespace = NS_MAIN, $prefix, $from = null, $hideredirects = false ) {
                global $wgContLang;
 
                if ( $from === null ) {
@@ -154,13 +163,19 @@ class SpecialPrefixindex extends SpecialAllpages {
 
                        $dbr = wfGetDB( DB_SLAVE );
 
+                       $conds = array(
+                               'page_namespace' => $namespace,
+                               'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
+                               'page_title >= ' . $dbr->addQuotes( $fromKey ),
+                       );
+
+                       if ( $hideredirects ) {
+                               $conds['page_is_redirect'] = 0;
+                       }
+
                        $res = $dbr->select( 'page',
                                array( 'page_namespace', 'page_title', 'page_is_redirect' ),
-                               array(
-                                       'page_namespace' => $namespace,
-                                       'page_title' . $dbr->buildLike( $prefixKey, $dbr->anyString() ),
-                                       'page_title >= ' . $dbr->addQuotes( $fromKey ),
-                               ),
+                               $conds,
                                __METHOD__,
                                array(
                                        'ORDER BY'  => 'page_title',
@@ -209,7 +224,7 @@ class SpecialPrefixindex extends SpecialAllpages {
                if ( $this->including() ) {
                        $out2 = '';
                } else {
-                       $nsForm = $this->namespacePrefixForm( $namespace, $prefix );
+                       $nsForm = $this->namespacePrefixForm( $namespace, $prefix, $hideredirects );
                        $self = $this->getTitle();
                        $out2 = Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-prefixindex-nav-table' ) )  .
                                '<tr>
@@ -221,7 +236,8 @@ class SpecialPrefixindex extends SpecialAllpages {
                        if( isset( $res ) && $res && ( $n == $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
                                $query = array(
                                        'from' => $s->page_title,
-                                       'prefix' => $prefix
+                                       'prefix' => $prefix,
+                                       'hideredirects' => $hideredirects,
                                );
 
                                if( $namespace || ($prefix == '')) {
index 685b7a7..2f3cc12 100644 (file)
@@ -2664,6 +2664,7 @@ You can narrow down the view by selecting a log type, the username (case-sensiti
 'allpagesbadtitle'  => 'The given page title was invalid or had an inter-language or inter-wiki prefix.
 It may contain one or more characters which cannot be used in titles.',
 'allpages-bad-ns'   => '{{SITENAME}} does not have namespace "$1".',
+'allpages-hide-redirects' => 'Hide redirects',
 
 # Special:Categories
 'categories'                    => 'Categories',
index edfe52e..0f57a4e 100644 (file)
@@ -2347,6 +2347,7 @@ The title is {{msg-mw|nopagetitle}}.',
 
 {{Identical|Go}}',
 'allpagesprefix'    => "Used for the label of the input box of [[Special:PrefixIndex]]. On this page you can either write 'Name of namespace:string from which to begin display in alphabetical order' in the top box, or you can choose a namespace in the bottom box and put 'string from which to begin display in alphabetical order' in the top box. The result will be the same.",
+'allpages-hide-redirects' => 'Label for a checkbox. If the checkbox is checked redirects will not be shown in the list. Used in [[Special:PrefixIndex]] and [[Special:Allpages]].',
 
 # SpecialCachedPage
 'cachedspecial-viewing-cached-ttl' => 'Message notifying they are viewing a cached page. $1 is a duration (ie "1 hour and 30 minutes")',