MediaWiki  REL1_21
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();
00063                 foreach ( $pages as $page ) {
00064                         if ( $page->isListed() ) {
00065                                 $group = $page->getFinalGroupName();
00066                                 if( !isset( $groups[$group] ) ) {
00067                                         $groups[$group] = array();
00068                                 }
00069                                 $groups[$group][$page->getDescription()] = array(
00070                                         $page->getTitle(),
00071                                         $page->isRestricted(),
00072                                         $page->isCached()
00073                                 );
00074                         }
00075                 }
00076 
00078                 if ( $wgSortSpecialPages ) {
00079                         foreach( $groups as $group => $sortedPages ) {
00080                                 ksort( $groups[$group] );
00081                         }
00082                 }
00083 
00085                 if( array_key_exists( 'other', $groups ) ) {
00086                         $other = $groups['other'];
00087                         unset( $groups['other'] );
00088                         $groups['other'] = $other;
00089                 }
00090 
00091                 return $groups;
00092         }
00093 
00094         private function outputPageList( $groups ) {
00095                 $out = $this->getOutput();
00096 
00097                 $includesRestrictedPages = false;
00098                 $includesCachedPages = false;
00099 
00100                 foreach ( $groups as $group => $sortedPages ) {
00101                         $total = count( $sortedPages );
00102                         $middle = ceil( $total / 2 );
00103                         $count = 0;
00104 
00105                         $out->wrapWikiMsg( "<h2 class=\"mw-specialpagesgroup\" id=\"mw-specialpagesgroup-$group\">$1</h2>\n", "specialpages-group-$group" );
00106                         $out->addHTML(
00107                                 Html::openElement( 'table', array( 'style' => 'width:100%;', 'class' => 'mw-specialpages-table' ) ) ."\n" .
00108                                 Html::openElement( 'tr' ) . "\n" .
00109                                 Html::openElement( 'td', array( 'style' => 'width:30%;vertical-align:top' ) ) . "\n" .
00110                                 Html::openElement( 'ul' ) . "\n"
00111                         );
00112                         foreach( $sortedPages as $desc => $specialpage ) {
00113                                 list( $title, $restricted, $cached ) = $specialpage;
00114 
00115                                 $pageClasses = array();
00116                                 if ( $cached ) {
00117                                         $includesCachedPages = true;
00118                                         $pageClasses[] = 'mw-specialpagecached';
00119                                 }
00120                                 if( $restricted ) {
00121                                         $includesRestrictedPages = true;
00122                                         $pageClasses[] = 'mw-specialpagerestricted';
00123                                 }
00124 
00125                                 $link = Linker::linkKnown( $title, htmlspecialchars( $desc ) );
00126                                 $out->addHTML( Html::rawElement( 'li', array( 'class' => implode( ' ', $pageClasses ) ), $link ) . "\n" );
00127 
00128                                 # Split up the larger groups
00129                                 $count++;
00130                                 if( $total > 3 && $count == $middle ) {
00131                                         $out->addHTML(
00132                                                 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
00133                                                 Html::element( 'td', array( 'style' => 'width:10%' ), '' ) .
00134                                                 Html::openElement( 'td', array( 'style' => 'width:30%' ) ) . Html::openElement( 'ul' ) . "\n"
00135                                         );
00136                                 }
00137                         }
00138                         $out->addHTML(
00139                                 Html::closeElement( 'ul' ) . Html::closeElement( 'td' ) .
00140                                 Html::element( 'td', array( 'style' => 'width:30%' ), '' ) .
00141                                 Html::closeElement( 'tr' ) . Html::closeElement( 'table' ) . "\n"
00142                         );
00143                 }
00144 
00145                 if ( $includesRestrictedPages || $includesCachedPages ) {
00146                         $out->wrapWikiMsg( "<div class=\"mw-specialpages-notes\">\n$1\n</div>", 'specialpages-note' );
00147                 }
00148         }
00149 }