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