MediaWiki  1.23.5
SpecialPageFactory.php
Go to the documentation of this file.
1 <?php
50  private static $list = array(
51  // Maintenance Reports
52  'BrokenRedirects' => 'BrokenRedirectsPage',
53  'Deadendpages' => 'DeadendPagesPage',
54  'DoubleRedirects' => 'DoubleRedirectsPage',
55  'Longpages' => 'LongPagesPage',
56  'Ancientpages' => 'AncientPagesPage',
57  'Lonelypages' => 'LonelyPagesPage',
58  'Fewestrevisions' => 'FewestrevisionsPage',
59  'Withoutinterwiki' => 'WithoutInterwikiPage',
60  'Protectedpages' => 'SpecialProtectedpages',
61  'Protectedtitles' => 'SpecialProtectedtitles',
62  'Shortpages' => 'ShortpagesPage',
63  'Uncategorizedcategories' => 'UncategorizedCategoriesPage',
64  'Uncategorizedimages' => 'UncategorizedImagesPage',
65  'Uncategorizedpages' => 'UncategorizedPagesPage',
66  'Uncategorizedtemplates' => 'UncategorizedTemplatesPage',
67  'Unusedcategories' => 'UnusedCategoriesPage',
68  'Unusedimages' => 'UnusedimagesPage',
69  'Unusedtemplates' => 'UnusedtemplatesPage',
70  'Unwatchedpages' => 'UnwatchedpagesPage',
71  'Wantedcategories' => 'WantedCategoriesPage',
72  'Wantedfiles' => 'WantedFilesPage',
73  'Wantedpages' => 'WantedPagesPage',
74  'Wantedtemplates' => 'WantedTemplatesPage',
75 
76  // List of pages
77  'Allpages' => 'SpecialAllpages',
78  'Prefixindex' => 'SpecialPrefixindex',
79  'Categories' => 'SpecialCategories',
80  'Listredirects' => 'ListredirectsPage',
81  'PagesWithProp' => 'SpecialPagesWithProp',
82  'TrackingCategories' => 'SpecialTrackingCategories',
83 
84  // Login/create account
85  'Userlogin' => 'LoginForm',
86  'CreateAccount' => 'SpecialCreateAccount',
87 
88  // Users and rights
89  'Block' => 'SpecialBlock',
90  'Unblock' => 'SpecialUnblock',
91  'BlockList' => 'SpecialBlockList',
92  'ChangePassword' => 'SpecialChangePassword',
93  'PasswordReset' => 'SpecialPasswordReset',
94  'DeletedContributions' => 'DeletedContributionsPage',
95  'Preferences' => 'SpecialPreferences',
96  'ResetTokens' => 'SpecialResetTokens',
97  'Contributions' => 'SpecialContributions',
98  'Listgrouprights' => 'SpecialListGroupRights',
99  'Listusers' => 'SpecialListUsers',
100  'Listadmins' => 'SpecialListAdmins',
101  'Listbots' => 'SpecialListBots',
102  'Userrights' => 'UserrightsPage',
103  'EditWatchlist' => 'SpecialEditWatchlist',
104 
105  // Recent changes and logs
106  'Newimages' => 'SpecialNewFiles',
107  'Log' => 'SpecialLog',
108  'Watchlist' => 'SpecialWatchlist',
109  'Newpages' => 'SpecialNewpages',
110  'Recentchanges' => 'SpecialRecentChanges',
111  'Recentchangeslinked' => 'SpecialRecentChangesLinked',
112  'Tags' => 'SpecialTags',
113 
114  // Media reports and uploads
115  'Listfiles' => 'SpecialListFiles',
116  'Filepath' => 'SpecialFilepath',
117  'MIMEsearch' => 'MIMEsearchPage',
118  'FileDuplicateSearch' => 'FileDuplicateSearchPage',
119  'Upload' => 'SpecialUpload',
120  'UploadStash' => 'SpecialUploadStash',
121  'ListDuplicatedFiles' => 'ListDuplicatedFilesPage',
122 
123  // Data and tools
124  'Statistics' => 'SpecialStatistics',
125  'Allmessages' => 'SpecialAllmessages',
126  'Version' => 'SpecialVersion',
127  'Lockdb' => 'SpecialLockdb',
128  'Unlockdb' => 'SpecialUnlockdb',
129 
130  // Redirecting special pages
131  'LinkSearch' => 'LinkSearchPage',
132  'Randompage' => 'RandomPage',
133  'RandomInCategory' => 'SpecialRandomInCategory',
134  'Randomredirect' => 'SpecialRandomredirect',
135 
136  // High use pages
137  'Mostlinkedcategories' => 'MostlinkedCategoriesPage',
138  'Mostimages' => 'MostimagesPage',
139  'Mostinterwikis' => 'MostinterwikisPage',
140  'Mostlinked' => 'MostlinkedPage',
141  'Mostlinkedtemplates' => 'MostlinkedTemplatesPage',
142  'Mostcategories' => 'MostcategoriesPage',
143  'Mostrevisions' => 'MostrevisionsPage',
144 
145  // Page tools
146  'ComparePages' => 'SpecialComparePages',
147  'Export' => 'SpecialExport',
148  'Import' => 'SpecialImport',
149  'Undelete' => 'SpecialUndelete',
150  'Whatlinkshere' => 'SpecialWhatLinksHere',
151  'MergeHistory' => 'SpecialMergeHistory',
152  'ExpandTemplates' => 'SpecialExpandTemplates',
153 
154  // Other
155  'Booksources' => 'SpecialBookSources',
156 
157  // Unlisted / redirects
158  'Blankpage' => 'SpecialBlankpage',
159  'Diff' => 'SpecialDiff',
160  'Emailuser' => 'SpecialEmailUser',
161  'Movepage' => 'MovePageForm',
162  'Mycontributions' => 'SpecialMycontributions',
163  'Mypage' => 'SpecialMypage',
164  'Mytalk' => 'SpecialMytalk',
165  'Myuploads' => 'SpecialMyuploads',
166  'AllMyUploads' => 'SpecialAllMyUploads',
167  'PermanentLink' => 'SpecialPermanentLink',
168  'Redirect' => 'SpecialRedirect',
169  'Revisiondelete' => 'SpecialRevisionDelete',
170  'RunJobs' => 'SpecialRunJobs',
171  'Specialpages' => 'SpecialSpecialpages',
172  'Userlogout' => 'SpecialUserlogout',
173  );
174 
175  private static $aliases;
176 
182  static function getList() {
183  global $wgSpecialPages;
184  global $wgDisableCounters, $wgDisableInternalSearch, $wgEmailAuthentication;
185  global $wgEnableEmail, $wgEnableJavaScriptTest;
186 
187  if ( !is_object( self::$list ) ) {
188  wfProfileIn( __METHOD__ );
189 
190  if ( !$wgDisableCounters ) {
191  self::$list['Popularpages'] = 'PopularPagesPage';
192  }
193 
194  if ( !$wgDisableInternalSearch ) {
195  self::$list['Search'] = 'SpecialSearch';
196  }
197 
198  if ( $wgEmailAuthentication ) {
199  self::$list['Confirmemail'] = 'EmailConfirmation';
200  self::$list['Invalidateemail'] = 'EmailInvalidation';
201  }
202 
203  if ( $wgEnableEmail ) {
204  self::$list['ChangeEmail'] = 'SpecialChangeEmail';
205  }
206 
207  if ( $wgEnableJavaScriptTest ) {
208  self::$list['JavaScriptTest'] = 'SpecialJavaScriptTest';
209  }
210 
211  self::$list['Activeusers'] = 'SpecialActiveUsers';
212 
213  // Add extension special pages
214  self::$list = array_merge( self::$list, $wgSpecialPages );
215 
216  // Run hooks
217  // This hook can be used to remove undesired built-in special pages
218  wfRunHooks( 'SpecialPage_initList', array( &self::$list ) );
219 
220  // Cast to object: func()[$key] doesn't work, but func()->$key does
221  settype( self::$list, 'object' );
222 
223  wfProfileOut( __METHOD__ );
224  }
225 
226  return self::$list;
227  }
228 
237  static function getAliasList() {
238  if ( !is_object( self::$aliases ) ) {
240  $aliases = $wgContLang->getSpecialPageAliases();
241 
242  // Objects are passed by reference by default, need to create a copy
243  $missingPages = clone self::getList();
244 
245  self::$aliases = array();
246  foreach ( $aliases as $realName => $aliasList ) {
247  foreach ( $aliasList as $alias ) {
248  self::$aliases[$wgContLang->caseFold( $alias )] = $realName;
249  }
250  unset( $missingPages->$realName );
251  }
252  foreach ( $missingPages as $name => $stuff ) {
253  self::$aliases[$wgContLang->caseFold( $name )] = $name;
254  }
255 
256  // Cast to object: func()[$key] doesn't work, but func()->$key does
257  self::$aliases = (object)self::$aliases;
258  }
259 
260  return self::$aliases;
261  }
262 
271  public static function resolveAlias( $alias ) {
273  $bits = explode( '/', $alias, 2 );
274 
275  $caseFoldedAlias = $wgContLang->caseFold( $bits[0] );
276  $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
277  if ( isset( self::getAliasList()->$caseFoldedAlias ) ) {
278  $name = self::getAliasList()->$caseFoldedAlias;
279  } else {
280  return array( null, null );
281  }
282 
283  if ( !isset( $bits[1] ) ) { // bug 2087
284  $par = null;
285  } else {
286  $par = $bits[1];
287  }
288 
289  return array( $name, $par );
290  }
291 
299  public static function setGroup( $page, $group ) {
300  wfDeprecated( __METHOD__, '1.21' );
301 
302  global $wgSpecialPageGroups;
303  $name = is_object( $page ) ? $page->getName() : $page;
304  $wgSpecialPageGroups[$name] = $group;
305  }
306 
314  public static function getGroup( &$page ) {
315  wfDeprecated( __METHOD__, '1.21' );
316 
317  return $page->getFinalGroupName();
318  }
319 
326  public static function exists( $name ) {
327  list( $title, /*...*/ ) = self::resolveAlias( $name );
328 
329  return property_exists( self::getList(), $title );
330  }
331 
338  public static function getPage( $name ) {
339  list( $realName, /*...*/ ) = self::resolveAlias( $name );
340  if ( property_exists( self::getList(), $realName ) ) {
341  $rec = self::getList()->$realName;
342  if ( is_string( $rec ) ) {
343  $className = $rec;
344 
345  return new $className;
346  } elseif ( is_array( $rec ) ) {
347  // @deprecated, officially since 1.18, unofficially since forever
348  wfDebug( "Array syntax for \$wgSpecialPages is deprecated, " .
349  "define a subclass of SpecialPage instead." );
350  $className = array_shift( $rec );
351  self::getList()->$realName = MWFunction::newObj( $className, $rec );
352  }
353 
354  return self::getList()->$realName;
355  } else {
356  return null;
357  }
358  }
359 
368  public static function getUsablePages( User $user = null ) {
369  $pages = array();
370  if ( $user === null ) {
371  global $wgUser;
372  $user = $wgUser;
373  }
374  foreach ( self::getList() as $name => $rec ) {
375  $page = self::getPage( $name );
376  if ( $page ) { // not null
377  $page->setContext( RequestContext::getMain() );
378  if ( $page->isListed()
379  && ( !$page->isRestricted() || $page->userCanExecute( $user ) )
380  ) {
381  $pages[$name] = $page;
382  }
383  }
384  }
385 
386  return $pages;
387  }
388 
394  public static function getRegularPages() {
395  $pages = array();
396  foreach ( self::getList() as $name => $rec ) {
397  $page = self::getPage( $name );
398  if ( $page->isListed() && !$page->isRestricted() ) {
399  $pages[$name] = $page;
400  }
401  }
402 
403  return $pages;
404  }
405 
412  public static function getRestrictedPages() {
413  global $wgUser;
414  $pages = array();
415  foreach ( self::getList() as $name => $rec ) {
416  $page = self::getPage( $name );
417  if (
418  $page->isListed()
419  && $page->isRestricted()
420  && $page->userCanExecute( $wgUser )
421  ) {
422  $pages[$name] = $page;
423  }
424  }
425 
426  return $pages;
427  }
428 
443  public static function executePath( Title &$title, IContextSource &$context, $including = false ) {
444  wfProfileIn( __METHOD__ );
445 
446  // @todo FIXME: Redirects broken due to this call
447  $bits = explode( '/', $title->getDBkey(), 2 );
448  $name = $bits[0];
449  if ( !isset( $bits[1] ) ) { // bug 2087
450  $par = null;
451  } else {
452  $par = $bits[1];
453  }
454  $page = self::getPage( $name );
455  // Nonexistent?
456  if ( !$page ) {
457  $context->getOutput()->setArticleRelated( false );
458  $context->getOutput()->setRobotPolicy( 'noindex,nofollow' );
459 
460  global $wgSend404Code;
461  if ( $wgSend404Code ) {
462  $context->getOutput()->setStatusCode( 404 );
463  }
464 
465  $context->getOutput()->showErrorPage( 'nosuchspecialpage', 'nospecialpagetext' );
466  wfProfileOut( __METHOD__ );
467 
468  return false;
469  }
470 
471  // Page exists, set the context
472  $page->setContext( $context );
473 
474  if ( !$including ) {
475  // Redirect to canonical alias for GET commands
476  // Not for POST, we'd lose the post data, so it's best to just distribute
477  // the request. Such POST requests are possible for old extensions that
478  // generate self-links without being aware that their default name has
479  // changed.
480  if ( $name != $page->getLocalName() && !$context->getRequest()->wasPosted() ) {
481  $query = $context->getRequest()->getQueryValues();
482  unset( $query['title'] );
483  $title = $page->getPageTitle( $par );
484  $url = $title->getFullURL( $query );
485  $context->getOutput()->redirect( $url );
486  wfProfileOut( __METHOD__ );
487 
488  return $title;
489  } else {
490  $context->setTitle( $page->getPageTitle( $par ) );
491  }
492  } elseif ( !$page->isIncludable() ) {
493  wfProfileOut( __METHOD__ );
494 
495  return false;
496  }
497 
498  $page->including( $including );
499 
500  // Execute special page
501  $profName = 'Special:' . $page->getName();
502  wfProfileIn( $profName );
503  $page->run( $par );
504  wfProfileOut( $profName );
505  wfProfileOut( __METHOD__ );
506 
507  return true;
508  }
509 
524  static function capturePath( Title $title, IContextSource $context ) {
525  global $wgOut, $wgTitle, $wgRequest, $wgUser, $wgLang;
526 
527  // Save current globals
529  $oldOut = $wgOut;
530  $oldRequest = $wgRequest;
531  $oldUser = $wgUser;
532  $oldLang = $wgLang;
533 
534  // Set the globals to the current context
535  $wgTitle = $title;
536  $wgOut = $context->getOutput();
537  $wgRequest = $context->getRequest();
538  $wgUser = $context->getUser();
539  $wgLang = $context->getLanguage();
540 
541  // The useful part
542  $ret = self::executePath( $title, $context, true );
543 
544  // And restore the old globals
546  $wgOut = $oldOut;
547  $wgRequest = $oldRequest;
548  $wgUser = $oldUser;
549  $wgLang = $oldLang;
550 
551  return $ret;
552  }
553 
561  static function getLocalNameFor( $name, $subpage = false ) {
563  $aliases = $wgContLang->getSpecialPageAliases();
564 
565  if ( isset( $aliases[$name][0] ) ) {
566  $name = $aliases[$name][0];
567  } else {
568  // Try harder in case someone misspelled the correct casing
569  $found = false;
570  foreach ( $aliases as $n => $values ) {
571  if ( strcasecmp( $name, $n ) === 0 ) {
572  wfWarn( "Found alias defined for $n when searching for " .
573  "special page aliases for $name. Case mismatch?" );
574  $name = $values[0];
575  $found = true;
576  break;
577  }
578  }
579  if ( !$found ) {
580  wfWarn( "Did not find alias for special page '$name'. " .
581  "Perhaps no aliases are defined for it?" );
582  }
583  }
584  if ( $subpage !== false && !is_null( $subpage ) ) {
585  $name = "$name/$subpage";
586  }
587 
588  return $wgContLang->ucfirst( $name );
589  }
590 
597  static function getTitleForAlias( $alias ) {
598  $name = self::resolveAlias( $alias );
599  if ( $name ) {
601  } else {
602  return null;
603  }
604  }
605 }
SpecialPageFactory\getList
static getList()
Get the special page list.
Definition: SpecialPageFactory.php:182
$wgUser
$wgUser
Definition: Setup.php:552
object
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition: globals.txt:25
SpecialPageFactory
Factory for handling the special page list and generating SpecialPage objects.
Definition: SpecialPageFactory.php:46
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
SpecialPageFactory\$list
static $list
List of special page names to the subclass of SpecialPage which handles them.
Definition: SpecialPageFactory.php:50
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
$n
$n
Definition: RandomTest.php:76
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
SpecialPageFactory\getRestrictedPages
static getRestrictedPages()
Return categorised listable special pages which are available for the current user,...
Definition: SpecialPageFactory.php:412
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
SpecialPageFactory\executePath
static executePath(Title &$title, IContextSource &$context, $including=false)
Execute a special page path.
Definition: SpecialPageFactory.php:443
SpecialPageFactory\getUsablePages
static getUsablePages(User $user=null)
Return categorised listable special pages which are available for the current user,...
Definition: SpecialPageFactory.php:368
SpecialPageFactory\getGroup
static getGroup(&$page)
Get the group that the special page belongs in on Special:SpecialPage.
Definition: SpecialPageFactory.php:314
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1127
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
$wgOut
$wgOut
Definition: Setup.php:562
$oldTitle
versus $oldTitle
Definition: globals.txt:16
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4010
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialPageFactory\exists
static exists( $name)
Check if a given name exist as a special page or as a special page alias.
Definition: SpecialPageFactory.php:326
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
SpecialPageFactory\getRegularPages
static getRegularPages()
Return categorised listable special pages for all users.
Definition: SpecialPageFactory.php:394
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
MWFunction\newObj
static newObj( $class, $args=array())
Definition: MWFunction.php:54
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
SpecialPageFactory\setGroup
static setGroup( $page, $group)
Add a page to a certain display group for Special:SpecialPages.
Definition: SpecialPageFactory.php:299
SpecialPageFactory\resolveAlias
static resolveAlias( $alias)
Given a special page name with a possible subpage, return an array where the first element is the spe...
Definition: SpecialPageFactory.php:271
SpecialPageFactory\getTitleForAlias
static getTitleForAlias( $alias)
Get a title for a given alias.
Definition: SpecialPageFactory.php:597
SpecialPageFactory\getLocalNameFor
static getLocalNameFor( $name, $subpage=false)
Get the local name for a specified canonical name.
Definition: SpecialPageFactory.php:561
IContextSource\getUser
getUser()
Get the User object.
SpecialPageFactory\capturePath
static capturePath(Title $title, IContextSource $context)
Just like executePath() but will override global variables and execute the page in "inclusion" mode.
Definition: SpecialPageFactory.php:524
RequestContext\getMain
static getMain()
Static methods.
Definition: RequestContext.php:420
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
IContextSource
Interface for objects which can provide a context on request.
Definition: IContextSource.php:29
Title
Represents a title within MediaWiki.
Definition: Title.php:35
$wgLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
SpecialPageFactory\$aliases
static $aliases
Definition: SpecialPageFactory.php:175
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
IContextSource\getRequest
getRequest()
Get the WebRequest object.
SpecialPageFactory\getAliasList
static getAliasList()
Initialise and return the list of special page aliases.
Definition: SpecialPageFactory.php:237
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
Definition: GlobalFunctions.php:1141
SpecialPageFactory\getPage
static getPage( $name)
Find the object with a given name and return it (or NULL)
Definition: SpecialPageFactory.php:338
$query
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1105
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
IContextSource\getOutput
getOutput()
Get the OutputPage object.
IContextSource\getLanguage
getLanguage()
Get the Language object.
$wgTitle
if(! $wgRequest->checkUrlExtension()) if(! $wgEnableAPI) $wgTitle
Definition: api.php:63