fetch commons descriptions for display on local wikis
[lhc/web/wiklou.git] / includes / CategoryPage.php
index a3e7a71..bb6314f 100644 (file)
@@ -9,7 +9,9 @@
 if( !defined( 'MEDIAWIKI' ) )
        die();
 
-if( $wgCategoryMagicGallery ) 
+global $wgCategoryMagicGallery;
+if( $wgCategoryMagicGallery )
+       /** */
        require_once('ImageGallery.php');
 
 /**
@@ -18,6 +20,8 @@ if( $wgCategoryMagicGallery )
 class CategoryPage extends Article {
 
        function view() {
+               if(!wfRunHooks('CategoryPageView', array(&$this))) return;
+
                if ( NS_CATEGORY == $this->mTitle->getNamespace() ) {
                        $this->openShowCategory();
                }
@@ -87,11 +91,11 @@ class CategoryPage extends Article {
                $limit = 200;
                $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(),
-                              'page_is_redirect' => 0),
+                              'cl_to'           => $this->mTitle->getDBKey()),
+                              #'page_is_redirect' => 0),
                        #+ $pageCondition,
                        $fname,
                        array( 'ORDER BY' => $flip ? 'cl_sortkey DESC' : 'cl_sortkey',
@@ -113,17 +117,19 @@ class CategoryPage extends Article {
                        
                        if( $title->getNamespace() == NS_CATEGORY ) {
                                // Subcategory; strip the 'Category' namespace from the link text.
-                               array_push( $children, $sk->makeKnownLinkObj( $title, $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,
                                // else use sortkey...
+                               $sortkey='';
                                if( $title->getPrefixedText() == $x->cl_sortkey ) {
-                                       array_push( $children_start_char, $wgContLang->firstChar( $x->page_title ) );
+                                       $sortkey=$wgContLang->firstChar( $x->page_title );
                                } else {
-                                       array_push( $children_start_char, $wgContLang->firstChar( $x->cl_sortkey ) ) ;
+                                       $sortkey=$wgContLang->firstChar( $x->cl_sortkey );
                                }
+                               array_push( $children_start_char, $wgContLang->convert( $sortkey ) ) ;
                        } elseif( $wgCategoryMagicGallery && $title->getNamespace() == NS_IMAGE ) {
                                // Show thumbnails of categorized images, in a separate chunk
                                if( $flip ) {
@@ -133,8 +139,8 @@ class CategoryPage extends Article {
                                }
                        } else {
                                // Page in this category
-                               array_push( $articles, $sk->makeKnownLinkObj( $title ) ) ;
-                               array_push( $articles_start_char, $wgContLang->firstChar( $x->cl_sortkey ) ) ;
+                               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 ) ) );
                        }
                }
                $dbr->freeResult( $res );
@@ -232,8 +238,8 @@ class CategoryPage extends Article {
                        $chunkIndex < 3;
                        $chunkIndex++, $startChunk = $endChunk, $endChunk += $chunk + 1)
                {
-
-                       $r .= '<td><ul>';
+                       $r .= "<td>\n";
+                       $atColumnTop = true;
 
                        // output all articles in category
                        for ($index = $startChunk ;
@@ -245,16 +251,24 @@ class CategoryPage extends Article {
                                         ($articles_start_char[$index] != $articles_start_char[$index - 1]) )
 
                                {
+                                       if( $atColumnTop ) {
+                                               $atColumnTop = false;
+                                       } else {
+                                               $r .= "</ul>\n";
+                                       }
                                        $cont_msg = "";
                                        if ( $articles_start_char[$index] == $prev_start_char )
                                                $cont_msg = wfMsg('listingcontinuesabbrev');
-                                       $r .= "</ul><h3>{$articles_start_char[$index]}$cont_msg</h3>\n<ul>";
+                                       $r .= "<h3>{$articles_start_char[$index]}$cont_msg</h3>\n<ul>";
                                        $prev_start_char = $articles_start_char[$index];
                                }
 
                                $r .= "<li>{$articles[$index]}</li>";
                        }
-                       $r .= '</ul></td>';
+                       if( !$atColumnTop ) {
+                               $r .= "</ul>\n";
+                       }
+                       $r .= "</td>\n";
 
 
                }