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.
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.
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
22 * @ingroup SpecialPage
24 class SpecialSpecialpages
extends UnlistedSpecialPage
{
26 function __construct() {
27 parent
::__construct( 'Specialpages' );
30 function execute( $par ) {
32 $this->outputHeader();
34 $groups = $this->getPageGroups();
36 if ( $groups === false ) {
40 $this->outputPageList( $groups );
43 private function getPageGroups() {
44 global $wgSortSpecialPages;
46 $pages = SpecialPage
::getUsablePages();
48 if( !count( $pages ) ) {
49 # Yeah, that was pointless. Thanks for coming.
53 /** Put them into a sortable array */
55 foreach ( $pages as $page ) {
56 if ( $page->isListed() ) {
57 $group = SpecialPage
::getGroup( $page );
58 if( !isset( $groups[$group] ) ) {
59 $groups[$group] = array();
61 $groups[$group][$page->getDescription()] = array( $page->getTitle(), $page->isRestricted() );
66 if ( $wgSortSpecialPages ) {
67 foreach( $groups as $group => $sortedPages ) {
68 ksort( $groups[$group] );
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;
82 private function outputPageList( $groups ) {
83 global $wgUser, $wgOut;
85 $sk = $wgUser->getSkin();
86 $includesRestrictedPages = false;
88 foreach ( $groups as $group => $sortedPages ) {
89 $middle = ceil( count( $sortedPages )/2 );
90 $total = count( $sortedPages );
93 $wgOut->wrapWikiMsg( "<h4 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h4>\n", "specialpages-group-$group" );
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"
100 foreach( $sortedPages as $desc => $specialpage ) {
101 list( $title, $restricted ) = $specialpage;
102 $link = $sk->linkKnown( $title , htmlspecialchars( $desc ) );
104 $includesRestrictedPages = true;
105 $wgOut->addHTML( Html
::rawElement( 'li', array( 'class' => 'mw-specialpages-page mw-specialpagerestricted' ), Html
::rawElement( 'strong', array(), $link ) ) . "\n" );
107 $wgOut->addHTML( Html
::rawElement( 'li', array(), $link ) . "\n" );
110 # Split up the larger groups
112 if( $total > 3 && $count == $middle ) {
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"
121 Html
::closeElement( 'ul' ) . Html
::closeElement( 'td' ) .
122 Html
::element( 'td', array( 'style' => 'width:30%' ), '' ) .
123 Html
::closeElement( 'tr' ) . Html
::closeElement( 'table' ) . "\n"
127 if ( $includesRestrictedPages ) {
128 $wgOut->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );