Don't require an existence check before calling loadPageData(). Added an accessor...
[lhc/web/wiklou.git] / includes / CategoryPage.php
index 2d09936..b515986 100644 (file)
@@ -5,9 +5,9 @@
  *
  * @package MediaWiki
  */
+
 if( !defined( 'MEDIAWIKI' ) )
-       die();
+       die( -1 );
 
 global $wgCategoryMagicGallery;
 if( $wgCategoryMagicGallery )
@@ -15,7 +15,7 @@ if( $wgCategoryMagicGallery )
        require_once('ImageGallery.php');
 
 /**
- * @package MediaWiki 
+ * @package MediaWiki
  */
 class CategoryPage extends Article {
 
@@ -27,7 +27,7 @@ class CategoryPage extends Article {
                }
 
                Article::view();
-               
+
                # If the article we've just shown is in the "Image" namespace,
                # follow it with the history list and link list for the image
                # it describes.
@@ -40,7 +40,7 @@ class CategoryPage extends Article {
        function openShowCategory() {
                # For overloading
        }
-       
+
        # generate a list of subcategories and pages for a category
        # depending on wfMsg("usenewcategorypage") it either calls the new
        # or the old code. The new code will not work properly for some
@@ -64,7 +64,7 @@ class CategoryPage extends Article {
         * @access private
         */
        function doCategoryMagic( $from = '', $until = '' ) {
-               global $wgContLang,$wgUser, $wgCategoryMagicGallery;
+               global $wgContLang,$wgUser, $wgCategoryMagicGallery, $wgCategoryPagingLimit;
                $fname = 'CategoryPage::doCategoryMagic';
                wfProfileIn( $fname );
 
@@ -85,13 +85,13 @@ class CategoryPage extends Article {
                        $pageCondition = 'cl_sortkey < ' . $dbr->addQuotes( $until );
                        $flip = true;
                } else {
-                       $pageCondition = '1';
+                       $pageCondition = '1 = 1';
                        $flip = false;
                }
-               $limit = 200;
+               $limit = $wgCategoryPagingLimit;
                $res = $dbr->select(
                        array( 'page', 'categorylinks' ),
-                       array( 'page_title', 'page_namespace', 'cl_sortkey' ),
+                       array( 'page_title', 'page_namespace', 'page_len', 'cl_sortkey' ),
                        array( $pageCondition,
                               'cl_from          =  page_id',
                               'cl_to'           => $this->mTitle->getDBKey()),
@@ -100,7 +100,7 @@ class CategoryPage extends Article {
                        $fname,
                        array( 'ORDER BY' => $flip ? 'cl_sortkey DESC' : 'cl_sortkey',
                               'LIMIT'    => $limit + 1 ) );
-               
+
                $sk =& $wgUser->getSkin();
                $r = "<br style=\"clear:both;\"/>\n";
                $count = 0;
@@ -112,13 +112,13 @@ class CategoryPage extends Article {
                                $nextPage = $x->cl_sortkey;
                                break;
                        }
-                       
+
                        $title = Title::makeTitle( $x->page_namespace, $x->page_title );
-                       
+
                        if( $title->getNamespace() == NS_CATEGORY ) {
                                // Subcategory; strip the 'Category' namespace from the link text.
-                               array_push( $children, $sk->makeKnownLinkObj( $title, $wgContLang->convert( $title->getText() ) ) );
-                               
+                               array_push( $children, $sk->makeKnownLinkObj( $title, $wgContLang->convertHtml( $title->getText() ) ) );
+
                                // 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,
@@ -139,7 +139,7 @@ class CategoryPage extends Article {
                                }
                        } else {
                                // Page in this category
-                               array_push( $articles, $sk->makeKnownLinkObj( $title, $wgContLang->convert( $title->getText() ) ) ) ;
+                               array_push( $articles, $sk->makeSizeLinkObj( $x->page_len, $title, $wgContLang->convert( $title->getPrefixedText() ) ) ) ;
                                array_push( $articles_start_char, $wgContLang->convert( $wgContLang->firstChar( $x->cl_sortkey ) ) );
                        }
                }
@@ -151,13 +151,13 @@ class CategoryPage extends Article {
                        $articles            = array_reverse( $articles );
                        $articles_start_char = array_reverse( $articles_start_char );
                }
-               
+
                if( $until != '' ) {
                        $r .= $this->pagingLinks( $this->mTitle, $nextPage, $until, $limit );
                } elseif( $nextPage != '' || $from != '' ) {
                        $r .= $this->pagingLinks( $this->mTitle, $from, $nextPage, $limit );
                }
-               
+
                # Don't show subcategories section if there are none.
                if( count( $children ) > 0 ) {
                        # Showing subcategories
@@ -176,6 +176,12 @@ class CategoryPage extends Article {
                        $r.= $ig->toHTML();
                }
 
+               if( $until != '' ) {
+                       $r .= $this->pagingLinks( $this->mTitle, $nextPage, $until, $limit );
+               } elseif( $nextPage != '' || $from != '' ) {
+                       $r .= $this->pagingLinks( $this->mTitle, $from, $nextPage, $limit );
+               }
+
                wfProfileOut( $fname );
                return $r;
        }
@@ -214,7 +220,7 @@ class CategoryPage extends Article {
                }
                return '';
        }
-       
+
        /**
         * Format a list of articles chunked by letter in a three-column
         * list, ordered vertically.
@@ -231,7 +237,7 @@ class CategoryPage extends Article {
                // get and display header
                $r = '<table width="100%"><tr valign="top">';
 
-               $prev_start_char = 'none'; 
+               $prev_start_char = 'none';
 
                // loop through the chunks
                for($startChunk = 0, $endChunk = $chunk, $chunkIndex = 0;
@@ -258,8 +264,8 @@ class CategoryPage extends Article {
                                        }
                                        $cont_msg = "";
                                        if ( $articles_start_char[$index] == $prev_start_char )
-                                               $cont_msg = wfMsg('listingcontinuesabbrev');
-                                       $r .= "<h3>{$articles_start_char[$index]}$cont_msg</h3>\n<ul>";
+                                               $cont_msg = wfMsgHtml('listingcontinuesabbrev');
+                                       $r .= "<h3>" . htmlspecialchars( $articles_start_char[$index] ) . "$cont_msg</h3>\n<ul>";
                                        $prev_start_char = $articles_start_char[$index];
                                }
 
@@ -275,7 +281,7 @@ class CategoryPage extends Article {
                $r .= '</tr></table>';
                return $r;
        }
-       
+
        /**
         * Format a list of articles chunked by letter in a bullet list.
         * @param array $articles
@@ -284,13 +290,13 @@ class CategoryPage extends Article {
         * @access private
         */
        function shortList( $articles, $articles_start_char ) {
-               $r = '<h3>'.$articles_start_char[0]."</h3>\n";
+               $r = '<h3>' . htmlspecialchars( $articles_start_char[0] ) . "</h3>\n";
                $r .= '<ul><li>'.$articles[0].'</li>';
                for ($index = 1; $index < count($articles); $index++ )
                {
                        if ($articles_start_char[$index] != $articles_start_char[$index - 1])
                        {
-                               $r .= "</ul><h3>{$articles_start_char[$index]}</h3>\n<ul>";
+                               $r .= "</ul><h3>" . htmlspecialchars( $articles_start_char[$index] ) . "</h3>\n<ul>";
                        }
 
                        $r .= "<li>{$articles[$index]}</li>";
@@ -298,7 +304,7 @@ class CategoryPage extends Article {
                $r .= '</ul>';
                return $r;
        }
-       
+
        /**
         * @param Title  $title
         * @param string $first
@@ -312,7 +318,7 @@ class CategoryPage extends Article {
                global $wgUser, $wgLang;
                $sk =& $wgUser->getSkin();
                $limitText = $wgLang->formatNum( $limit );
-               
+
                $prevLink = htmlspecialchars( wfMsg( 'prevn', $limitText ) );
                if( $first != '' ) {
                        $prevLink = $sk->makeLinkObj( $title, $prevLink,
@@ -323,7 +329,7 @@ class CategoryPage extends Article {
                        $nextLink = $sk->makeLinkObj( $title, $nextLink,
                                wfArrayToCGI( $query + array( 'from' => $last ) ) );
                }
-               
+
                return "($prevLink) ($nextLink)";
        }
 }