Make paging links on category pages known. This allows more comfortable browsing...
[lhc/web/wiklou.git] / includes / CategoryPage.php
index a5bdc05..f431045 100644 (file)
@@ -144,8 +144,13 @@ class CategoryViewer {
        function addSubcategory( $title, $sortkey, $pageLength ) {
                global $wgContLang;
                // Subcategory; strip the 'Category' namespace from the link text.
-               $this->children[] = $this->getSkin()->makeKnownLinkObj(
-                       $title, $wgContLang->convertHtml( $title->getText() ) );
+               $this->children[] = $this->getSkin()->link(
+                       $title,
+                       $wgContLang->convertHtml( $title->getText() ),
+                       array(),
+                       array(),
+                       array( 'known', 'noclasses' )
+               );
 
                $this->children_start_char[] = $this->getSubcategorySortChar( $title, $sortkey );
        }
@@ -189,9 +194,16 @@ class CategoryViewer {
         */
        function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
                global $wgContLang;
-               $titletext = $wgContLang->convert($title);
+               $titletext = $wgContLang->convertHtml( $title->getPrefixedText() );
                $this->articles[] = $isRedirect
-                       ? '<span class="redirect-in-category">' . $this->getSkin()->makeKnownLinkObj( $title, $titletext ) . '</span>'
+                       ? '<span class="redirect-in-category">' .
+                               $this->getSkin()->link(
+                                       $title,
+                                       $titletext,
+                                       array(),
+                                       array(),
+                                       array( 'known', 'noclasses' )
+                               ) . '</span>'
                        : $this->getSkin()->makeSizeLinkObj( $pageLength, $title, $titletext );
                $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );
        }
@@ -206,7 +218,7 @@ class CategoryViewer {
        }
 
        function doCategoryQuery() {
-               $dbr = wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE, 'category' );
                if( $this->from != '' ) {
                        $pageCondition = 'cl_sortkey >= ' . $dbr->addQuotes( $this->from );
                        $this->flip = false;
@@ -251,17 +263,11 @@ class CategoryViewer {
                                $this->addPage( $title, $x->cl_sortkey, $x->page_len, $x->page_is_redirect );
                        }
                }
-               $dbr->freeResult( $res );
        }
 
        function getCategoryTop() {
-               $r = '';
-               if( $this->until != '' ) {
-                       $r .= $this->pagingLinks( $this->title, $this->nextPage, $this->until, $this->limit );
-               } elseif( $this->nextPage != '' || $this->from != '' ) {
-                       $r .= $this->pagingLinks( $this->title, $this->from, $this->nextPage, $this->limit );
-               }
-               return $r == ''
+               $r = $this->getCategoryBottom();
+               return $r === ''
                        ? $r
                        : "<br style=\"clear:both;\"/>\n" . $r;
        }
@@ -362,7 +368,8 @@ class CategoryViewer {
         */
        function columnList( $articles, $articles_start_char ) {
                // divide list into three equal chunks
-               $chunk = (int) (count ( $articles ) / 3);
+               $chunk = (int) ( count( $articles ) / 3 );
+               $remaining = count( $articles ) % 3;
 
                // get and display header
                $r = '<table width="100%"><tr valign="top">';
@@ -370,9 +377,9 @@ class CategoryViewer {
                $prev_start_char = 'none';
 
                // loop through the chunks
-               for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0;
+               for( $startChunk = 0, $endChunk = $chunk, $chunkIndex = 0;
                        $chunkIndex < 3;
-                       $chunkIndex++, $startChunk = $endChunk, $endChunk += $chunk + 1)
+                       $chunkIndex++, $startChunk = $endChunk, $endChunk += $remaining == 0 ? $chunk : $chunk + 1 )
                {
                        $r .= "<td>\n";
                        $atColumnTop = true;
@@ -449,15 +456,27 @@ class CategoryViewer {
                $sk = $this->getSkin();
                $limitText = $wgLang->formatNum( $limit );
 
-               $prevLink = wfMsgExt( 'prevn', array( 'escape' ), $limitText );
+               $prevLink = wfMsgExt( 'prevn', array( 'escape', 'parsemag' ), $limitText );
                if( $first != '' ) {
-                       $prevLink = $sk->makeLinkObj( $title, $prevLink,
-                               wfArrayToCGI( $query + array( 'until' => $first ) ) );
+                       $prevQuery = $query;
+                       $prevQuery['until'] = $first;
+                       $prevLink = $sk->linkKnown(
+                               $title,
+                               $prevLink,
+                               array(),
+                               $prevQuery
+                       );
                }
-               $nextLink = wfMsgExt( 'nextn', array( 'escape' ), $limitText );
+               $nextLink = wfMsgExt( 'nextn', array( 'escape', 'parsemag' ), $limitText );
                if( $last != '' ) {
-                       $nextLink = $sk->makeLinkObj( $title, $nextLink,
-                               wfArrayToCGI( $query + array( 'from' => $last ) ) );
+                       $lastQuery = $query;
+                       $lastQuery['from'] = $last;
+                       $nextLink = $sk->linkKnown(
+                               $title,
+                               $nextLink,
+                               array(),
+                               $lastQuery
+                       );
                }
 
                return "($prevLink) ($nextLink)";