Merge "Disallow top level domains in Cookie::validateCookieDomain()."
[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 /** @var SpecialPage $page */
64 foreach ( $pages as $page ) {
65 if ( $page->isListed() ) {
66 $group = $page->getFinalGroupName();
67 if ( !isset( $groups[$group] ) ) {
68 $groups[$group] = array();
69 }
70 $groups[$group][$page->getDescription()] = array(
71 $page->getPageTitle(),
72 $page->isRestricted(),
73 $page->isCached()
74 );
75 }
76 }
77
78 /** Sort */
79 if ( $wgSortSpecialPages ) {
80 foreach ( $groups as $group => $sortedPages ) {
81 ksort( $groups[$group] );
82 }
83 }
84
85 /** Always move "other" to end */
86 if ( array_key_exists( 'other', $groups ) ) {
87 $other = $groups['other'];
88 unset( $groups['other'] );
89 $groups['other'] = $other;
90 }
91
92 return $groups;
93 }
94
95 private function outputPageList( $groups ) {
96 $out = $this->getOutput();
97
98 $includesRestrictedPages = false;
99 $includesCachedPages = false;
100
101 foreach ( $groups as $group => $sortedPages ) {
102 $total = count( $sortedPages );
103 $middle = ceil( $total / 2 );
104 $count = 0;
105
106 $out->wrapWikiMsg(
107 "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n",
108 "specialpages-group-$group"
109 );
110 $out->addHTML(
111 Html::openElement(
112 'table',
113 array( 'style' => 'width:100%;', 'class' => 'mw-specialpages-table' )
114 ) . "\n" .
115 Html::openElement( 'tr' ) . "\n" .
116 Html::openElement( 'td', array( 'style' => 'width:30%;vertical-align:top' ) ) . "\n" .
117 Html::openElement( 'ul' ) . "\n"
118 );
119 foreach ( $sortedPages as $desc => $specialpage ) {
120 list( $title, $restricted, $cached ) = $specialpage;
121
122 $pageClasses = array();
123 if ( $cached ) {
124 $includesCachedPages = true;
125 $pageClasses[] = 'mw-specialpagecached';
126 }
127 if ( $restricted ) {
128 $includesRestrictedPages = true;
129 $pageClasses[] = 'mw-specialpagerestricted';
130 }
131
132 $link = Linker::linkKnown( $title, htmlspecialchars( $desc ) );
133 $out->addHTML( Html::rawElement(
134 'li',
135 array( 'class' => implode( ' ', $pageClasses ) ),
136 $link
137 ) . "\n" );
138
139 # Split up the larger groups
140 $count++;
141 if ( $total > 3 && $count == $middle ) {
142 $out->addHTML(
143 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
144 Html::element( 'td', array( 'style' => 'width:10%' ), '' ) .
145 Html::openElement( 'td', array( 'style' => 'width:30%' ) ) . Html::openElement( 'ul' ) . "\n"
146 );
147 }
148 }
149 $out->addHTML(
150 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
151 Html::element( 'td', array( 'style' => 'width:30%' ), '' ) .
152 Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n"
153 );
154 }
155
156 if ( $includesRestrictedPages || $includesCachedPages ) {
157 $out->wrapWikiMsg( "<h2 class=\"mw-specialpages-note-top\">$1</h2>", 'specialpages-note-top' );
158 $out->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
159 }
160 }
161 }