- /**
- * Get the character to be used for sorting subcategories.
- * If there's a link from Category:A to Category:B, the sortkey of the resulting
- * entry in the categorylinks table is Category:A, not A, which it SHOULD be.
- * Workaround: If sortkey == "Category:".$title, than use $title for sorting,
- * else use sortkey...
- */
- function getSubcategorySortChar( $title, $sortkey ) {
- global $wgContLang;
-
- if( $title->getPrefixedText() == $sortkey ) {
- $firstChar = $wgContLang->firstChar( $title->getDBkey() );
- } else {
- $firstChar = $wgContLang->firstChar( $sortkey );
- }
-
- return $wgContLang->convert( $firstChar );
- }
-
- /**
- * Add a page in the image namespace
- */
- function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
- if ( $this->showGallery ) {
- if( $this->flip ) {
- $this->gallery->insert( $title );
- } else {
- $this->gallery->add( $title );
- }
- } else {
- $this->addPage( $title, $sortkey, $pageLength, $isRedirect );
- }
- }
-
- /**
- * Add a miscellaneous page
- */
- function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
- global $wgContLang;
- $titletext = $wgContLang->convertHtml( $title->getPrefixedText(), true );
- $this->articles[] = $isRedirect
- ? '<span class="redirect-in-category">' . $this->getSkin()->makeKnownLinkObj( $title, $titletext ) . '</span>'
- : $this->getSkin()->makeSizeLinkObj( $pageLength, $title, $titletext );
- $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );
- }
-
- function finaliseCategoryState() {
- if( $this->flip ) {
- $this->children = array_reverse( $this->children );
- $this->children_start_char = array_reverse( $this->children_start_char );
- $this->articles = array_reverse( $this->articles );
- $this->articles_start_char = array_reverse( $this->articles_start_char );
- }
- }
-
- function doCategoryQuery() {
- $dbr = wfGetDB( DB_SLAVE, 'category' );
- if( $this->from != '' ) {
- $pageCondition = 'cl_sortkey >= ' . $dbr->addQuotes( $this->from );
- $this->flip = false;
- } elseif( $this->until != '' ) {
- $pageCondition = 'cl_sortkey < ' . $dbr->addQuotes( $this->until );
- $this->flip = true;
- } else {
- $pageCondition = '1 = 1';
- $this->flip = false;
- }
- $res = $dbr->select(
- array( 'page', 'categorylinks', 'category' ),
- array( 'page_title', 'page_namespace', 'page_len', 'page_is_redirect', 'cl_sortkey',
- 'cat_id', 'cat_title', 'cat_subcats', 'cat_pages', 'cat_files' ),
- array( $pageCondition, 'cl_to' => $this->title->getDBkey() ),
- __METHOD__,
- array( 'ORDER BY' => $this->flip ? 'cl_sortkey DESC' : 'cl_sortkey',
- 'USE INDEX' => array( 'categorylinks' => 'cl_sortkey' ),
- 'LIMIT' => $this->limit + 1 ),
- array( 'categorylinks' => array( 'INNER JOIN', 'cl_from = page_id' ),
- 'category' => array( 'LEFT JOIN', 'cat_title = page_title AND page_namespace = ' . NS_CATEGORY ) )
- );
-
- $count = 0;
- $this->nextPage = null;
- while( $x = $dbr->fetchObject ( $res ) ) {
- if( ++$count > $this->limit ) {
- // We've reached the one extra which shows that there are
- // additional pages to be had. Stop here...
- $this->nextPage = $x->cl_sortkey;
- break;
- }
-
- $title = Title::makeTitle( $x->page_namespace, $x->page_title );
-
- if( $title->getNamespace() == NS_CATEGORY ) {
- $cat = Category::newFromRow( $x, $title );
- $this->addSubcategoryObject( $cat, $x->cl_sortkey, $x->page_len );
- } elseif( $this->showGallery && $title->getNamespace() == NS_FILE ) {
- $this->addImage( $title, $x->cl_sortkey, $x->page_len, $x->page_is_redirect );
- } else {
- $this->addPage( $title, $x->cl_sortkey, $x->page_len, $x->page_is_redirect );
- }
- }
- $dbr->freeResult( $res );
- }