Merge "Remove unused $wgDebugDBTransactions"
[lhc/web/wiklou.git] / includes / specials / SpecialPrefixindex.php
index fd5005e..fca1748 100644 (file)
@@ -52,12 +52,13 @@ 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(
+               $out->setPageTitle(
                        ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces ) ) )
-                               ? wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
-                               : wfMsg( 'prefixindex' )
+                               ? $this->msg( 'prefixindex-namespace', str_replace( '_', ' ', $namespaces[$namespace] ) )
+                               : $this->msg( 'prefixindex' )
                );
 
                $showme = '';
@@ -65,25 +66,28 @@ class SpecialPrefixindex extends SpecialAllpages {
                        $showme = $par;
                } elseif( $prefix != '' ) {
                        $showme = $prefix;
-               } elseif( $from != '' ) {
+               } elseif( $from != '' && $ns === null ) {
                        // For back-compat with Special:Allpages
+                       // Don't do this if namespace is passed, so paging works when doing NS views.
                        $showme = $from;
                }
 
                // 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.
-       */
-       function namespacePrefixForm( $namespace = NS_MAIN, $from = '' ) {
+        * 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 = '', $hideredirects = false ) {
                global $wgScript;
 
                $out  = Xml::openElement( 'div', array( 'class' => 'namespaceoptions' ) );
@@ -105,10 +109,22 @@ class SpecialPrefixindex extends SpecialAllpages {
                                        Xml::label( wfMsg( 'namespace' ), 'namespace' ) .
                                "</td>
                                <td class='mw-input'>" .
-                                       Xml::namespaceSelector( $namespace, null ) . ' ' .
-                                       Xml::submitButton( wfMsg( 'allpagessubmit' ) ) .
+                               Html::namespaceSelector( array(
+                                               'selected' => $namespace,
+                                       ), array(
+                                               'name'  => 'namespace',
+                                               'id'    => 'namespace',
+                                               'class' => 'namespaceselector',
+                               ) ) .
+                               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' );
@@ -120,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 ) {
@@ -146,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',
@@ -201,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>
@@ -213,13 +236,15 @@ 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 ) {
+                               if( $namespace || ($prefix == '')) {
+                                       // Keep the namespace even if it's 0 for empty prefixes.
+                                       // This tells us we're not just a holdover from old links.
                                        $query['namespace'] = $namespace;
                                }
-
                                $nextLink = Linker::linkKnown(
                                                $self,
                                                wfMsgHtml( 'nextpage', str_replace( '_',' ', htmlspecialchars( $s->page_title ) ) ),