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