invert without namespace doesn't do anything, so ignore it
[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 $this->setHeaders();
37 $this->outputHeader();
38
39 $groups = $this->getPageGroups();
40
41 if ( $groups === false ) {
42 return;
43 }
44
45 $this->outputPageList( $groups );
46 }
47
48 private function getPageGroups() {
49 global $wgSortSpecialPages;
50
51 $pages = SpecialPage::getUsablePages();
52
53 if( !count( $pages ) ) {
54 # Yeah, that was pointless. Thanks for coming.
55 return false;
56 }
57
58 /** Put them into a sortable array */
59 $groups = array();
60 foreach ( $pages as $page ) {
61 if ( $page->isListed() ) {
62 $group = SpecialPage::getGroup( $page );
63 if( !isset( $groups[$group] ) ) {
64 $groups[$group] = array();
65 }
66 $groups[$group][$page->getDescription()] = array( $page->getTitle(), $page->isRestricted() );
67 }
68 }
69
70 /** Sort */
71 if ( $wgSortSpecialPages ) {
72 foreach( $groups as $group => $sortedPages ) {
73 ksort( $groups[$group] );
74 }
75 }
76
77 /** Always move "other" to end */
78 if( array_key_exists( 'other', $groups ) ) {
79 $other = $groups['other'];
80 unset( $groups['other'] );
81 $groups['other'] = $other;
82 }
83
84 return $groups;
85 }
86
87 private function outputPageList( $groups ) {
88 global $wgUser, $wgOut;
89
90 $sk = $wgUser->getSkin();
91 $includesRestrictedPages = false;
92
93 foreach ( $groups as $group => $sortedPages ) {
94 $middle = ceil( count( $sortedPages )/2 );
95 $total = count( $sortedPages );
96 $count = 0;
97
98 $wgOut->wrapWikiMsg( "<h4 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h4>\n", "specialpages-group-$group" );
99 $wgOut->addHTML(
100 Html::openElement( 'table', array( 'style' => 'width:100%;', 'class' => 'mw-specialpages-table' ) ) ."\n" .
101 Html::openElement( 'tr' ) . "\n" .
102 Html::openElement( 'td', array( 'style' => 'width:30%;vertical-align:top' ) ) . "\n" .
103 Html::openElement( 'ul' ) . "\n"
104 );
105 foreach( $sortedPages as $desc => $specialpage ) {
106 list( $title, $restricted ) = $specialpage;
107 $link = $sk->linkKnown( $title , htmlspecialchars( $desc ) );
108 if( $restricted ) {
109 $includesRestrictedPages = true;
110 $wgOut->addHTML( Html::rawElement( 'li', array( 'class' => 'mw-specialpages-page mw-specialpagerestricted' ), Html::rawElement( 'strong', array(), $link ) ) . "\n" );
111 } else {
112 $wgOut->addHTML( Html::rawElement( 'li', array(), $link ) . "\n" );
113 }
114
115 # Split up the larger groups
116 $count++;
117 if( $total > 3 && $count == $middle ) {
118 $wgOut->addHTML(
119 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
120 Html::element( 'td', array( 'style' => 'width:10%' ), '' ) .
121 Html::openElement( 'td', array( 'style' => 'width:30%' ) ) . Html::openElement( 'ul' ) . "\n"
122 );
123 }
124 }
125 $wgOut->addHTML(
126 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
127 Html::element( 'td', array( 'style' => 'width:30%' ), '' ) .
128 Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n"
129 );
130 }
131
132 if ( $includesRestrictedPages ) {
133 $wgOut->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
134 }
135 }
136 }