MediaWiki  1.23.8
SpecialPage.php
Go to the documentation of this file.
1 <?php
33 class SpecialPage {
34  // The canonical name of this special page
35  // Also used for the default <h1> heading, @see getDescription()
36  protected $mName;
37 
38  // The local name of this special page
39  private $mLocalName;
40 
41  // Minimum user level required to access this page, or "" for anyone.
42  // Also used to categorise the pages in Special:Specialpages
43  private $mRestriction;
44 
45  // Listed in Special:Specialpages?
46  private $mListed;
47 
48  // Function name called by the default execute()
49  private $mFunction;
50 
51  // File which needs to be included before the function above can be called
52  private $mFile;
53 
54  // Whether or not this special page is being included from an article
55  protected $mIncluding;
56 
57  // Whether the special page can be included in an article
58  protected $mIncludable;
59 
64  protected $mContext;
65 
75  public static function getTitleFor( $name, $subpage = false, $fragment = '' ) {
77 
78  return Title::makeTitle( NS_SPECIAL, $name, $fragment );
79  }
80 
88  public static function getSafeTitleFor( $name, $subpage = false ) {
90  if ( $name ) {
92  } else {
93  return null;
94  }
95  }
96 
116  public function __construct(
117  $name = '', $restriction = '', $listed = true,
118  $function = false, $file = 'default', $includable = false
119  ) {
120  $this->mName = $name;
121  $this->mRestriction = $restriction;
122  $this->mListed = $listed;
123  $this->mIncludable = $includable;
124  if ( !$function ) {
125  $this->mFunction = 'wfSpecial' . $name;
126  } else {
127  $this->mFunction = $function;
128  }
129  if ( $file === 'default' ) {
130  $this->mFile = __DIR__ . "/specials/Special$name.php";
131  } else {
132  $this->mFile = $file;
133  }
134  }
135 
140  function getName() {
141  return $this->mName;
142  }
143 
148  function getRestriction() {
149  return $this->mRestriction;
150  }
151 
159  function getFile() {
160  wfDeprecated( __METHOD__, '1.18' );
161 
162  return $this->mFile;
163  }
164 
165  // @todo FIXME: Decide which syntax to use for this, and stick to it
171  function isListed() {
172  return $this->mListed;
173  }
174 
181  function setListed( $listed ) {
182  return wfSetVar( $this->mListed, $listed );
183  }
184 
191  function listed( $x = null ) {
192  return wfSetVar( $this->mListed, $x );
193  }
194 
199  public function isIncludable() {
200  return $this->mIncludable;
201  }
202 
208  function including( $x = null ) {
209  return wfSetVar( $this->mIncluding, $x );
210  }
211 
216  function getLocalName() {
217  if ( !isset( $this->mLocalName ) ) {
218  $this->mLocalName = SpecialPageFactory::getLocalNameFor( $this->mName );
219  }
220 
221  return $this->mLocalName;
222  }
223 
232  public function isExpensive() {
233  return false;
234  }
235 
245  public function isCached() {
246  return false;
247  }
248 
256  public function isRestricted() {
257  // DWIM: If anons can do something, then it is not restricted
258  return $this->mRestriction != '' && !User::groupHasPermission( '*', $this->mRestriction );
259  }
260 
269  public function userCanExecute( User $user ) {
270  return $user->isAllowed( $this->mRestriction );
271  }
272 
277  function displayRestrictionError() {
278  throw new PermissionsError( $this->mRestriction );
279  }
280 
288  public function checkPermissions() {
289  if ( !$this->userCanExecute( $this->getUser() ) ) {
290  $this->displayRestrictionError();
291  }
292  }
293 
301  public function checkReadOnly() {
302  if ( wfReadOnly() ) {
303  throw new ReadOnlyError;
304  }
305  }
306 
322  public function requireLogin( $reasonMsg = null, $titleMsg = null ) {
323  if ( $this->getUser()->isAnon() ) {
324  // Use default messages if not given or explicit null passed
325  if ( !$reasonMsg ) {
326  $reasonMsg = 'exception-nologin-text-manual';
327  }
328  if ( !$titleMsg ) {
329  $titleMsg = 'exception-nologin';
330  }
331 
332  // Convert to Messages with current context
333  if ( is_string( $reasonMsg ) ) {
334  $loginreqlink = Linker::linkKnown(
335  SpecialPage::getTitleFor( 'Userlogin' ),
336  $this->msg( 'loginreqlink' )->escaped(),
337  array(),
338  array( 'returnto' => $this->getPageTitle()->getPrefixedText() )
339  );
340  $reasonMsg = $this->msg( $reasonMsg )->rawParams( $loginreqlink );
341  }
342  if ( is_string( $titleMsg ) ) {
343  $titleMsg = $this->msg( $titleMsg );
344  }
345 
346  throw new UserNotLoggedIn( $reasonMsg, $titleMsg );
347  }
348  }
349 
353  function setHeaders() {
354  $out = $this->getOutput();
355  $out->setArticleRelated( false );
356  $out->setRobotPolicy( $this->getRobotPolicy() );
357  $out->setPageTitle( $this->getDescription() );
358  }
359 
367  final public function run( $subPage ) {
376  wfRunHooks( 'SpecialPageBeforeExecute', array( $this, $subPage ) );
377 
378  $this->beforeExecute( $subPage );
379  $this->execute( $subPage );
380  $this->afterExecute( $subPage );
381 
390  wfRunHooks( 'SpecialPageAfterExecute', array( $this, $subPage ) );
391  }
392 
400  protected function beforeExecute( $subPage ) {
401  // No-op
402  }
403 
411  protected function afterExecute( $subPage ) {
412  // No-op
413  }
414 
423  public function execute( $subPage ) {
424  $this->setHeaders();
425  $this->checkPermissions();
426 
427  $func = $this->mFunction;
428  // only load file if the function does not exist
429  if ( !is_callable( $func ) && $this->mFile ) {
430  require_once $this->mFile;
431  }
432  $this->outputHeader();
433  call_user_func( $func, $subPage, $this );
434  }
435 
444  function outputHeader( $summaryMessageKey = '' ) {
446 
447  if ( $summaryMessageKey == '' ) {
448  $msg = $wgContLang->lc( $this->getName() ) . '-summary';
449  } else {
450  $msg = $summaryMessageKey;
451  }
452  if ( !$this->msg( $msg )->isDisabled() && !$this->including() ) {
453  $this->getOutput()->wrapWikiMsg(
454  "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
455  }
456  }
457 
467  function getDescription() {
468  return $this->msg( strtolower( $this->mName ) )->text();
469  }
470 
478  function getTitle( $subpage = false ) {
479  return $this->getPageTitle( $subpage );
480  }
481 
489  function getPageTitle( $subpage = false ) {
490  return self::getTitleFor( $this->mName, $subpage );
491  }
492 
499  public function setContext( $context ) {
500  $this->mContext = $context;
501  }
502 
509  public function getContext() {
510  if ( $this->mContext instanceof IContextSource ) {
511  return $this->mContext;
512  } else {
513  wfDebug( __METHOD__ . " called and \$mContext is null. " .
514  "Return RequestContext::getMain(); for sanity\n" );
515 
516  return RequestContext::getMain();
517  }
518  }
519 
526  public function getRequest() {
527  return $this->getContext()->getRequest();
528  }
529 
536  public function getOutput() {
537  return $this->getContext()->getOutput();
538  }
539 
546  public function getUser() {
547  return $this->getContext()->getUser();
548  }
549 
556  public function getSkin() {
557  return $this->getContext()->getSkin();
558  }
559 
567  public function getLang() {
568  wfDeprecated( __METHOD__, '1.19' );
569 
570  return $this->getLanguage();
571  }
572 
579  public function getLanguage() {
580  return $this->getContext()->getLanguage();
581  }
582 
589  public function getFullTitle() {
590  return $this->getContext()->getTitle();
591  }
592 
600  protected function getRobotPolicy() {
601  return 'noindex,nofollow';
602  }
603 
610  public function msg( /* $args */ ) {
611  $message = call_user_func_array(
612  array( $this->getContext(), 'msg' ),
613  func_get_args()
614  );
615  // RequestContext passes context to wfMessage, and the language is set from
616  // the context, but setting the language for Message class removes the
617  // interface message status, which breaks for example usernameless gender
618  // invocations. Restore the flag when not including special page in content.
619  if ( $this->including() ) {
620  $message->setInterfaceMessageFlag( false );
621  }
622 
623  return $message;
624  }
625 
631  protected function addFeedLinks( $params ) {
632  global $wgFeedClasses;
633 
634  $feedTemplate = wfScript( 'api' );
635 
636  foreach ( $wgFeedClasses as $format => $class ) {
637  $theseParams = $params + array( 'feedformat' => $format );
638  $url = wfAppendQuery( $feedTemplate, $theseParams );
639  $this->getOutput()->addFeedLink( $format, $url );
640  }
641  }
642 
651  public function getFinalGroupName() {
652  global $wgSpecialPageGroups;
653  $name = $this->getName();
654 
655  // Allow overbidding the group from the wiki side
656  $msg = $this->msg( 'specialpages-specialpagegroup-' . strtolower( $name ) )->inContentLanguage();
657  if ( !$msg->isBlank() ) {
658  $group = $msg->text();
659  } else {
660  // Than use the group from this object
661  $group = $this->getGroupName();
662 
663  // Group '-' is used as default to have the chance to determine,
664  // if the special pages overrides this method,
665  // if not overridden, $wgSpecialPageGroups is checked for b/c
666  if ( $group === '-' && isset( $wgSpecialPageGroups[$name] ) ) {
667  $group = $wgSpecialPageGroups[$name];
668  }
669  }
670 
671  // never give '-' back, change to 'other'
672  if ( $group === '-' ) {
673  $group = 'other';
674  }
675 
676  return $group;
677  }
678 
687  protected function getGroupName() {
688  // '-' used here to determine, if this group is overridden or has a hardcoded 'other'
689  // Needed for b/c in getFinalGroupName
690  return '-';
691  }
692 }
ReadOnlyError
Show an error when the wiki is locked/read-only and the user tries to do something that requires writ...
Definition: ReadOnlyError.php:28
SpecialPage\$mIncluding
$mIncluding
Definition: SpecialPage.php:55
SpecialPage\getPageTitle
getPageTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:488
SpecialPage\getFinalGroupName
getFinalGroupName()
Get the group that the special page belongs in on Special:SpecialPage Use this method,...
Definition: SpecialPage.php:650
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
SpecialPage\$mFunction
$mFunction
Definition: SpecialPage.php:49
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
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:535
SpecialPage\isExpensive
isExpensive()
Is this page expensive (for some definition of expensive)? Expensive pages are disabled or cached in ...
Definition: SpecialPage.php:231
SpecialPage\getTitle
getTitle( $subpage=false)
Get a self-referential title object.
Definition: SpecialPage.php:477
SpecialPage\getLang
getLang()
Shortcut to get user's language.
Definition: SpecialPage.php:566
SpecialPage\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialPage.php:686
wfSetVar
wfSetVar(&$dest, $source, $force=false)
Sets dest to source and returns the original value of dest If source is NULL, it just returns the val...
Definition: GlobalFunctions.php:2139
UserNotLoggedIn
Shows a generic "user is not logged in" error page.
Definition: UserNotLoggedIn.php:48
SpecialPage\$mIncludable
$mIncludable
Definition: SpecialPage.php:58
SpecialPage\checkPermissions
checkPermissions()
Checks if userCanExecute, and if not throws a PermissionsError.
Definition: SpecialPage.php:287
SpecialPage\$mFile
$mFile
Definition: SpecialPage.php:52
SpecialPage\displayRestrictionError
displayRestrictionError()
Output an error message telling the user what access level they have to have.
Definition: SpecialPage.php:276
SpecialPage\setListed
setListed( $listed)
Set whether this page is listed in Special:Specialpages, at run-time.
Definition: SpecialPage.php:180
$params
$params
Definition: styleTest.css.php:40
wfReadOnly
wfReadOnly()
Check whether the wiki is in read-only mode.
Definition: GlobalFunctions.php:1313
SpecialPage\getLocalName
getLocalName()
Get the localised name of the special page.
Definition: SpecialPage.php:215
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
SpecialPage\$mContext
IContextSource $mContext
Current request context.
Definition: SpecialPage.php:63
SpecialPage\getSkin
getSkin()
Shortcut to get the skin being used for this instance.
Definition: SpecialPage.php:555
PermissionsError
Show an error when a user tries to do something they do not have the necessary permissions for.
Definition: PermissionsError.php:28
$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
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:578
SpecialPage\__construct
__construct( $name='', $restriction='', $listed=true, $function=false, $file='default', $includable=false)
Default constructor for special pages Derivative classes should call this from their constructor Note...
Definition: SpecialPage.php:115
User\groupHasPermission
static groupHasPermission( $group, $role)
Check, if the given group has the given permission.
Definition: User.php:4147
SpecialPage\getName
getName()
Get the name of this Special Page.
Definition: SpecialPage.php:139
SpecialPage\requireLogin
requireLogin( $reasonMsg=null, $titleMsg=null)
If the user is not logged in, throws UserNotLoggedIn error.
Definition: SpecialPage.php:321
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=array(), $query=array(), $options=array( 'known', 'noclasses'))
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
SpecialPage\isListed
isListed()
Whether this special page is listed in Special:SpecialPages.
Definition: SpecialPage.php:170
SpecialPage\getRestriction
getRestriction()
Get the permission that a user must have to execute this page.
Definition: SpecialPage.php:147
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:459
SpecialPage\getSafeTitleFor
static getSafeTitleFor( $name, $subpage=false)
Get a localised Title object for a page name with a possibly unvalidated subpage.
Definition: SpecialPage.php:87
SpecialPage\$mRestriction
$mRestriction
Definition: SpecialPage.php:43
SpecialPage\getDescription
getDescription()
Returns the name that goes in the <h1> in the special page itself, and also the name that will be lis...
Definition: SpecialPage.php:466
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:68
$out
$out
Definition: UtfNormalGenerate.php:167
SpecialPage\addFeedLinks
addFeedLinks( $params)
Adds RSS/atom links.
Definition: SpecialPage.php:630
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1127
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:3739
SpecialPage\$mLocalName
$mLocalName
Definition: SpecialPage.php:39
SpecialPage\getFullTitle
getFullTitle()
Return the full title, including $par.
Definition: SpecialPage.php:588
SpecialPage\isRestricted
isRestricted()
Can be overridden by subclasses with more complicated permissions schemes.
Definition: SpecialPage.php:255
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.
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:352
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:545
SpecialPage\isIncludable
isIncludable()
Whether it's allowed to transclude the special page via {{Special:Foo/params}}.
Definition: SpecialPage.php:198
SpecialPage\afterExecute
afterExecute( $subPage)
Gets called after.
Definition: SpecialPage.php:410
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
SpecialPage\getFile
getFile()
Get the file which will be included by SpecialPage::execute() if your extension is still stuck in the...
Definition: SpecialPage.php:158
SpecialPage\beforeExecute
beforeExecute( $subPage)
Gets called before.
Definition: SpecialPage.php:399
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:508
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\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:422
SpecialPage\userCanExecute
userCanExecute(User $user)
Checks if the given user (identified by an object) can execute this special page (as defined by $mRes...
Definition: SpecialPage.php:268
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
SpecialPage\getRobotPolicy
getRobotPolicy()
Return the robot policy.
Definition: SpecialPage.php:599
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:609
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:33
SpecialPage\listed
listed( $x=null)
Get or set whether this special page is listed in Special:SpecialPages.
Definition: SpecialPage.php:190
SpecialPage\isCached
isCached()
Is this page cached? Expensive pages are cached or disabled in miser mode.
Definition: SpecialPage.php:244
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:525
SpecialPageFactory\getLocalNameFor
static getLocalNameFor( $name, $subpage=false)
Get the local name for a specified canonical name.
Definition: SpecialPageFactory.php:561
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
SpecialPage\run
run( $subPage)
Entry point.
Definition: SpecialPage.php:366
SpecialPage\execute
execute( $subPage)
Default execute method Checks user permissions, calls the function given in mFunction.
Definition: SpecialPage.php:422
IContextSource
Interface for objects which can provide a context on request.
Definition: IContextSource.php:29
SpecialPage\$mName
$mName
Definition: SpecialPage.php:36
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
SpecialPage\$mListed
$mListed
Definition: SpecialPage.php:46
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
SpecialPage\setContext
setContext( $context)
Sets the context this SpecialPage is executed in.
Definition: SpecialPage.php:498
SpecialPage\checkReadOnly
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
Definition: SpecialPage.php:300
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:443
SpecialPage\including
including( $x=null)
Whether the special page is being evaluated via transclusion.
Definition: SpecialPage.php:207