MediaWiki master
SpecialSpecialPages.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Specials;
22
27use OOUI\FieldLayout;
28use OOUI\SearchInputWidget;
29
36
37 public function __construct() {
38 parent::__construct( 'Specialpages' );
39 }
40
41 public function execute( $par ) {
42 $out = $this->getOutput();
43 $this->setHeaders();
44 $this->outputHeader();
45 $out->getMetadata()->setPreventClickjacking( false );
46 $out->addModuleStyles( 'mediawiki.special' );
47
48 $groups = $this->getSpecialPages();
49
50 if ( $groups === false ) {
51 return;
52 }
53
54 $this->addHelpLink( 'Help:Special pages' );
55 $this->outputPageList( $groups );
56 }
57
59 private function getSpecialPages() {
60 $pages = $this->getSpecialPageFactory()->getUsablePages( $this->getUser() );
61
62 if ( $pages === [] ) {
63 // Yeah, that was pointless. Thanks for coming.
64 return false;
65 }
66
67 // Put them into a sortable array
68 $specialPages = [];
69 foreach ( $pages as $page ) {
70 $group = $page->getFinalGroupName();
71 $desc = $page->getDescription();
72 // T343849
73 if ( is_string( $desc ) ) {
74 wfDeprecated( "string return from {$page->getName()}::getDescription()", '1.41' );
75 $desc = ( new RawMessage( '$1' ) )->rawParams( $desc );
76 }
77 // (T360723) Only show an entry if the message isn't blanked, to allow on-wiki unlisting
78 if ( !$desc->isDisabled() ) {
79 $specialPages[$desc->text()] = [
80 $page->getPageTitle(),
81 $page->isRestricted(),
82 $page->isCached(),
83 $group
84 ];
85 }
86 }
87
88 // Sort by group
89 uasort( $specialPages, static fn ( $a, $b ) => $a[3] <=> $b[3] );
90
91 return $specialPages;
92 }
93
94 private function outputPageList( array $specialPages ) {
95 $out = $this->getOutput();
96 $aliases = $this->getSpecialPageFactory()->getAliasList();
97 $out->addModuleStyles( [ 'codex-styles' ] );
98 $out->addModules( 'mediawiki.special.specialpages' );
99 $out->enableOOUI();
100
101 $includesRestrictedPages = false;
102 foreach ( $specialPages as $desc => [ $title, $restricted, $cached, $group ] ) {
103 if ( $restricted ) {
104 $includesRestrictedPages = true;
105 break;
106 }
107 }
108
109 if ( $includesRestrictedPages ) {
110 $legend = Html::rawElement(
111 'div',
112 [ 'class' => [ 'cdx-card', 'mw-special-pages-legend' ] ],
114 'div',
115 [ 'class' => [ 'cdx-card__text' ] ],
116 $this->msg( 'specialpages-access-restricted-note' )->text()
117 )
118 );
119 $out->addHTML( $legend );
120 }
121
122 $out->addHTML(
123 Html::openElement( 'div', [ 'class' => 'cdx-table' ] ) .
124 Html::openElement( 'div', [ 'class' => 'cdx-table__header' ] )
125 );
126 // Headers
127 $out->addHTML( new FieldLayout(
128 new SearchInputWidget( [
129 'placeholder' => $this->msg( 'specialpages-header-search' )->text(),
130 ] ),
131 [
132 'classes' => [ 'mw-special-pages-search' ],
133 'label' => $this->msg( 'specialpages-header-search' )->text(),
134 'invisibleLabel' => true,
135 'infusable' => true,
136 ]
137 ) );
138 // Open table elements
139 $out->addHTML(
140 Html::closeElement( 'div' ) .
141 Html::openElement( 'div', [ 'class' => 'cdx-table__table-wrapper' ] ) .
142 Html::openElement( 'table', [ 'class' => 'cdx-table__table sortable' ] )
143 );
144 // Add table header
145 $accessHeader = $includesRestrictedPages ?
146 Html::element( 'th', [], $this->msg( 'specialpages-header-access' )->text() ) : '';
147 $out->addHTML(
148 Html::openElement( 'thead' ) .
149 Html::openElement( 'tr' ) .
150 Html::element( 'th', [], $this->msg( 'specialpages-header-name' )->text() ) .
151 Html::element( 'th', [], $this->msg( 'specialpages-header-category' )->text() ) .
152 $accessHeader .
153 Html::closeElement( 'tr' ) .
154 Html::closeElement( 'thead' ) .
155 Html::openElement( 'tbody' )
156 );
157 // Format contents
158 $language = $this->getLanguage();
159 foreach ( $specialPages as $desc => [ $title, $restricted, $cached, $group ] ) {
160 $indexAttr = [ 'data-search-index-0' => $language->lc( $title->getText() ) ];
161 $c = 1;
162 foreach ( $aliases as $alias => $target ) {
164 if ( $target == $title->getText() && $language->lc( $alias ) !== $language->lc( $title->getText() ) ) {
165 $indexAttr['data-search-index-' . $c ] = $language->lc( $alias );
166 ++$c;
167 }
168 }
169 if ( str_contains( $group, '/' ) ) {
170 [ $group, $subGroup ] = explode( '/', $group, 2 );
171 $groupName = $this->msg( "specialpages-group-$group-$subGroup" )->text();
172 } else {
173 $groupName = $this->msg( "specialpages-group-$group" )->text();
174 }
175 $rowClasses = [ 'mw-special-pages-search-highlight', 'mw-special-pages-row' ];
176 if ( $includesRestrictedPages ) {
177 if ( $restricted === true ) {
178 $rowClasses[] = 'mw-special-pages-row-restricted';
179 $accessMessageKey = 'specialpages-access-restricted';
180 } else {
181 $accessMessageKey = 'specialpages-access-public';
182 }
183 $accessCell = Html::element( 'td', [], $this->msg( $accessMessageKey )->text() );
184 } else {
185 $accessCell = '';
186 }
187 $out->addHTML(
188 Html::openElement( 'tr', $indexAttr + [ 'class' => $rowClasses ] ) .
189 Html::rawElement(
190 'td',
191 [ 'class' => 'mw-special-pages-name' ],
192 $this->getLinkRenderer()->makeKnownLink( $title, $desc )
193 ) .
194 Html::element( 'td', [], $groupName ) .
195 $accessCell .
196 Html::closeElement( 'tr' )
197 );
198 }
199
200 $out->addHTML(
201 Html::closeElement( 'tbody' ) .
202 Html::closeElement( 'table' ) .
203 Html::closeElement( 'div' ) .
204 Html::closeElement( 'div' )
205 );
206 }
207}
208
213class_alias( SpecialSpecialPages::class, 'SpecialSpecialpages' );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
This class is a collection of static functions that serve two purposes:
Definition Html.php:57
Variant of the Message class.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getUser()
Shortcut to get the User executing this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getLanguage()
Shortcut to get user's language.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Shortcut to construct a special page which is unlisted by default.
A special page that lists special pages.
execute( $par)
Default execute method Checks user permissions.
Represents a title within MediaWiki.
Definition Title.php:78
element(SerializerNode $parent, SerializerNode $node, $contents)