MediaWiki  1.32.5
MediaWiki\Special\SpecialPageFactory Class Reference

Factory for handling the special page list and generating SpecialPage objects. More...

Collaboration diagram for MediaWiki\Special\SpecialPageFactory:

Public Member Functions

 __construct (Config $config, Language $contLang)
 
 capturePath (Title $title, IContextSource $context, LinkRenderer $linkRenderer=null)
 Just like executePath() but will override global variables and execute the page in "inclusion" mode. More...
 
 executePath (Title &$title, IContextSource &$context, $including=false, LinkRenderer $linkRenderer=null)
 Execute a special page path. More...
 
 exists ( $name)
 Check if a given name exist as a special page or as a special page alias. More...
 
 getLocalNameFor ( $name, $subpage=false)
 Get the local name for a specified canonical name. More...
 
 getNames ()
 Returns a list of canonical special page names. More...
 
 getPage ( $name)
 Find the object with a given name and return it (or NULL) More...
 
 getRegularPages ()
 Return categorised listable special pages for all users. More...
 
 getRestrictedPages (User $user)
 Return categorised listable special pages which are available for the current user, but not for everyone. More...
 
 getTitleForAlias ( $alias)
 Get a title for a given alias. More...
 
 getUsablePages (User $user)
 Return categorised listable special pages which are available for the current user, and everyone. More...
 
 resolveAlias ( $alias)
 Given a special page name with a possible subpage, return an array where the first element is the special page name and the second is the subpage. More...
 

Private Member Functions

 getAliasList ()
 Initialise and return the list of special page aliases. More...
 
 getPageList ()
 Get the special page list as an array. More...
 

Private Attributes

array $aliases
 
Config $config
 
Language $contLang
 
array $list
 Special page name => class name. More...
 

Static Private Attributes

static $coreList
 List of special page names to the subclass of SpecialPage which handles them. More...
 

Detailed Description

Factory for handling the special page list and generating SpecialPage objects.

To add a special page in an extension, add to $wgSpecialPages either an object instance or an array containing the name and constructor parameters. The latter is preferred for performance reasons.

The object instantiated must be either an instance of SpecialPage or a sub-class thereof. It must have an execute() method, which sends the HTML for the special page to $wgOut. The parent class has an execute() method which distributes the call to the historical global functions. Additionally, execute() also checks if the user has the necessary access privileges and bails out if not.

To add a core special page, use the similar static list in SpecialPageFactory::$list. To remove a core static special page at runtime, use a SpecialPage_initList hook.

Note
There are two classes called SpecialPageFactory. You should use this first one, in namespace MediaWiki\Special, which is a service. \SpecialPageFactory is a deprecated collection of static methods that forwards to the global service.
Since
1.17

Definition at line 63 of file SpecialPageFactory.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Special\SpecialPageFactory::__construct ( Config  $config,
Language  $contLang 
)

Member Function Documentation

◆ capturePath()

MediaWiki\Special\SpecialPageFactory::capturePath ( Title  $title,
IContextSource  $context,
LinkRenderer  $linkRenderer = null 
)

Just like executePath() but will override global variables and execute the page in "inclusion" mode.

Returns true if the execution was successful or false if there was no such special page, or a title object if it was a redirect.

Also saves the current $wgTitle, $wgOut, $wgRequest, $wgUser and $wgLang variables so that the special page will get the context it'd expect on a normal request, and then restores them to their previous values after.

Parameters
Title$title
IContextSource$context
LinkRenderer | null$linkRenderer(since 1.28)
Returns
string HTML fragment

Definition at line 588 of file SpecialPageFactory.php.

References MediaWiki\$context, $linkRenderer, $ret, $title, $wgLang, $wgOut, $wgRequest, $wgTitle, MediaWiki\Special\SpecialPageFactory\executePath(), IContextSource\getLanguage(), RequestContext\getMain(), IContextSource\getOutput(), IContextSource\getRequest(), and IContextSource\getUser().

◆ executePath()

MediaWiki\Special\SpecialPageFactory::executePath ( Title $title,
IContextSource $context,
  $including = false,
LinkRenderer  $linkRenderer = null 
)

Execute a special page path.

The path may contain parameters, e.g. Special:Name/Params Extracts the special page name and call the execute method, passing the parameters

Returns a title object if the page is redirected, false if there was no such special page, and true if it was successful.

Parameters
Title&$title
IContextSource&$context
bool$includingBool output is being captured for use in {{special:whatever}}
LinkRenderer | null$linkRenderer(since 1.28)
Returns
bool|Title

Definition at line 501 of file SpecialPageFactory.php.

References MediaWiki\$context, $linkRenderer, $name, $query, $title, $wgSend404Code, IContextSource\getConfig(), IContextSource\getOutput(), MediaWiki\Special\SpecialPageFactory\getPage(), IContextSource\getRequest(), and Profiler\instance().

Referenced by MediaWiki\Special\SpecialPageFactory\capturePath().

◆ exists()

MediaWiki\Special\SpecialPageFactory::exists (   $name)

Check if a given name exist as a special page or as a special page alias.

Parameters
string$nameName of a special page
Returns
bool True if a special page exists with this name

Definition at line 376 of file SpecialPageFactory.php.

References $name, $title, MediaWiki\Special\SpecialPageFactory\getPageList(), list, and MediaWiki\Special\SpecialPageFactory\resolveAlias().

◆ getAliasList()

MediaWiki\Special\SpecialPageFactory::getAliasList ( )
private

Initialise and return the list of special page aliases.

