MediaWiki  master
SpecialCategories.php
Go to the documentation of this file.
00001 <?php
00027 class SpecialCategories extends SpecialPage {
00028 
00029         function __construct() {
00030                 parent::__construct( 'Categories' );
00031         }
00032 
00033         function execute( $par ) {
00034                 $this->setHeaders();
00035                 $this->outputHeader();
00036                 $this->getOutput()->allowClickjacking();
00037 
00038                 $from = $this->getRequest()->getText( 'from', $par );
00039 
00040                 $cap = new CategoryPager( $this->getContext(), $from );
00041                 $cap->doQuery();
00042 
00043                 $this->getOutput()->addHTML(
00044                         Html::openElement( 'div', array( 'class' => 'mw-spcontent' ) ) .
00045                         $this->msg( 'categoriespagetext', $cap->getNumRows() )->parseAsBlock() .
00046                         $cap->getStartForm( $from ) .
00047                         $cap->getNavigationBar() .
00048                         '<ul>' . $cap->getBody() . '</ul>' .
00049                         $cap->getNavigationBar() .
00050                         Html::closeElement( 'div' )
00051                 );
00052         }
00053 }
00054 
00061 class CategoryPager extends AlphabeticPager {
00062         function __construct( IContextSource $context, $from ) {
00063                 parent::__construct( $context );
00064                 $from = str_replace( ' ', '_', $from );
00065                 if( $from !== '' ) {
00066                         $from = Title::capitalize( $from, NS_CATEGORY );
00067                         $this->setOffset( $from );
00068                         $this->setIncludeOffset( true );
00069                 }
00070         }
00071 
00072         function getQueryInfo() {
00073                 return array(
00074                         'tables' => array( 'category' ),
00075                         'fields' => array( 'cat_title','cat_pages' ),
00076                         'conds' => array( 'cat_pages > 0' ),
00077                         'options' => array( 'USE INDEX' => 'cat_title' ),
00078                 );
00079         }
00080 
00081         function getIndexField() {
00082 #               return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
00083                 return 'cat_title';
00084         }
00085 
00086         function getDefaultQuery() {
00087                 parent::getDefaultQuery();
00088                 unset( $this->mDefaultQuery['from'] );
00089                 return $this->mDefaultQuery;
00090         }
00091 #       protected function getOrderTypeMessages() {
00092 #               return array( 'abc' => 'special-categories-sort-abc',
00093 #                       'count' => 'special-categories-sort-count' );
00094 #       }
00095 
00096         protected function getDefaultDirections() {
00097 #               return array( 'abc' => false, 'count' => true );
00098                 return false;
00099         }
00100 
00101         /* Override getBody to apply LinksBatch on resultset before actually outputting anything. */
00102         public function getBody() {
00103                 $batch = new LinkBatch;
00104 
00105                 $this->mResult->rewind();
00106 
00107                 foreach ( $this->mResult as $row ) {
00108                         $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
00109                 }
00110                 $batch->execute();
00111                 $this->mResult->rewind();
00112                 return parent::getBody();
00113         }
00114 
00115         function formatRow($result) {
00116                 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
00117                 $titleText = Linker::link( $title, htmlspecialchars( $title->getText() ) );
00118                 $count = $this->msg( 'nmembers' )->numParams( $result->cat_pages )->escaped();
00119                 return Xml::tags( 'li', null, $this->getLanguage()->specialList( $titleText, $count ) ) . "\n";
00120         }
00121 
00122         public function getStartForm( $from ) {
00123                 global $wgScript;
00124 
00125                 return
00126                         Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
00127                                 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
00128                                 Xml::fieldset( $this->msg( 'categories' )->text(),
00129                                         Xml::inputLabel( $this->msg( 'categoriesfrom' )->text(),
00130                                                 'from', 'from', 20, $from ) .
00131                                         ' ' .
00132                                         Xml::submitButton( $this->msg( 'allpagessubmit' )->text() ) ) );
00133         }
00134 }