MediaWiki  master
SpecialSpecialpages.php
Go to the documentation of this file.
1 <?php
25 
32 
35 
40  parent::__construct( 'Specialpages' );
41  $this->specialPageFactory = $specialPageFactory;
42  }
43 
44  public function execute( $par ) {
45  $out = $this->getOutput();
46  $this->setHeaders();
47  $this->outputHeader();
48  $out->allowClickjacking();
49  $out->addModuleStyles( 'mediawiki.special' );
50 
51  $groups = $this->getPageGroups();
52 
53  if ( $groups === false ) {
54  return;
55  }
56 
57  $this->addHelpLink( 'Help:Special pages' );
58  $this->outputPageList( $groups );
59  }
60 
61  private function getPageGroups() {
62  $pages = $this->specialPageFactory->getUsablePages( $this->getUser() );
63 
64  if ( $pages === [] ) {
65  # Yeah, that was pointless. Thanks for coming.
66  return false;
67  }
68 
70  $groups = [];
72  foreach ( $pages as $page ) {
73  if ( $page->isListed() ) {
74  $group = $page->getFinalGroupName();
75  if ( !isset( $groups[$group] ) ) {
76  $groups[$group] = [];
77  }
78  $groups[$group][$page->getDescription()] = [
79  $page->getPageTitle(),
80  $page->isRestricted(),
81  $page->isCached()
82  ];
83  }
84  }
85 
87  foreach ( $groups as $group => $sortedPages ) {
88  ksort( $groups[$group] );
89  }
90 
92  if ( array_key_exists( 'other', $groups ) ) {
93  $other = $groups['other'];
94  unset( $groups['other'] );
95  $groups['other'] = $other;
96  }
97 
98  return $groups;
99  }
100 
101  private function outputPageList( $groups ) {
102  $out = $this->getOutput();
103 
104  $includesRestrictedPages = false;
105  $includesCachedPages = false;
106 
107  foreach ( $groups as $group => $sortedPages ) {
108  if ( strpos( $group, '/' ) !== false ) {
109  list( $group, $subGroup ) = explode( '/', $group, 2 );
110  $out->wrapWikiMsg(
111  "<h3 class=\"mw-specialpagessubgroup\">$1</h3>\n",
112  "specialpages-group-$group-$subGroup"
113  );
114  } else {
115  $out->wrapWikiMsg(
116  "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n",
117  "specialpages-group-$group"
118  );
119  }
120  $out->addHTML(
121  Html::openElement( 'div', [ 'class' => 'mw-specialpages-list' ] )
122  . '<ul>'
123  );
124  foreach ( $sortedPages as $desc => $specialpage ) {
125  list( $title, $restricted, $cached ) = $specialpage;
126 
127  $pageClasses = [];
128  if ( $cached ) {
129  $includesCachedPages = true;
130  $pageClasses[] = 'mw-specialpagecached';
131  }
132  if ( $restricted ) {
133  $includesRestrictedPages = true;
134  $pageClasses[] = 'mw-specialpagerestricted';
135  }
136 
137  $link = $this->getLinkRenderer()->makeKnownLink( $title, $desc );
138  $out->addHTML( Html::rawElement(
139  'li',
140  [ 'class' => $pageClasses ],
141  $link
142  ) . "\n" );
143  }
144  $out->addHTML(
145  Html::closeElement( 'ul' ) .
146  Html::closeElement( 'div' )
147  );
148  }
149 
150  // add legend
151  $notes = [];
152  if ( $includesRestrictedPages ) {
153  $restricedMsg = $this->msg( 'specialpages-note-restricted' );
154  if ( !$restricedMsg->isDisabled() ) {
155  $notes[] = $restricedMsg->plain();
156  }
157  }
158  if ( $includesCachedPages ) {
159  $cachedMsg = $this->msg( 'specialpages-note-cached' );
160  if ( !$cachedMsg->isDisabled() ) {
161  $notes[] = $cachedMsg->plain();
162  }
163  }
164  if ( $notes !== [] ) {
165  $out->wrapWikiMsg(
166  "<h2 class=\"mw-specialpages-note-top\">$1</h2>", 'specialpages-note-top'
167  );
168  $out->wrapWikiTextAsInterface(
169  'mw-specialpages-notes',
170  implode( "\n", $notes )
171  );
172  }
173  }
174 }
SpecialPage\msg
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:827
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:743
UnlistedSpecialPage
Shortcut to construct a special page which is unlisted by default.
Definition: UnlistedSpecialPage.php:31
MediaWiki\SpecialPage\SpecialPageFactory
Factory for handling the special page list and generating SpecialPage objects.
Definition: SpecialPageFactory.php:61
SpecialSpecialpages\getPageGroups
getPageGroups()
Definition: SpecialSpecialpages.php:61
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:315
SpecialPage\addHelpLink
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition: SpecialPage.php:863
SpecialSpecialpages\__construct
__construct(SpecialPageFactory $specialPageFactory)
Definition: SpecialSpecialpages.php:39
SpecialSpecialpages\$specialPageFactory
SpecialPageFactory $specialPageFactory
Definition: SpecialSpecialpages.php:34
SpecialSpecialpages\outputPageList
outputPageList( $groups)
Definition: SpecialSpecialpages.php:101
$title
$title
Definition: testCompression.php:38
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!...
Definition: SpecialPage.php:571
SpecialPage\getUser
getUser()
Shortcut to get the User executing this instance.
Definition: SpecialPage.php:753
SpecialSpecialpages
A special page that lists special pages.
Definition: SpecialSpecialpages.php:31
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:41
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:944
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:251
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
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:662
SpecialSpecialpages\execute
execute( $par)
Default execute method Checks user permissions.
Definition: SpecialSpecialpages.php:44