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