heading, @see getDescription() protected $mName; // The local name of this special page private $mLocalName; // Minimum user level required to access this page, or "" for anyone. // Also used to categorise the pages in Special:Specialpages protected $mRestriction; // Listed in Special:Specialpages? private $mListed; // Whether or not this special page is being included from an article protected $mIncluding; // Whether the special page can be included in an article protected $mIncludable; /** * Current request context * @var IContextSource */ protected $mContext; /** * Get a localised Title object for a specified special page name * * @param string $name * @param string|bool $subpage Subpage string, or false to not use a subpage * @param string $fragment The link fragment (after the "#") * @return Title * @throws MWException */ public static function getTitleFor( $name, $subpage = false, $fragment = '' ) { $name = SpecialPageFactory::getLocalNameFor( $name, $subpage ); return Title::makeTitle( NS_SPECIAL, $name, $fragment ); } /** * Get a localised Title object for a page name with a possibly unvalidated subpage * * @param string $name * @param string|bool $subpage Subpage string, or false to not use a subpage * @return Title|null Title object or null if the page doesn't exist */ public static function getSafeTitleFor( $name, $subpage = false ) { $name = SpecialPageFactory::getLocalNameFor( $name, $subpage ); if ( $name ) { return Title::makeTitleSafe( NS_SPECIAL, $name ); } else { return null; } } /** * Default constructor for special pages * Derivative classes should call this from their constructor * Note that if the user does not have the required level, an error message will * be displayed by the default execute() method, without the global function ever * being called. * * If you override execute(), you can recover the default behavior with userCanExecute() * and displayRestrictionError() * * @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 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 = '', $includable = false ) { $this->mName = $name; $this->mRestriction = $restriction; $this->mListed = $listed; $this->mIncludable = $includable; } /** * Get the name of this Special Page. * @return string */ function getName() { return $this->mName; } /** * Get the permission that a user must have to execute this page * @return string */ function getRestriction() { return $this->mRestriction; } // @todo FIXME: Decide which syntax to use for this, and stick to it /** * Whether this special page is listed in Special:SpecialPages * @since 1.3 (r3583) * @return bool */ function isListed() { return $this->mListed; } /** * Set whether this page is listed in Special:Specialpages, at run-time * @since 1.3 * @param bool $listed * @return bool */ function setListed( $listed ) { return wfSetVar( $this->mListed, $listed ); } /** * Get or set whether this special page is listed in Special:SpecialPages * @since 1.6 * @param bool $x * @return bool */ function listed( $x = null ) { return wfSetVar( $this->mListed, $x ); } /** * Whether it's allowed to transclude the special page via {{Special:Foo/params}} * @return bool */ public function isIncludable() { return $this->mIncludable; } /** * Whether the special page is being evaluated via transclusion * @param bool $x * @return bool */ function including( $x = null ) { return wfSetVar( $this->mIncluding, $x ); } /** * Get the localised name of the special page * @return string */ function getLocalName() { if ( !isset( $this->mLocalName ) ) { $this->mLocalName = SpecialPageFactory::getLocalNameFor( $this->mName ); } return $this->mLocalName; } /** * Is this page expensive (for some definition of expensive)? * Expensive pages are disabled or cached in miser mode. Originally used * (and still overridden) by QueryPage and subclasses, moved here so that * Special:SpecialPages can safely call it for all special pages. * * @return bool */ public function isExpensive() { return false; } /** * Is this page cached? * Expensive pages are cached or disabled in miser mode. * Used by QueryPage and subclasses, moved here so that * Special:SpecialPages can safely call it for all special pages. * * @return bool * @since 1.21 */ public function isCached() { return false; } /** * Can be overridden by subclasses with more complicated permissions * schemes. * * @return bool Should the page be displayed with the restricted-access * pages? */ public function isRestricted() { // DWIM: If anons can do something, then it is not restricted return $this->mRestriction != '' && !User::groupHasPermission( '*', $this->mRestriction ); } /** * Checks if the given user (identified by an object) can execute this * special page (as defined by $mRestriction). Can be overridden by sub- * classes with more complicated permissions schemes. * * @param User $user The user to check * @return bool Does the user have permission to view the page? */ public function userCanExecute( User $user ) { return $user->isAllowed( $this->mRestriction ); } /** * Output an error message telling the user what access level they have to have * @throws PermissionsError */ function displayRestrictionError() { throw new PermissionsError( $this->mRestriction ); } /** * Checks if userCanExecute, and if not throws a PermissionsError * * @since 1.19 * @return void * @throws PermissionsError */ public function checkPermissions() { if ( !$this->userCanExecute( $this->getUser() ) ) { $this->displayRestrictionError(); } } /** * If the wiki is currently in readonly mode, throws a ReadOnlyError * * @since 1.19 * @return void * @throws ReadOnlyError */ public function checkReadOnly() { if ( wfReadOnly() ) { throw new ReadOnlyError; } } /** * If the user is not logged in, throws UserNotLoggedIn error * * The user will be redirected to Special:Userlogin with the given message as an error on * the form. * * @since 1.23 * @param string $reasonMsg [optional] Message key to be displayed on login page * @param string $titleMsg [optional] Passed on to UserNotLoggedIn constructor * @throws UserNotLoggedIn */ public function requireLogin( $reasonMsg = 'exception-nologin-text', $titleMsg = 'exception-nologin' ) { if ( $this->getUser()->isAnon() ) { throw new UserNotLoggedIn( $reasonMsg, $titleMsg ); } } /** * 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 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 ) { $subpages = $this->getSubpagesForPrefixSearch(); if ( !$subpages ) { return array(); } return self::prefixSearchArray( $search, $limit, $subpages, $offset ); } /** * Return an array of subpages that this special page will accept for prefix * searches. If this method requires a query you might instead want to implement * prefixSearchSubpages() directly so you can support $limit and $offset. This * method is better for static-ish lists of things. * * @return string[] subpages to search from */ protected function getSubpagesForPrefixSearch() { return array(); } /** * Helper function for implementations of prefixSearchSubpages() that * filter the values in memory (as opposed to making a query). * * @since 1.24 * @param string $search * @param int $limit * @param array $subpages * @param int $offset * @return string[] */ protected static function prefixSearchArray( $search, $limit, array $subpages, $offset ) { $escaped = preg_quote( $search, '/' ); return array_slice( preg_grep( "/^$escaped/i", array_slice( $subpages, $offset ) ), 0, $limit ); } /** * Sets headers - this should be called from the execute() method of all derived classes! */ function setHeaders() { $out = $this->getOutput(); $out->setArticleRelated( false ); $out->setRobotPolicy( $this->getRobotPolicy() ); $out->setPageTitle( $this->getDescription() ); if ( $this->getConfig()->get( 'UseMediaWikiUIEverywhere' ) ) { $out->addModuleStyles( array( 'mediawiki.ui.input', 'mediawiki.ui.radio', 'mediawiki.ui.checkbox', ) ); } } /** * Entry point. * * @since 1.20 * * @param string|null $subPage */ final public function run( $subPage ) { /** * Gets called before @see SpecialPage::execute. * * @since 1.20 * * @param SpecialPage $this * @param string|null $subPage */ Hooks::run( 'SpecialPageBeforeExecute', array( $this, $subPage ) ); $this->beforeExecute( $subPage ); $this->execute( $subPage ); $this->afterExecute( $subPage ); /** * Gets called after @see SpecialPage::execute. * * @since 1.20 * * @param SpecialPage $this * @param string|null $subPage */ Hooks::run( 'SpecialPageAfterExecute', array( $this, $subPage ) ); } /** * Gets called before @see SpecialPage::execute. * * @since 1.20 * * @param string|null $subPage */ protected function beforeExecute( $subPage ) { // No-op } /** * Gets called after @see SpecialPage::execute. * * @since 1.20 * * @param string|null $subPage */ protected function afterExecute( $subPage ) { // No-op } /** * Default execute method * Checks user permissions * * This must be overridden by subclasses; it will be made abstract in a future version * * @param string|null $subPage */ public function execute( $subPage ) { $this->setHeaders(); $this->checkPermissions(); $this->outputHeader(); } /** * Outputs a summary message on top of special pages * Per default the message key is the canonical name of the special page * May be overridden, i.e. by extensions to stick with the naming conventions * for message keys: 'extensionname-xxx' * * @param string $summaryMessageKey Message key of the summary */ function outputHeader( $summaryMessageKey = '' ) { global $wgContLang; if ( $summaryMessageKey == '' ) { $msg = $wgContLang->lc( $this->getName() ) . '-summary'; } else { $msg = $summaryMessageKey; } if ( !$this->msg( $msg )->isDisabled() && !$this->including() ) { $this->getOutput()->wrapWikiMsg( "