Group special pages at Special:SpecialPages
[lhc/web/wiklou.git] / includes / SpecialSpecialpages.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 *
9 */
10 function wfSpecialSpecialpages() {
11 global $wgOut, $wgUser, $wgMessageCache;
12
13 $wgMessageCache->loadAllMessages();
14
15 $wgOut->setRobotpolicy( 'noindex,nofollow' ); # Is this really needed?
16 $sk = $wgUser->getSkin();
17
18 /** Pages available to all */
19 wfSpecialSpecialpages_gen( SpecialPage::getRegularPages(), 'spheading', $sk );
20
21 /** Restricted special pages */
22 wfSpecialSpecialpages_gen( SpecialPage::getRestrictedPages(), 'restrictedpheading', $sk );
23 }
24
25 /**
26 * sub function generating the list of pages
27 * @param $pages the list of pages
28 * @param $heading header to be used
29 * @param $sk skin object ???
30 */
31 function wfSpecialSpecialpages_gen($pages,$heading,$sk) {
32 global $wgOut, $wgSortSpecialPages;
33
34 if( count( $pages ) == 0 ) {
35 # Yeah, that was pointless. Thanks for coming.
36 return;
37 }
38
39 /** Put them into a sortable array */
40 $groups = array();
41 foreach ( $pages as $page ) {
42 if ( $page->isListed() ) {
43 $group = SpecialPage::getGroup( $page );
44 if( !isset($groups[$group]) ) {
45 $groups[$group] = array();
46 }
47 $groups[$group][$page->getDescription()] = $page->getTitle();
48 }
49 }
50
51 /** Sort */
52 if ( $wgSortSpecialPages ) {
53 foreach( $groups as $group => $sortedPages ) {
54 ksort( $groups[$group] );
55 }
56 }
57
58 /** Always move "other" to end */
59 if( array_key_exists('other',$groups) ) {
60 $other = $groups['other'];
61 unset( $groups['other'] );
62 $groups['other'] = $other;
63 }
64
65 /** Now output the HTML */
66 $wgOut->addHTML( '<h2>' . wfMsgHtml( $heading ) . "</h2>\n" );
67 foreach ( $groups as $group => $sortedPages ) {
68 $middle = ceil( count($sortedPages)/2 );
69 $max = count($sortedPages) - 1;
70 $count = 0;
71
72 $wgOut->addHTML( "<h3 class='mw-specialpagesgroup'>".wfMsgHtml("specialpages-group-$group")."</h3>\n" );
73 $wgOut->addHTML( "<table style='width: 100%;' class='mw-specialpages-table'><tr>" );
74 $wgOut->addHTML( "<td width='30%' valign='top'><ul>\n" );
75 foreach ( $sortedPages as $desc => $title ) {
76 $link = $sk->makeKnownLinkObj( $title , htmlspecialchars( $desc ) );
77 $wgOut->addHTML( "<li>{$link}</li>\n" );
78
79 # Slit up the larger groups
80 $count++;
81 if( $max > 3 && $count == $middle && $count < $max ) {
82 $wgOut->addHTML( "</ul></td><td width='10%'></td><td width='30%' valign='top'><ul>" );
83 }
84 }
85 $wgOut->addHTML( "</ul></td><td width='30%' valign='top'></td></tr></table>\n" );
86 }
87 }
88
89