SpecialSpecialpages.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup SpecialPage
  5. */
  6. /**
  7. *
  8. */
  9. function wfSpecialSpecialpages() {
  10. global $wgOut, $wgUser, $wgMessageCache, $wgSortSpecialPages;
  11. $wgMessageCache->loadAllMessages();
  12. $wgOut->setRobotPolicy( 'noindex,nofollow' ); # Is this really needed?
  13. $sk = $wgUser->getSkin();
  14. $pages = SpecialPage::getUsablePages();
  15. if( count( $pages ) == 0 ) {
  16. # Yeah, that was pointless. Thanks for coming.
  17. return;
  18. }
  19. /** Put them into a sortable array */
  20. $groups = array();
  21. foreach ( $pages as $page ) {
  22. if ( $page->isListed() ) {
  23. $group = SpecialPage::getGroup( $page );
  24. if( !isset($groups[$group]) ) {
  25. $groups[$group] = array();
  26. }
  27. $groups[$group][$page->getDescription()] = array( $page->getTitle(), $page->isRestricted() );
  28. }
  29. }
  30. /** Sort */
  31. if ( $wgSortSpecialPages ) {
  32. foreach( $groups as $group => $sortedPages ) {
  33. ksort( $groups[$group] );
  34. }
  35. }
  36. /** Always move "other" to end */
  37. if( array_key_exists('other',$groups) ) {
  38. $other = $groups['other'];
  39. unset( $groups['other'] );
  40. $groups['other'] = $other;
  41. }
  42. $includesRestrictedPages = false;
  43. /** Now output the HTML */
  44. foreach ( $groups as $group => $sortedPages ) {
  45. $middle = ceil( count($sortedPages)/2 );
  46. $total = count($sortedPages);
  47. $count = 0;
  48. $wgOut->wrapWikiMsg( "<h4 class='mw-specialpagesgroup'>$1</h4>\n", "specialpages-group-$group" );
  49. $wgOut->addHTML( "<table style='width: 100%;' class='mw-specialpages-table'><tr>" );
  50. $wgOut->addHTML( "<td width='30%' valign='top'><ul>\n" );
  51. foreach( $sortedPages as $desc => $specialpage ) {
  52. list( $title, $restricted ) = $specialpage;
  53. $link = $sk->makeKnownLinkObj( $title , htmlspecialchars( $desc ) );
  54. if( $restricted ) {
  55. $includesRestrictedPages = true;
  56. $wgOut->addHTML( "<li class='mw-specialpages-page mw-specialpagerestricted'>{$link}</li>\n" );
  57. } else {
  58. $wgOut->addHTML( "<li>{$link}</li>\n" );
  59. }
  60. # Split up the larger groups
  61. $count++;
  62. if( $total > 3 && $count == $middle ) {
  63. $wgOut->addHTML( "</ul></td><td width='10%'></td><td width='30%' valign='top'><ul>" );
  64. }
  65. }
  66. $wgOut->addHTML( "</ul></td><td width='30%' valign='top'></td></tr></table>\n" );
  67. }
  68. if ( $includesRestrictedPages ) {
  69. $wgOut->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
  70. }
  71. }