<?php
+/**
+ *
+ * @addtogroup SpecialPage
+ */
-function wfSpecialSpecialpages()
-{
- global $wgUser, $wgOut, $wgLang;
+/**
+ *
+ */
+function wfSpecialSpecialpages() {
+ global $wgOut, $wgUser, $wgMessageCache;
- $wgOut->setRobotpolicy( "index,nofollow" );
+ $wgMessageCache->loadAllMessages();
+ $wgOut->setRobotpolicy( 'noindex,nofollow' ); # Is this really needed?
$sk = $wgUser->getSkin();
- $validSP = $wgLang->getValidSpecialPages();
- $wgOut->addHTML( "<h2>" . wfMsg( "spheading" ) . "</h2>\n<ul>" );
- foreach ( $validSP as $name => $desc ) {
- if ( "" == $desc ) { continue; }
- $link = $sk->makeKnownLink( $wgLang->specialPage( $name ), $desc );
- $wgOut->addHTML( "<li>{$link}</li>\n" );
+ /** Pages available to all */
+ wfSpecialSpecialpages_gen( SpecialPage::getRegularPages(), 'spheading', $sk );
+
+ /** Restricted special pages */
+ wfSpecialSpecialpages_gen( SpecialPage::getRestrictedPages(), 'restrictedpheading', $sk );
+}
+
+/**
+ * sub function generating the list of pages
+ * @param $pages the list of pages
+ * @param $heading header to be used
+ * @param $sk skin object ???
+ */
+function wfSpecialSpecialpages_gen($pages,$heading,$sk) {
+ global $wgOut, $wgSortSpecialPages;
+
+ if( count( $pages ) == 0 ) {
+ # Yeah, that was pointless. Thanks for coming.
+ return;
}
- $wgOut->addHTML( "</ul>\n" );
- if ( $wgUser->isSysop() ) {
- $sysopSP = $wgLang->getSysopSpecialPages();
- $wgOut->addHTML( "<h2>" . wfMsg( "sysopspheading" ) . "</h2>\n<ul>" );
+ /** Put them into a sortable array */
+ $groups = array();
+ foreach ( $pages as $page ) {
+ if ( $page->isListed() ) {
+ $group = SpecialPage::getGroup( $page );
+ if( !isset($groups[$group]) ) {
+ $groups[$group] = array();
+ }
+ $groups[$group][$page->getDescription()] = $page->getTitle();
+ }
+ }
- foreach ( $sysopSP as $name => $desc ) {
- if ( "" == $desc ) { continue; }
- $link = $sk->makeKnownLink( $wgLang->specialPage( $name ), $desc );
- $wgOut->addHTML( "<li>{$link}</li>\n" );
+ /** Sort */
+ if ( $wgSortSpecialPages ) {
+ foreach( $groups as $group => $sortedPages ) {
+ ksort( $groups[$group] );
}
- $wgOut->addHTML( "</ul>\n" );
}
- if ( $wgUser->isDeveloper() ) {
- $devSP = $wgLang->getDeveloperSpecialPages();
- $wgOut->addHTML( "<h2>" . wfMsg( "developerspheading" ) .
- "</h2>\n<ul>" );
+ /** Always move "other" to end */
+ if( array_key_exists('other',$groups) ) {
+ $other = $groups['other'];
+ unset( $groups['other'] );
+ $groups['other'] = $other;
+ }
+
+ /** Now output the HTML */
+ $wgOut->addHTML( '<h2>' . wfMsgHtml( $heading ) . "</h2>\n" );
+ foreach ( $groups as $group => $sortedPages ) {
+ $middle = ceil( count($sortedPages)/2 );
+ $total = count($sortedPages);
+ $count = 0;
- foreach ( $devSP as $name => $desc ) {
- if ( "" == $desc ) { continue; }
- $link = $sk->makeKnownLink( $wgLang->specialPage( $name ), $desc );
+ $wgOut->addHTML( "<h4 class='mw-specialpagesgroup'>".wfMsgHtml("specialpages-group-$group")."</h4>\n" );
+ $wgOut->addHTML( "<table style='width: 100%;' class='mw-specialpages-table'><tr>" );
+ $wgOut->addHTML( "<td width='30%' valign='top'><ul>\n" );
+ foreach ( $sortedPages as $desc => $title ) {
+ $link = $sk->makeKnownLinkObj( $title , htmlspecialchars( $desc ) );
$wgOut->addHTML( "<li>{$link}</li>\n" );
+
+ # Slit up the larger groups
+ $count++;
+ if( $total > 3 && $count == $middle ) {
+ $wgOut->addHTML( "</ul></td><td width='10%'></td><td width='30%' valign='top'><ul>" );
+ }
}
- $wgOut->addHTML( "</ul>\n" );
+ $wgOut->addHTML( "</ul></td><td width='30%' valign='top'></td></tr></table>\n" );
}
}
-
-?>