Autocomplete special pages' subpages in search suggestions
[lhc/web/wiklou.git] / includes / specialpage / SpecialPage.php
index d9340b4..da51a33 100644 (file)
@@ -45,12 +45,6 @@ class SpecialPage {
        // Listed in Special:Specialpages?
        private $mListed;
 
-       // Function name called by the default execute()
-       private $mFunction;
-
-       // File which needs to be included before the function above can be called
-       private $mFile;
-
        // Whether or not this special page is being included from an article
        protected $mIncluding;
 
@@ -107,30 +101,18 @@ class SpecialPage {
         * @param string $name Name of the special page, as seen in links and URLs
         * @param string $restriction User right required, e.g. "block" or "delete"
         * @param bool $listed Whether the page is listed in Special:Specialpages
-        * @param callable|bool $function Function called by execute(). By default
-        *   it is constructed from $name
-        * @param string $file File which is included by execute(). It is also
-        *   constructed from $name by default
+        * @param callable|bool $function unused
+        * @param string $file unused
         * @param bool $includable Whether the page can be included in normal pages
         */
        public function __construct(
                $name = '', $restriction = '', $listed = true,
-               $function = false, $file = 'default', $includable = false
+               $function = false, $file = '', $includable = false
        ) {
                $this->mName = $name;
                $this->mRestriction = $restriction;
                $this->mListed = $listed;
                $this->mIncludable = $includable;
-               if ( !$function ) {
-                       $this->mFunction = 'wfSpecial' . $name;
-               } else {
-                       $this->mFunction = $function;
-               }
-               if ( $file === 'default' ) {
-                       $this->mFile = __DIR__ . "/specials/Special$name.php";
-               } else {
-                       $this->mFile = $file;
-               }
        }
 
        /**
@@ -347,6 +329,25 @@ class SpecialPage {
                }
        }
 
+       /**
+        * Return an array of subpages beginning with $search that this special page will accept.
+        *
+        * For example, if a page supports subpages "foo", "bar" and "baz" (as in Special:PageName/foo,
+        * etc.):
+        *
+        *   - `prefixSearchSubpages( "ba" )` should return `array( "bar", "baz" )`
+        *   - `prefixSearchSubpages( "f" )` should return `array( "foo" )`
+        *   - `prefixSearchSubpages( "z" )` should return `array()`
+        *   - `prefixSearchSubpages( "" )` should return `array( foo", "bar", "baz" )`
+        *
+        * @param string $search Prefix to search for
+        * @param integer $limit Maximum number of results to return
+        * @return string[] Matching subpages
+        */
+       public function prefixSearchSubpages( $search, $limit = 10 ) {
+               return array();
+       }
+
        /**
         * Sets headers - this should be called from the execute() method of all derived classes!
         */
@@ -414,7 +415,7 @@ class SpecialPage {
 
        /**
         * Default execute method
-        * Checks user permissions, calls the function given in mFunction
+        * Checks user permissions
         *
         * This must be overridden by subclasses; it will be made abstract in a future version
         *
@@ -423,14 +424,7 @@ class SpecialPage {
        public function execute( $subPage ) {
                $this->setHeaders();
                $this->checkPermissions();
-
-               $func = $this->mFunction;
-               // only load file if the function does not exist
-               if ( !is_callable( $func ) && $this->mFile ) {
-                       require_once $this->mFile;
-               }
                $this->outputHeader();
-               call_user_func( $func, $subPage, $this );
        }
 
        /**
@@ -473,11 +467,9 @@ class SpecialPage {
         *
         * @param string|bool $subpage
         * @return Title
-        * @deprecated in 1.23, use SpecialPage::getPageTitle
+        * @deprecated since 1.23, use SpecialPage::getPageTitle
         */
        function getTitle( $subpage = false ) {
-               wfDeprecated( __METHOD__, '1.23' );
-
                return $this->getPageTitle( $subpage );
        }
 
@@ -582,6 +574,15 @@ class SpecialPage {
                return $this->getContext()->getLanguage();
        }
 
+       /**
+        * Shortcut to get main config object
+        * @return Config
+        * @since 1.24
+        */
+       public function getConfig() {
+               return $this->getContext()->getConfig();
+       }
+
        /**
         * Return the full title, including $par
         *