Returns an array where the key is an alias, and the value is the canonical name of the special page. All registered special pages are guaranteed to map to themselves.

Returns
array

Definition at line 293 of file SpecialPageFactory.php.

References MediaWiki\Special\SpecialPageFactory\$aliases, $name, as, MediaWiki\Special\SpecialPageFactory\getPageList(), and wfWarn().

Referenced by MediaWiki\Special\SpecialPageFactory\getLocalNameFor(), and MediaWiki\Special\SpecialPageFactory\resolveAlias().

◆ getLocalNameFor()

MediaWiki\Special\SpecialPageFactory::getLocalNameFor (   $name,
  $subpage = false 
)

Get the local name for a specified canonical name.

Parameters
string$name
string | bool$subpage
Returns
string

Definition at line 647 of file SpecialPageFactory.php.

References MediaWiki\Special\SpecialPageFactory\$aliases, $name, as, MediaWiki\Special\SpecialPageFactory\getAliasList(), and wfWarn().

◆ getNames()

MediaWiki\Special\SpecialPageFactory::getNames ( )

Returns a list of canonical special page names.

May be used to iterate over all registered special pages.

Returns
string[]

Definition at line 238 of file SpecialPageFactory.php.

References MediaWiki\Special\SpecialPageFactory\getPageList().

◆ getPage()

MediaWiki\Special\SpecialPageFactory::getPage (   $name)

Find the object with a given name and return it (or NULL)

Parameters
string$nameSpecial page name, may be localised and/or an alias
Returns
SpecialPage|null SpecialPage object or null if the page doesn't exist

Definition at line 389 of file SpecialPageFactory.php.

References $name, MediaWiki\Special\SpecialPageFactory\getPageList(), list, MediaWiki\Special\SpecialPageFactory\resolveAlias(), and wfLogWarning().

Referenced by MediaWiki\Special\SpecialPageFactory\executePath(), MediaWiki\Special\SpecialPageFactory\getRegularPages(), MediaWiki\Special\SpecialPageFactory\getRestrictedPages(), and MediaWiki\Special\SpecialPageFactory\getUsablePages().

◆ getPageList()

◆ getRegularPages()

MediaWiki\Special\SpecialPageFactory::getRegularPages ( )

Return categorised listable special pages for all users.

Returns
array ( string => Specialpage )

Definition at line 451 of file SpecialPageFactory.php.

References $name, as, MediaWiki\Special\SpecialPageFactory\getPage(), and MediaWiki\Special\SpecialPageFactory\getPageList().

◆ getRestrictedPages()

MediaWiki\Special\SpecialPageFactory::getRestrictedPages ( User  $user)

Return categorised listable special pages which are available for the current user, but not for everyone.

Parameters
User$userUser object to use
Returns
array ( string => Specialpage )

Definition at line 470 of file SpecialPageFactory.php.

References $name, $user, as, MediaWiki\Special\SpecialPageFactory\getPage(), and MediaWiki\Special\SpecialPageFactory\getPageList().

◆ getTitleForAlias()

MediaWiki\Special\SpecialPageFactory::getTitleForAlias (   $alias)

Get a title for a given alias.

Parameters
string$alias
Returns
Title|null Title or null if there is no such alias

Definition at line 700 of file SpecialPageFactory.php.

References $name, SpecialPage\getTitleFor(), list, and MediaWiki\Special\SpecialPageFactory\resolveAlias().

◆ getUsablePages()

MediaWiki\Special\SpecialPageFactory::getUsablePages ( User  $user)

Return categorised listable special pages which are available for the current user, and everyone.

Parameters
User$userUser object to check permissions provided
Returns
array ( string => Specialpage )

Definition at line 429 of file SpecialPageFactory.php.

References $name, $user, as, RequestContext\getMain(), MediaWiki\Special\SpecialPageFactory\getPage(), and MediaWiki\Special\SpecialPageFactory\getPageList().

◆ resolveAlias()

MediaWiki\Special\SpecialPageFactory::resolveAlias (   $alias)

Given a special page name with a possible subpage, return an array where the first element is the special page name and the second is the subpage.

Parameters
string$alias
Returns
array Array( String, String|null ), or array( null, null ) if the page is invalid

Definition at line 349 of file SpecialPageFactory.php.

References MediaWiki\Special\SpecialPageFactory\$aliases, $name, and MediaWiki\Special\SpecialPageFactory\getAliasList().

Referenced by MediaWiki\Special\SpecialPageFactory\exists(), MediaWiki\Special\SpecialPageFactory\getPage(), and MediaWiki\Special\SpecialPageFactory\getTitleForAlias().

Member Data Documentation

◆ $aliases

◆ $config

Config MediaWiki\Special\SpecialPageFactory::$config
private

◆ $contLang

Language MediaWiki\Special\SpecialPageFactory::$contLang
private

◆ $coreList

MediaWiki\Special\SpecialPageFactory::$coreList
staticprivate

List of special page names to the subclass of SpecialPage which handles them.

Todo:
Make this a const when we drop HHVM support (T192166). It can still be private in PHP 7.1.

Definition at line 69 of file SpecialPageFactory.php.

Referenced by MediaWiki\Special\SpecialPageFactory\getPageList().

◆ $list

array MediaWiki\Special\SpecialPageFactory::$list
private

Special page name => class name.

Definition at line 212 of file SpecialPageFactory.php.

Referenced by MediaWiki\Special\SpecialPageFactory\getPageList().


The documentation for this class was generated from the following file: