GPL Headers for all!
[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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20 /**
21 * @file
22 * @ingroup SpecialPage
23 */
24
25 function wfSpecialSpecialpages() {
26 global $wgOut, $wgUser, $wgMessageCache, $wgSortSpecialPages;
27
28 $wgMessageCache->loadAllMessages();
29
30 $wgOut->setRobotPolicy( 'noindex,nofollow' ); # Is this really needed?
31 $sk = $wgUser->getSkin();
32
33 $pages = SpecialPage::getUsablePages();
34
35 if( count( $pages ) == 0 ) {
36 # Yeah, that was pointless. Thanks for coming.
37 return;
38 }
39
40 /** Put them into a sortable array */
41 $groups = array();
42 foreach ( $pages as $page ) {
43 if ( $page->isListed() ) {
44 $group = SpecialPage::getGroup( $page );
45 if( !isset($groups[$group]) ) {
46 $groups[$group] = array();
47 }
48 $groups[$group][$page->getDescription()] = array( $page->getTitle(), $page->isRestricted() );
49 }
50 }
51
52 /** Sort */
53 if ( $wgSortSpecialPages ) {
54 foreach( $groups as $group => $sortedPages ) {
55 ksort( $groups[$group] );
56 }
57 }
58
59 /** Always move "other" to end */
60 if( array_key_exists('other',$groups) ) {
61 $other = $groups['other'];
62 unset( $groups['other'] );
63 $groups['other'] = $other;
64 }
65
66 $includesRestrictedPages = false;
67 /** Now output the HTML */
68 foreach ( $groups as $group => $sortedPages ) {
69 $middle = ceil( count($sortedPages)/2 );
70 $total = count($sortedPages);
71 $count = 0;
72
73 $wgOut->wrapWikiMsg( "<h4 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h4>\n", "specialpages-group-$group" );
74 $wgOut->addHTML( "<table style='width: 100%;' class='mw-specialpages-table'><tr>" );
75 $wgOut->addHTML( "<td width='30%' valign='top'><ul>\n" );
76 foreach( $sortedPages as $desc => $specialpage ) {
77 list( $title, $restricted ) = $specialpage;
78 $link = $sk->linkKnown( $title , htmlspecialchars( $desc ) );
79 if( $restricted ) {
80 $includesRestrictedPages = true;
81 $wgOut->addHTML( "<li class='mw-specialpages-page mw-specialpagerestricted'><strong>{$link}</strong></li>\n" );
82 } else {
83 $wgOut->addHTML( "<li>{$link}</li>\n" );
84 }
85
86 # Split up the larger groups
87 $count++;
88 if( $total > 3 && $count == $middle ) {
89 $wgOut->addHTML( "</ul></td><td width='10%'></td><td width='30%' valign='top'><ul>" );
90 }
91 }
92 $wgOut->addHTML( "</ul></td><td width='30%' valign='top'></td></tr></table>\n" );
93 }
94
95 if ( $includesRestrictedPages ) {
96 $wgOut->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
97 }
98 }