d80218fe25bdff94b11b804e051f1bbeb42e3871
[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 global $wgSortSpecialPages;
53
54 $pages = SpecialPageFactory::getUsablePages( $this->getUser() );
55
56 if( !count( $pages ) ) {
57 # Yeah, that was pointless. Thanks for coming.
58 return false;
59 }
60
61 /** Put them into a sortable array */
62 $groups = array();
63 foreach ( $pages as $page ) {
64 if ( $page->isListed() ) {
65 $group = SpecialPageFactory::getGroup( $page );
66 if( !isset( $groups[$group] ) ) {
67 $groups[$group] = array();
68 }
69 $groups[$group][$page->getDescription()] = array(
70 $page->getTitle(),
71 $page->isRestricted(),
72 $page->isCached()
73 );
74 }
75 }
76
77 /** Sort */
78 if ( $wgSortSpecialPages ) {
79 foreach( $groups as $group => $sortedPages ) {
80 ksort( $groups[$group] );
81 }
82 }
83
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;
89 }
90
91 return $groups;
92 }
93
94 private function outputPageList( $groups ) {
95 $out = $this->getOutput();
96
97 $includesRestrictedPages = false;
98 $includesCachedPages = false;
99
100 foreach ( $groups as $group => $sortedPages ) {
101 $total = count( $sortedPages );
102 $middle = ceil( $total / 2 );
103 $count = 0;
104
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"
111 );
112 foreach( $sortedPages as $desc => $specialpage ) {
113 list( $title, $restricted, $cached ) = $specialpage;
114
115 $pageClasses = array();
116 if ( $cached ) {
117 $includesCachedPages = true;
118 $pageClasses[] = 'mw-specialpagecached';
119 }
120 if( $restricted ) {
121 $includesRestrictedPages = true;
122 $pageClasses[] = 'mw-specialpagerestricted';
123 }
124
125 $link = Linker::linkKnown( $title, htmlspecialchars( $desc ) );
126 $out->addHTML( Html::rawElement( 'li', array( 'class' => implode( ' ', $pageClasses ) ), $link ) . "\n" );
127
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"
135 );
136 }
137 }
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"
142 );
143 }
144
145 if ( $includesRestrictedPages || $includesCachedPages ) {
146 $out->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
147 }
148 }
149 }