1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
<?php
/**
* Implements Special:Specialpages
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup SpecialPage
*/
/**
* A special page that lists special pages
*
* @ingroup SpecialPage
*/
class SpecialSpecialpages extends UnlistedSpecialPage {
function __construct() {
parent::__construct( 'Specialpages' );
}
function execute( $par ) {
$out = $this->getOutput();
$this->setHeaders();
$this->outputHeader();
$out->allowClickjacking();
$out->addModuleStyles( 'mediawiki.special' );
$groups = $this->getPageGroups();
if ( $groups === false ) {
return;
}
$this->outputPageList( $groups );
}
private function getPageGroups() {
global $wgSortSpecialPages;
$pages = SpecialPageFactory::getUsablePages( $this->getUser() );
if ( !count( $pages ) ) {
# Yeah, that was pointless. Thanks for coming.
return false;
}
/** Put them into a sortable array */
$groups = array();
/** @var SpecialPage $page */
foreach ( $pages as $page ) {
if ( $page->isListed() ) {
$group = $page->getFinalGroupName();
if ( !isset( $groups[$group] ) ) {
$groups[$group] = array();
}
$groups[$group][$page->getDescription()] = array(
$page->getTitle(),
$page->isRestricted(),
$page->isCached()
);
}
}
/** Sort */
if ( $wgSortSpecialPages ) {
foreach ( $groups as $group => $sortedPages ) {
ksort( $groups[$group] );
}
}
/** Always move "other" to end */
if ( array_key_exists( 'other', $groups ) ) {
$other = $groups['other'];
unset( $groups['other'] );
$groups['other'] = $other;
}
return $groups;
}
private function outputPageList( $groups ) {
$out = $this->getOutput();
$includesRestrictedPages = false;
$includesCachedPages = false;
foreach ( $groups as $group => $sortedPages ) {
$total = count( $sortedPages );
$middle = ceil( $total / 2 );
$count = 0;
$out->wrapWikiMsg( "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n", "specialpages-group-$group" );
$out->addHTML(
Html::openElement( 'table', array( 'style' => 'width:100%;', 'class' => 'mw-specialpages-table' ) ) . "\n" .
Html::openElement( 'tr' ) . "\n" .
Html::openElement( 'td', array( 'style' => 'width:30%;vertical-align:top' ) ) . "\n" .
Html::openElement( 'ul' ) . "\n"
);
foreach ( $sortedPages as $desc => $specialpage ) {
list( $title, $restricted, $cached ) = $specialpage;
$pageClasses = array();
if ( $cached ) {
$includesCachedPages = true;
$pageClasses[] = 'mw-specialpagecached';
}
if ( $restricted ) {
$includesRestrictedPages = true;
$pageClasses[] = 'mw-specialpagerestricted';
}
$link = Linker::linkKnown( $title, htmlspecialchars( $desc ) );
$out->addHTML( Html::rawElement( 'li', array( 'class' => implode( ' ', $pageClasses ) ), $link ) . "\n" );
# Split up the larger groups
$count++;
if ( $total > 3 && $count == $middle ) {
$out->addHTML(
Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
Html::element( 'td', array( 'style' => 'width:10%' ), '' ) .
Html::openElement( 'td', array( 'style' => 'width:30%' ) ) . Html::openElement( 'ul' ) . "\n"
);
}
}
$out->addHTML(
Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
Html::element( 'td', array( 'style' => 'width:30%' ), '' ) .
Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n"
);
}
if ( $includesRestrictedPages || $includesCachedPages ) {
$out->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
}
}
}
|