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