Merge "Remove unused $wgDebugDBTransactions"
[lhc/web/wiklou.git] / includes / specials / SpecialPrefixindex.php
index 495f15f..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,18 +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.
-       */
-       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' ) );
@@ -106,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' );
@@ -121,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 ) {
@@ -147,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',
@@ -202,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>
@@ -214,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 == '')) {