Merge "Making missing old files not try to render a thumbnail"
[lhc/web/wiklou.git] / includes / specials / SpecialSpecialpages.php
1 <?php
2 /**
3 * Implements Special:Specialpages
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page that lists special pages
26 *
27 * @ingroup SpecialPage
28 */
29 class SpecialSpecialpages extends UnlistedSpecialPage {
30
31 function __construct() {
32 parent::__construct( 'Specialpages' );
33 }
34
35 function execute( $par ) {
36 $out = $this->getOutput();
37 $this->setHeaders();
38 $this->outputHeader();
39 $out->allowClickjacking();
40 $out->addModuleStyles( 'mediawiki.special' );
41
42 $groups = $this->getPageGroups();
43
44 if ( $groups === false ) {
45 return;
46 }
47
48 $this->outputPageList( $groups );
49 }
50
51 private function getPageGroups() {
52 $pages = SpecialPageFactory::getUsablePages( $this->getUser() );
53
54 if ( !count( $pages ) ) {
55 # Yeah, that was pointless. Thanks for coming.
56 return false;
57 }
58
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();
67 }
68 $groups[$group][$page->getDescription()] = array(
69 $page->getPageTitle(),
70 $page->isRestricted(),
71 $page->isCached()
72 );
73 }
74 }
75
76 /** Sort */
77 foreach ( $groups as $group => $sortedPages ) {
78 ksort( $groups[$group] );
79 }
80
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;
86 }
87
88 return $groups;
89 }
90
91 private function outputPageList( $groups ) {
92 $out = $this->getOutput();
93
94 $includesRestrictedPages = false;
95 $includesCachedPages = false;
96
97 foreach ( $groups as $group => $sortedPages ) {
98 $total = count( $sortedPages );
99 $middle = ceil( $total / 2 );
100 $count = 0;
101
102 $out->wrapWikiMsg(
103 "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n",
104 "specialpages-group-$group"
105 );
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"
114 );
115 foreach ( $sortedPages as $desc => $specialpage ) {
116 list( $title, $restricted, $cached ) = $specialpage;
117
118 $pageClasses = array();
119 if ( $cached ) {
120 $includesCachedPages = true;
121 $pageClasses[] = 'mw-specialpagecached';
122 }
123 if ( $restricted ) {
124 $includesRestrictedPages = true;
125 $pageClasses[] = 'mw-specialpagerestricted';
126 }
127
128 $link = Linker::linkKnown( $title, htmlspecialchars( $desc ) );
129 $out->addHTML( Html::rawElement(
130 'li',
131 array( 'class' => implode( ' ', $pageClasses ) ),
132 $link
133 ) . "\n" );
134
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"
142 );
143 }
144 }
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"
149 );
150 }
151
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' );
155 }
156 }
157 }