Merge "Make Special:MediaStatistics show a total count of file sizes"
[lhc/web/wiklou.git] / includes / specials / SpecialPrefixindex.php
index fbe5ab3..a6c0423 100644 (file)
@@ -138,7 +138,7 @@ class SpecialPrefixindex extends SpecialAllPages {
                                'stripprefix',
                                $this->stripPrefix
                        ) . ' ' .
-                       Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) .
+                       Xml::submitButton( $this->msg( 'prefixindex-submit' )->text() ) .
                        "</td>
                        </tr>";
                $out .= Xml::closeElement( 'table' );
@@ -205,8 +205,7 @@ class SpecialPrefixindex extends SpecialAllPages {
 
                        $n = 0;
                        if ( $res->numRows() > 0 ) {
-                               $out = Html::openElement( 'div', array( 'class' => 'mw-prefixindex-body' ) );
-                               $out .= Html::openElement( 'ul', array( 'class' => 'mw-prefixindex-list' ) );
+                               $out = Html::openElement( 'ul', array( 'class' => 'mw-prefixindex-list' ) );
 
                                $prefixLength = strlen( $prefix );
                                while ( ( $n < $this->maxPerPage ) && ( $s = $res->fetchObject() ) ) {
@@ -228,12 +227,17 @@ class SpecialPrefixindex extends SpecialAllPages {
                                                $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
                                        }
 
-                                       $out .= "<li> $link </li>\n";
+                                       $out .= "<li>$link</li>\n";
                                        $n++;
 
                                }
                                $out .= Html::closeElement( 'ul' );
-                               $out .= Html::closeElement( 'div' );
+
+                               if ( $res->numRows() > 2 ) {
+                                       // Only apply CSS column styles if there's more than 2 entries.
+                                       // Otherwise rendering is broken as "mw-prefixindex-body"'s CSS column count is 3.
+                                       $out = Html::rawElement( 'div', array( 'class' => 'mw-prefixindex-body' ), $out );
+                               }
                        } else {
                                $out = '';
                        }
@@ -290,6 +294,26 @@ class SpecialPrefixindex extends SpecialAllPages {
                $output->addHTML( $topOut . $out );
        }
 
+       /**
+        * Return an array of subpages beginning with $search that this special page will accept.
+        *
+        * @param string $search Prefix to search for
+        * @param int $limit Maximum number of results to return (usually 10)
+        * @param int $offset Number of results to skip (usually 0)
+        * @return string[] Matching subpages
+        */
+       public function prefixSearchSubpages( $search, $limit, $offset ) {
+               $title = Title::newFromText( $search );
+               if ( !$title || !$title->canExist() ) {
+                       // No prefix suggestion in special and media namespace
+                       return array();
+               }
+               // Autocomplete subpage the same as a normal search
+               $prefixSearcher = new StringPrefixSearch;
+               $result = $prefixSearcher->search( $search, $limit, array(), $offset );
+               return $result;
+       }
+
        protected function getGroupName() {
                return 'pages';
        }