MediaWiki  REL1_23
SpecialSpecialpages.php
Go to the documentation of this file.
00001 <?php
00029 class SpecialSpecialpages extends UnlistedSpecialPage {
00030 
00031     function __construct() {
00032         parent::__construct( 'Specialpages' );
00033     }
00034 
00035     function execute( $par ) {
00036         $out = $this->getOutput();
00037         $this->setHeaders();
00038         $this->outputHeader();
00039         $out->allowClickjacking();
00040         $out->addModuleStyles( 'mediawiki.special' );
00041 
00042         $groups = $this->getPageGroups();
00043 
00044         if ( $groups === false ) {
00045             return;
00046         }
00047 
00048         $this->outputPageList( $groups );
00049     }
00050 
00051     private function getPageGroups() {
00052         global $wgSortSpecialPages;
00053 
00054         $pages = SpecialPageFactory::getUsablePages( $this->getUser() );
00055 
00056         if ( !count( $pages ) ) {
00057             # Yeah, that was pointless. Thanks for coming.
00058             return false;
00059         }
00060 
00062         $groups = array();
00064         foreach ( $pages as $page ) {
00065             if ( $page->isListed() ) {
00066                 $group = $page->getFinalGroupName();
00067                 if ( !isset( $groups[$group] ) ) {
00068                     $groups[$group] = array();
00069                 }
00070                 $groups[$group][$page->getDescription()] = array(
00071                     $page->getPageTitle(),
00072                     $page->isRestricted(),
00073                     $page->isCached()
00074                 );
00075             }
00076         }
00077 
00079         if ( $wgSortSpecialPages ) {
00080             foreach ( $groups as $group => $sortedPages ) {
00081                 ksort( $groups[$group] );
00082             }
00083         }
00084 
00086         if ( array_key_exists( 'other', $groups ) ) {
00087             $other = $groups['other'];
00088             unset( $groups['other'] );
00089             $groups['other'] = $other;
00090         }
00091 
00092         return $groups;
00093     }
00094 
00095     private function outputPageList( $groups ) {
00096         $out = $this->getOutput();
00097 
00098         $includesRestrictedPages = false;
00099         $includesCachedPages = false;
00100 
00101         foreach ( $groups as $group => $sortedPages ) {
00102             $total = count( $sortedPages );
00103             $middle = ceil( $total / 2 );
00104             $count = 0;
00105 
00106             $out->wrapWikiMsg(
00107                 "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n",
00108                 "specialpages-group-$group"
00109             );
00110             $out->addHTML(
00111                 Html::openElement(
00112                     'table',
00113                     array( 'style' => 'width:100%;', 'class' => 'mw-specialpages-table' )
00114                 ) . "\n" .
00115                 Html::openElement( 'tr' ) . "\n" .
00116                 Html::openElement( 'td', array( 'style' => 'width:30%;vertical-align:top' ) ) . "\n" .
00117                 Html::openElement( 'ul' ) . "\n"
00118             );
00119             foreach ( $sortedPages as $desc => $specialpage ) {
00120                 list( $title, $restricted, $cached ) = $specialpage;
00121 
00122                 $pageClasses = array();
00123                 if ( $cached ) {
00124                     $includesCachedPages = true;
00125                     $pageClasses[] = 'mw-specialpagecached';
00126                 }
00127                 if ( $restricted ) {
00128                     $includesRestrictedPages = true;
00129                     $pageClasses[] = 'mw-specialpagerestricted';
00130                 }
00131 
00132                 $link = Linker::linkKnown( $title, htmlspecialchars( $desc ) );
00133                 $out->addHTML( Html::rawElement(
00134                         'li',
00135                         array( 'class' => implode( ' ', $pageClasses ) ),
00136                         $link
00137                     ) . "\n" );
00138 
00139                 # Split up the larger groups
00140                 $count++;
00141                 if ( $total > 3 && $count == $middle ) {
00142                     $out->addHTML(
00143                         Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
00144                         Html::element( 'td', array( 'style' => 'width:10%' ), '' ) .
00145                         Html::openElement( 'td', array( 'style' => 'width:30%' ) ) . Html::openElement( 'ul' ) . "\n"
00146                     );
00147                 }
00148             }
00149             $out->addHTML(
00150                 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
00151                 Html::element( 'td', array( 'style' => 'width:30%' ), '' ) .
00152                 Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n"
00153             );
00154         }
00155 
00156         if ( $includesRestrictedPages || $includesCachedPages ) {
00157             $out->wrapWikiMsg( "<h2 class=\"mw-specialpages-note-top\">$1</h2>", 'specialpages-note-top' );
00158             $out->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
00159         }
00160     }
00161 }