Implement mediawiki.confirmCloseWindow module
[lhc/web/wiklou.git] / includes / PrefixSearch.php
index c5dd698..718750f 100644 (file)
@@ -29,7 +29,7 @@
 abstract class PrefixSearch {
        /**
         * Do a prefix search of titles and return a list of matching page names.
-        * @deprecated: Since 1.23, use TitlePrefixSearch or StringPrefixSearch classes
+        * @deprecated Since 1.23, use TitlePrefixSearch or StringPrefixSearch classes
         *
         * @param string $search
         * @param int $limit
@@ -121,7 +121,7 @@ abstract class PrefixSearch {
         * @param array $titles
         * @return array
         */
-       protected abstract function titles( array $titles );
+       abstract protected function titles( array $titles );
 
        /**
         * When implemented in a descendant class, receives an array of titles as strings and returns
@@ -131,7 +131,7 @@ abstract class PrefixSearch {
         *
         * @return array
         */
-       protected abstract function strings( array $strings );
+       abstract protected function strings( array $strings );
 
        /**
         * Do a prefix search of titles and return a list of matching page names.
@@ -166,20 +166,41 @@ abstract class PrefixSearch {
        protected function specialSearch( $search, $limit ) {
                global $wgContLang;
 
-               # normalize searchKey, so aliases with spaces can be found - bug 25675
-               $search = str_replace( ' ', '_', $search );
+               $searchParts = explode( '/', $search, 2 );
+               $searchKey = $searchParts[0];
+               $subpageSearch = isset( $searchParts[1] ) ? $searchParts[1] : null;
+
+               // Handle subpage search separately.
+               if ( $subpageSearch !== null ) {
+                       // Try matching the full search string as a page name
+                       $specialTitle = Title::makeTitleSafe( NS_SPECIAL, $searchKey );
+                       if ( !$specialTitle ) {
+                               return array();
+                       }
+                       $special = SpecialPageFactory::getPage( $specialTitle->getText() );
+                       if ( $special ) {
+                               $subpages = $special->prefixSearchSubpages( $subpageSearch, $limit );
+                               return array_map( function ( $sub ) use ( $specialTitle ) {
+                                       return $specialTitle->getSubpage( $sub );
+                               }, $subpages );
+                       } else {
+                               return array();
+                       }
+               }
 
-               $searchKey = $wgContLang->caseFold( $search );
+               # normalize searchKey, so aliases with spaces can be found - bug 25675
+               $searchKey = str_replace( ' ', '_', $searchKey );
+               $searchKey = $wgContLang->caseFold( $searchKey );
 
                // Unlike SpecialPage itself, we want the canonical forms of both
                // canonical and alias title forms...
                $keys = array();
-               foreach ( SpecialPageFactory::getList() as $page => $class ) {
+               foreach ( SpecialPageFactory::getNames() as $page  ) {
                        $keys[$wgContLang->caseFold( $page )] = $page;
                }
 
                foreach ( $wgContLang->getSpecialPageAliases() as $page => $aliases ) {
-                       if ( !array_key_exists( $page, SpecialPageFactory::getList() ) ) {# bug 20885
+                       if ( !in_array( $page, SpecialPageFactory::getNames() ) ) {# bug 20885
                                continue;
                        }
 
@@ -296,7 +317,9 @@ class TitlePrefixSearch extends PrefixSearch {
 class StringPrefixSearch extends PrefixSearch {
 
        protected function titles( array $titles ) {
-               return array_map( function( Title $t ) { return $t->getPrefixedText(); }, $titles );
+               return array_map( function ( Title $t ) {
+                       return $t->getPrefixedText();
+               }, $titles );
        }
 
        protected function strings( array $strings ) {