Merge "mediawiki.special.preferences: Support Back/Forward navigation"
[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( $page->getTitle(), $page->isRestricted(), $page->isExpensive() );
70 }
71 }
72
73 /** Sort */
74 if ( $wgSortSpecialPages ) {
75 foreach( $groups as $group => $sortedPages ) {
76 ksort( $groups[$group] );
77 }
78 }
79
80 /** Always move "other" to end */
81 if( array_key_exists( 'other', $groups ) ) {
82 $other = $groups['other'];
83 unset( $groups['other'] );
84 $groups['other'] = $other;
85 }
86
87 return $groups;
88 }
89
90 private function outputPageList( $groups ) {
91 global $wgMiserMode;
92 $out = $this->getOutput();
93
94 $includesRestrictedPages = false;
95 $includesCachedPages = false;
96
97 foreach ( $groups as $group => $sortedPages ) {
98 $middle = ceil( count( $sortedPages )/2 );
99 $total = count( $sortedPages );
100 $count = 0;
101
102 $out->wrapWikiMsg( "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n", "specialpages-group-$group" );
103 $out->addHTML(
104 Html::openElement( 'table', array( 'style' => 'width:100%;', 'class' => 'mw-specialpages-table' ) ) ."\n" .
105 Html::openElement( 'tr' ) . "\n" .
106 Html::openElement( 'td', array( 'style' => 'width:30%;vertical-align:top' ) ) . "\n" .
107 Html::openElement( 'ul' ) . "\n"
108 );
109 foreach( $sortedPages as $desc => $specialpage ) {
110 list( $title, $restricted, $expensive) = $specialpage;
111
112 $pageClasses = array();
113 if ( $expensive && $wgMiserMode ){
114 $includesCachedPages = true;
115 $pageClasses[] = 'mw-specialpagecached';
116 }
117 if( $restricted ) {
118 $includesRestrictedPages = true;
119 $pageClasses[] = 'mw-specialpagerestricted';
120 }
121
122 $link = Linker::linkKnown( $title , htmlspecialchars( $desc ) );
123 $out->addHTML( Html::rawElement( 'li', array( 'class' => implode( ' ', $pageClasses ) ), $link ) . "\n" );
124
125 # Split up the larger groups
126 $count++;
127 if( $total > 3 && $count == $middle ) {
128 $out->addHTML(
129 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
130 Html::element( 'td', array( 'style' => 'width:10%' ), '' ) .
131 Html::openElement( 'td', array( 'style' => 'width:30%' ) ) . Html::openElement( 'ul' ) . "\n"
132 );
133 }
134 }
135 $out->addHTML(
136 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
137 Html::element( 'td', array( 'style' => 'width:30%' ), '' ) .
138 Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n"
139 );
140 }
141
142 if ( $includesRestrictedPages || $includesCachedPages ) {
143 $out->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
144 }
145 }
146 }