- 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;
- }
-
- $tables = array( 'page', 'categorylinks', 'category' );
- $fields = array( 'page_title', 'page_namespace', 'page_len',
- 'page_is_redirect', 'cl_sortkey', 'cat_id', 'cat_title',
- 'cat_subcats', 'cat_pages', 'cat_files' );
- $conds = array( 'cl_to' => $this->title->getDBkey() );
- $opts = array( 'ORDER BY' => $this->flip ? 'cl_sortkey DESC' :
- 'cl_sortkey', 'USE INDEX' => array( 'categorylinks' => 'cl_sortkey' ) );
- $joins = array( 'categorylinks' => array( 'INNER JOIN', 'cl_from = page_id' ),
- 'category' => array( 'LEFT JOIN', 'cat_title = page_title AND page_namespace = ' . NS_CATEGORY ) );
-
- if ( $wgExperimentalCategorySort ) {
- # Copy-pasted from below, but that's okay, because the stuff below
- # will be deleted when this becomes the default.
- $count = 0;
- $this->nextPage = null;
-
- foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
- $res = $dbr->select(
- $tables,
- $fields,
- $conds + array( 'cl_type' => $type ) + ( $type == 'page' ? array( $pageCondition ) : array() ),
- __METHOD__,
- $opts + ( $type == 'page' ? array( 'LIMIT' => $this->limit + 1 ) : array() ),
- $joins
- );
-
- foreach ( $res as $row ) {
- if ( $type == 'page' && ++$count > $this->limit ) {
- # We've reached the one extra which shows that there
- # are additional pages to be had. Stop here...
- $this->nextPage = $row->cl_sortkey;
- break;
- }
-
- $title = Title::newFromRow( $row );
-
- if ( $title->getNamespace() == NS_CATEGORY ) {
- $cat = Category::newFromRow( $row, $title );
- $this->addSubcategoryObject( $cat, $row->cl_sortkey, $row->page_len );
- } elseif ( $this->showGallery && $title->getNamespace() == NS_FILE ) {
- $this->addImage( $title, $row->cl_sortkey, $row->page_len, $row->page_is_redirect );
- } else {
- $this->addPage( $title, $row->cl_sortkey, $row->page_len, $row->page_is_redirect );
- }
- }
- }
-
- return;
- }
-
- # Non-$wgExperimentalCategorySort stuff