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