- $dbr = wfGetDB( DB_SLAVE );
- 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;
+ global $wgContLang;
+
+ $dbr = wfGetDB( DB_SLAVE, 'category' );
+
+ $this->nextPage = array(
+ 'page' => null,
+ 'subcat' => null,
+ 'file' => null,
+ );
+ $this->flip = array( 'page' => false, 'subcat' => false, 'file' => false );
+
+ foreach ( array( 'page', 'subcat', 'file' ) as $type ) {
+ # Get the sortkeys for start/end, if applicable. Note that if
+ # the collation in the database differs from the one
+ # $wgContLang is using, pagination might go totally haywire.
+ $extraConds = array( 'cl_type' => $type );
+ if ( $this->from[$type] !== null ) {
+ $extraConds[] = 'cl_sortkey >= '
+ . $dbr->addQuotes( $wgContLang->convertToSortkey( $this->from[$type] ) );
+ } elseif ( $this->until[$type] !== null ) {
+ $extraConds[] = 'cl_sortkey < '
+ . $dbr->addQuotes( $wgContLang->convertToSortkey( $this->until[$type] ) );
+ $this->flip[$type] = true;