Implement extension registration from an extension.json file
[mediawiki.git] / includes / specials / SpecialSpecialpages.php
blobeff06f4603ba3b976dab6d43f7a0b6109a8dd43f
1 <?php
2 /**
3 * Implements Special:Specialpages
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * A special page that lists special pages
27 * @ingroup SpecialPage
29 class SpecialSpecialpages extends UnlistedSpecialPage {
31 function __construct() {
32 parent::__construct( 'Specialpages' );
35 function execute( $par ) {
36 $out = $this->getOutput();
37 $this->setHeaders();
38 $this->outputHeader();
39 $out->allowClickjacking();
40 $out->addModuleStyles( 'mediawiki.special' );
42 $groups = $this->getPageGroups();
44 if ( $groups === false ) {
45 return;
48 $this->outputPageList( $groups );
51 private function getPageGroups() {
52 $pages = SpecialPageFactory::getUsablePages( $this->getUser() );
54 if ( !count( $pages ) ) {
55 # Yeah, that was pointless. Thanks for coming.
56 return false;
59 /** Put them into a sortable array */
60 $groups = array();
61 /** @var SpecialPage $page */
62 foreach ( $pages as $page ) {
63 if ( $page->isListed() ) {
64 $group = $page->getFinalGroupName();
65 if ( !isset( $groups[$group] ) ) {
66 $groups[$group] = array();
68 $groups[$group][$page->getDescription()] = array(
69 $page->getPageTitle(),
70 $page->isRestricted(),
71 $page->isCached()
76 /** Sort */
77 foreach ( $groups as $group => $sortedPages ) {
78 ksort( $groups[$group] );
81 /** Always move "other" to end */
82 if ( array_key_exists( 'other', $groups ) ) {
83 $other = $groups['other'];
84 unset( $groups['other'] );
85 $groups['other'] = $other;
88 return $groups;
91 private function outputPageList( $groups ) {
92 $out = $this->getOutput();
94 $includesRestrictedPages = false;
95 $includesCachedPages = false;
97 foreach ( $groups as $group => $sortedPages ) {
98 $total = count( $sortedPages );
99 $middle = ceil( $total / 2 );
100 $count = 0;
102 $out->wrapWikiMsg(
103 "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n",
104 "specialpages-group-$group"
106 $out->addHTML(
107 Html::openElement(
108 'table',
109 array( 'style' => 'width:100%;', 'class' => 'mw-specialpages-table' )
110 ) . "\n" .
111 Html::openElement( 'tr' ) . "\n" .
112 Html::openElement( 'td', array( 'style' => 'width:30%;vertical-align:top' ) ) . "\n" .
113 Html::openElement( 'ul' ) . "\n"
115 foreach ( $sortedPages as $desc => $specialpage ) {
116 list( $title, $restricted, $cached ) = $specialpage;
118 $pageClasses = array();
119 if ( $cached ) {
120 $includesCachedPages = true;
121 $pageClasses[] = 'mw-specialpagecached';
123 if ( $restricted ) {
124 $includesRestrictedPages = true;
125 $pageClasses[] = 'mw-specialpagerestricted';
128 $link = Linker::linkKnown( $title, htmlspecialchars( $desc ) );
129 $out->addHTML( Html::rawElement(
130 'li',
131 array( 'class' => implode( ' ', $pageClasses ) ),
132 $link
133 ) . "\n" );
135 # Split up the larger groups
136 $count++;
137 if ( $total > 3 && $count == $middle ) {
138 $out->addHTML(
139 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
140 Html::element( 'td', array( 'style' => 'width:10%' ), '' ) .
141 Html::openElement( 'td', array( 'style' => 'width:30%' ) ) . Html::openElement( 'ul' ) . "\n"
145 $out->addHTML(
146 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
147 Html::element( 'td', array( 'style' => 'width:30%' ), '' ) .
148 Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n"
152 if ( $includesRestrictedPages || $includesCachedPages ) {
153 $out->wrapWikiMsg( "<h2 class=\"mw-specialpages-note-top\">$1</h2>", 'specialpages-note-top' );
154 $out->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );