MediaWiki  master
SpecialSpecialpages.php
Go to the documentation of this file.
1 <?php
25 
32 
33  function __construct() {
34  parent::__construct( 'Specialpages' );
35  }
36 
37  function execute( $par ) {
38  $out = $this->getOutput();
39  $this->setHeaders();
40  $this->outputHeader();
41  $out->allowClickjacking();
42  $out->addModuleStyles( 'mediawiki.special' );
43 
44  $groups = $this->getPageGroups();
45 
46  if ( $groups === false ) {
47  return;
48  }
49 
50  $this->addHelpLink( 'Help:Special pages' );
51  $this->outputPageList( $groups );
52  }
53 
54  private function getPageGroups() {
55  $pages = MediaWikiServices::getInstance()->getSpecialPageFactory()->
56  getUsablePages( $this->getUser() );
57 
58  if ( !count( $pages ) ) {
59  # Yeah, that was pointless. Thanks for coming.
60  return false;
61  }
62 
64  $groups = [];
66  foreach ( $pages as $page ) {
67  if ( $page->isListed() ) {
68  $group = $page->getFinalGroupName();
69  if ( !isset( $groups[$group] ) ) {
70  $groups[$group] = [];
71  }
72  $groups[$group][$page->getDescription()] = [
73  $page->getPageTitle(),
74  $page->isRestricted(),
75  $page->isCached()
76  ];
77  }
78  }
79 
81  foreach ( $groups as $group => $sortedPages ) {
82  ksort( $groups[$group] );
83  }
84 
86  if ( array_key_exists( 'other', $groups ) ) {
87  $other = $groups['other'];
88  unset( $groups['other'] );
89  $groups['other'] = $other;
90  }
91 
92  return $groups;
93  }
94 
95  private function outputPageList( $groups ) {
96  $out = $this->getOutput();
97 
98  $includesRestrictedPages = false;
99  $includesCachedPages = false;
100 
101  foreach ( $groups as $group => $sortedPages ) {
102  $out->wrapWikiMsg(
103  "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n",
104  "specialpages-group-$group"
105  );
106  $out->addHTML(
107  Html::openElement( 'div', [ 'class' => 'mw-specialpages-list' ] )
108  . '<ul>'
109  );
110  foreach ( $sortedPages as $desc => $specialpage ) {
111  list( $title, $restricted, $cached ) = $specialpage;
112 
113  $pageClasses = [];
114  if ( $cached ) {
115  $includesCachedPages = true;
116  $pageClasses[] = 'mw-specialpagecached';
117  }
118  if ( $restricted ) {
119  $includesRestrictedPages = true;
120  $pageClasses[] = 'mw-specialpagerestricted';
121  }
122 
123  $link = $this->getLinkRenderer()->makeKnownLink( $title, $desc );
124  $out->addHTML( Html::rawElement(
125  'li',
126  [ 'class' => implode( ' ', $pageClasses ) ],
127  $link
128  ) . "\n" );
129  }
130  $out->addHTML(
131  Html::closeElement( 'ul' ) .
132  Html::closeElement( 'div' )
133  );
134  }
135 
136  // add legend
137  $notes = [];
138  if ( $includesRestrictedPages ) {
139  $restricedMsg = $this->msg( 'specialpages-note-restricted' );
140  if ( !$restricedMsg->isDisabled() ) {
141  $notes[] = $restricedMsg->plain();
142  }
143  }
144  if ( $includesCachedPages ) {
145  $cachedMsg = $this->msg( 'specialpages-note-cached' );
146  if ( !$cachedMsg->isDisabled() ) {
147  $notes[] = $cachedMsg->plain();
148  }
149  }
150  if ( $notes !== [] ) {
151  $out->wrapWikiMsg(
152  "<h2 class=\"mw-specialpages-note-top\">$1</h2>", 'specialpages-note-top'
153  );
154  $out->wrapWikiTextAsInterface(
155  'mw-specialpages-notes',
156  implode( "\n", $notes )
157  );
158  }
159  }
160 }
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
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:785
Shortcut to construct a special page which is unlisted by default.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing &#39;/&#39;...
Definition: Html.php:252
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:210
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
Definition: injection.txt:23
getOutput()
Get the OutputPage being used for this instance.
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:3043
A special page that lists special pages.
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:310
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:936
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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
getUser()
Shortcut to get the User executing this instance.
msg( $key)
Wrapper around wfMessage that sets the current context.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...