MediaWiki  REL1_22
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->getTitle(),
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( "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n", "specialpages-group-$group" );
00107             $out->addHTML(
00108                 Html::openElement( 'table', array( 'style' => 'width:100%;', 'class' => 'mw-specialpages-table' ) ) . "\n" .
00109                 Html::openElement( 'tr' ) . "\n" .
00110                 Html::openElement( 'td', array( 'style' => 'width:30%;vertical-align:top' ) ) . "\n" .
00111                 Html::openElement( 'ul' ) . "\n"
00112             );
00113             foreach ( $sortedPages as $desc => $specialpage ) {
00114                 list( $title, $restricted, $cached ) = $specialpage;
00115 
00116                 $pageClasses = array();
00117                 if ( $cached ) {
00118                     $includesCachedPages = true;
00119                     $pageClasses[] = 'mw-specialpagecached';
00120                 }
00121                 if ( $restricted ) {
00122                     $includesRestrictedPages = true;
00123                     $pageClasses[] = 'mw-specialpagerestricted';
00124                 }
00125 
00126                 $link = Linker::linkKnown( $title, htmlspecialchars( $desc ) );
00127                 $out->addHTML( Html::rawElement( 'li', array( 'class' => implode( ' ', $pageClasses ) ), $link ) . "\n" );
00128 
00129                 # Split up the larger groups
00130                 $count++;
00131                 if ( $total > 3 && $count == $middle ) {
00132                     $out->addHTML(
00133                         Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
00134                         Html::element( 'td', array( 'style' => 'width:10%' ), '' ) .
00135                         Html::openElement( 'td', array( 'style' => 'width:30%' ) ) . Html::openElement( 'ul' ) . "\n"
00136                     );
00137                 }
00138             }
00139             $out->addHTML(
00140                 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
00141                 Html::element( 'td', array( 'style' => 'width:30%' ), '' ) .
00142                 Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n"
00143             );
00144         }
00145 
00146         if ( $includesRestrictedPages || $includesCachedPages ) {
00147             $out->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
00148         }
00149     }
00150 }