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