Consistency tweak: Wrap variable names into <code></code>
[mediawiki.git] / includes / specials / SpecialSpecialpages.php
blob57fffb8494ec54038e0ca85f94bbe0177e9018de
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 global $wgSortSpecialPages;
54 $pages = SpecialPageFactory::getUsablePages( $this->getUser() );
56 if( !count( $pages ) ) {
57 # Yeah, that was pointless. Thanks for coming.
58 return false;
61 /** Put them into a sortable array */
62 $groups = array();
63 foreach ( $pages as $page ) {
64 if ( $page->isListed() ) {
65 $group = $page->getFinalGroupName();
66 if( !isset( $groups[$group] ) ) {
67 $groups[$group] = array();
69 $groups[$group][$page->getDescription()] = array(
70 $page->getTitle(),
71 $page->isRestricted(),
72 $page->isCached()
77 /** Sort */
78 if ( $wgSortSpecialPages ) {
79 foreach( $groups as $group => $sortedPages ) {
80 ksort( $groups[$group] );
84 /** Always move "other" to end */
85 if( array_key_exists( 'other', $groups ) ) {
86 $other = $groups['other'];
87 unset( $groups['other'] );
88 $groups['other'] = $other;
91 return $groups;
94 private function outputPageList( $groups ) {
95 $out = $this->getOutput();
97 $includesRestrictedPages = false;
98 $includesCachedPages = false;
100 foreach ( $groups as $group => $sortedPages ) {
101 $total = count( $sortedPages );
102 $middle = ceil( $total / 2 );
103 $count = 0;
105 $out->wrapWikiMsg( "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n", "specialpages-group-$group" );
106 $out->addHTML(
107 Html::openElement( 'table', array( 'style' => 'width:100%;', 'class' => 'mw-specialpages-table' ) ) ."\n" .
108 Html::openElement( 'tr' ) . "\n" .
109 Html::openElement( 'td', array( 'style' => 'width:30%;vertical-align:top' ) ) . "\n" .
110 Html::openElement( 'ul' ) . "\n"
112 foreach( $sortedPages as $desc => $specialpage ) {
113 list( $title, $restricted, $cached ) = $specialpage;
115 $pageClasses = array();
116 if ( $cached ) {
117 $includesCachedPages = true;
118 $pageClasses[] = 'mw-specialpagecached';
120 if( $restricted ) {
121 $includesRestrictedPages = true;
122 $pageClasses[] = 'mw-specialpagerestricted';
125 $link = Linker::linkKnown( $title, htmlspecialchars( $desc ) );
126 $out->addHTML( Html::rawElement( 'li', array( 'class' => implode( ' ', $pageClasses ) ), $link ) . "\n" );
128 # Split up the larger groups
129 $count++;
130 if( $total > 3 && $count == $middle ) {
131 $out->addHTML(
132 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
133 Html::element( 'td', array( 'style' => 'width:10%' ), '' ) .
134 Html::openElement( 'td', array( 'style' => 'width:30%' ) ) . Html::openElement( 'ul' ) . "\n"
138 $out->addHTML(
139 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
140 Html::element( 'td', array( 'style' => 'width:30%' ), '' ) .
141 Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n"
145 if ( $includesRestrictedPages || $includesCachedPages ) {
146 $out->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );