3 * Implements Special:Specialpages
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.
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.
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
21 * @ingroup SpecialPage
25 * A special page that lists special pages
27 * @ingroup SpecialPage
29 class SpecialSpecialpages
extends UnlistedSpecialPage
{
31 function __construct() {
32 parent
::__construct( 'Specialpages' );
35 function execute( $par ) {
36 $out = $this->getOutput();
38 $this->outputHeader();
39 $out->allowClickjacking();
40 $out->addModuleStyles( 'mediawiki.special' );
42 $groups = $this->getPageGroups();
44 if ( $groups === false ) {
48 $this->addHelpLink( 'Help:Special pages' );
49 $this->outputPageList( $groups );
52 private function getPageGroups() {
53 $pages = SpecialPageFactory
::getUsablePages( $this->getUser() );
55 if ( !count( $pages ) ) {
56 # Yeah, that was pointless. Thanks for coming.
60 /** Put them into a sortable array */
62 /** @var SpecialPage $page */
63 foreach ( $pages as $page ) {
64 if ( $page->isListed() ) {
65 $group = $page->getFinalGroupName();
66 if ( !isset( $groups[$group] ) ) {
67 $groups[$group] = array();
69 $groups[$group][$page->getDescription()] = array(
70 $page->getPageTitle(),
71 $page->isRestricted(),
78 foreach ( $groups as $group => $sortedPages ) {
79 ksort( $groups[$group] );
82 /** Always move "other" to end */
83 if ( array_key_exists( 'other', $groups ) ) {
84 $other = $groups['other'];
85 unset( $groups['other'] );
86 $groups['other'] = $other;
92 private function outputPageList( $groups ) {
93 $out = $this->getOutput();
95 $includesRestrictedPages = false;
96 $includesCachedPages = false;
98 foreach ( $groups as $group => $sortedPages ) {
101 "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n",
102 "specialpages-group-$group"
105 Html
::openElement( 'div', array( 'class' => 'mw-specialpages-list' ) )
108 foreach ( $sortedPages as $desc => $specialpage ) {
109 list( $title, $restricted, $cached ) = $specialpage;
111 $pageClasses = array();
113 $includesCachedPages = true;
114 $pageClasses[] = 'mw-specialpagecached';
117 $includesRestrictedPages = true;
118 $pageClasses[] = 'mw-specialpagerestricted';
121 $link = Linker
::linkKnown( $title, htmlspecialchars( $desc ) );
122 $out->addHTML( Html
::rawElement(
124 array( 'class' => implode( ' ', $pageClasses ) ),
129 Html
::closeElement( 'ul' ) .
130 Html
::closeElement( 'div' )
134 if ( $includesRestrictedPages ||
$includesCachedPages ) {
135 $out->wrapWikiMsg( "<h2 class=\"mw-specialpages-note-top\">$1</h2>", 'specialpages-note-top' );
136 $out->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );