00001 <?php
00007 function wfSpecialCategories( $par=null ) {
00008 global $wgOut, $wgRequest;
00009
00010 if( $par == '' ) {
00011 $from = $wgRequest->getText( 'from' );
00012 } else {
00013 $from = $par;
00014 }
00015 $cap = new CategoryPager( $from );
00016 $wgOut->addHTML(
00017 XML::openElement( 'div', array('class' => 'mw-spcontent') ) .
00018 wfMsgExt( 'categoriespagetext', array( 'parse' ) ) .
00019 $cap->getStartForm( $from ) .
00020 $cap->getNavigationBar() .
00021 '<ul>' . $cap->getBody() . '</ul>' .
00022 $cap->getNavigationBar() .
00023 XML::closeElement( 'div' )
00024 );
00025 }
00026
00033 class CategoryPager extends AlphabeticPager {
00034 function __construct( $from ) {
00035 parent::__construct();
00036 $from = str_replace( ' ', '_', $from );
00037 if( $from !== '' ) {
00038 global $wgCapitalLinks, $wgContLang;
00039 if( $wgCapitalLinks ) {
00040 $from = $wgContLang->ucfirst( $from );
00041 }
00042 $this->mOffset = $from;
00043 }
00044 }
00045
00046 function getQueryInfo() {
00047 return array(
00048 'tables' => array( 'category' ),
00049 'fields' => array( 'cat_title','cat_pages' ),
00050 'conds' => array( 'cat_pages > 0' ),
00051 'options' => array( 'USE INDEX' => 'cat_title' ),
00052 );
00053 }
00054
00055 function getIndexField() {
00056 # return array( 'abc' => 'cat_title', 'count' => 'cat_pages' );
00057 return 'cat_title';
00058 }
00059
00060 function getDefaultQuery() {
00061 parent::getDefaultQuery();
00062 unset( $this->mDefaultQuery['from'] );
00063 return $this->mDefaultQuery;
00064 }
00065 # protected function getOrderTypeMessages() {
00066 # return array( 'abc' => 'special-categories-sort-abc',
00067 # 'count' => 'special-categories-sort-count' );
00068 # }
00069
00070 protected function getDefaultDirections() {
00071 # return array( 'abc' => false, 'count' => true );
00072 return false;
00073 }
00074
00075
00076 public function getBody() {
00077 if (!$this->mQueryDone) {
00078 $this->doQuery();
00079 }
00080 $batch = new LinkBatch;
00081
00082 $this->mResult->rewind();
00083
00084 while ( $row = $this->mResult->fetchObject() ) {
00085 $batch->addObj( Title::makeTitleSafe( NS_CATEGORY, $row->cat_title ) );
00086 }
00087 $batch->execute();
00088 $this->mResult->rewind();
00089 return parent::getBody();
00090 }
00091
00092 function formatRow($result) {
00093 global $wgLang;
00094 $title = Title::makeTitle( NS_CATEGORY, $result->cat_title );
00095 $titleText = $this->getSkin()->makeLinkObj( $title, htmlspecialchars( $title->getText() ) );
00096 $count = wfMsgExt( 'nmembers', array( 'parsemag', 'escape' ),
00097 $wgLang->formatNum( $result->cat_pages ) );
00098 return Xml::tags('li', null, "$titleText ($count)" ) . "\n";
00099 }
00100
00101 public function getStartForm( $from ) {
00102 global $wgScript;
00103 $t = SpecialPage::getTitleFor( 'Categories' );
00104
00105 return
00106 Xml::tags( 'form', array( 'method' => 'get', 'action' => $wgScript ),
00107 Xml::hidden( 'title', $t->getPrefixedText() ) .
00108 Xml::fieldset( wfMsg( 'categories' ),
00109 Xml::inputLabel( wfMsg( 'categoriesfrom' ),
00110 'from', 'from', 20, $from ) .
00111 ' ' .
00112 Xml::submitButton( wfMsg( 'allpagessubmit' ) ) ) );
00113 }
00114 }