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