Fix up AJAX watch and enable it by default.
[lhc/web/wiklou.git] / includes / CategoryPage.php
index 9709033..2c9a163 100644 (file)
@@ -3,17 +3,23 @@
  * Special handling for category description pages
  * Modelled after ImagePage.php
  *
- * @package MediaWiki
  */
 
 if( !defined( 'MEDIAWIKI' ) )
        die( 1 );
 
 /**
- * @package MediaWiki
  */
 class CategoryPage extends Article {
        function view() {
+               global $wgRequest, $wgUser;
+
+               $diff = $wgRequest->getVal( 'diff' );
+               $diffOnly = $wgRequest->getBool( 'diffonly', $wgUser->getOption( 'diffonly' ) );
+
+               if ( isset( $diff ) && $diffOnly )
+                       return Article::view();
+
                if(!wfRunHooks('CategoryPageView', array(&$this))) return;
 
                if ( NS_CATEGORY == $this->mTitle->getNamespace() ) {
@@ -49,7 +55,8 @@ class CategoryViewer {
        var $title, $limit, $from, $until,
                $articles, $articles_start_char, 
                $children, $children_start_char,
-               $showGallery, $gallery;
+               $showGallery, $gallery,
+               $skin;
 
        function __construct( $title, $from = '', $until = '' ) {
                global $wgCategoryPagingLimit;
@@ -98,13 +105,21 @@ class CategoryViewer {
                }
        }
 
+       function getSkin() {
+               if ( !$this->skin ) {
+                       global $wgUser;
+                       $this->skin = $wgUser->getSkin();
+               }
+               return $this->skin;
+       }
+
        /**
         * Add a subcategory to the internal lists
         */
        function addSubcategory( $title, $sortkey, $pageLength ) {
                global $wgContLang;
                // Subcategory; strip the 'Category' namespace from the link text.
-               $this->children[] = Linker::makeKnownLinkObj( 
+               $this->children[] = $this->getSkin()->makeKnownLinkObj( 
                        $title, $wgContLang->convertHtml( $title->getText() ) );
 
                $this->children_start_char[] = $this->getSubcategorySortChar( $title, $sortkey );
@@ -132,7 +147,7 @@ class CategoryViewer {
        /**
         * Add a page in the image namespace
         */
-       function addImage( $title, $sortkey, $pageLength ) {
+       function addImage( Title $title, $sortkey, $pageLength, $isRedirect = false ) {
                if ( $this->showGallery ) {
                        $image = new Image( $title );
                        if( $this->flip ) {
@@ -141,18 +156,21 @@ class CategoryViewer {
                                $this->gallery->add( $image );
                        }
                } else {
-                       $this->addPage( $title, $sortkey, $pageLength );
+                       $this->addPage( $title, $sortkey, $pageLength, $isRedirect );
                }
        }
 
        /**
         * Add a miscellaneous page
         */
-       function addPage( $title, $sortkey, $pageLength ) {
+       function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) {
                global $wgContLang;
-               $this->articles[] = Linker::makeSizeLinkObj( 
+               $link = $this->getSkin()->makeSizeLinkObj( 
                        $pageLength, $title, $wgContLang->convert( $title->getPrefixedText() ) 
                );
+               if ($isRedirect)
+                       $link = '<span class="redirect-in-category">'.$link.'</span>';
+               $this->articles[] = $link;
                $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );
        }
 
@@ -166,7 +184,7 @@ class CategoryViewer {
        }
 
        function doCategoryQuery() {
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
                if( $this->from != '' ) {
                        $pageCondition = 'cl_sortkey >= ' . $dbr->addQuotes( $this->from );
                        $this->flip = false;
@@ -179,7 +197,7 @@ class CategoryViewer {
                }
                $res = $dbr->select(
                        array( 'page', 'categorylinks' ),
-                       array( 'page_title', 'page_namespace', 'page_len', 'cl_sortkey' ),
+                       array( 'page_title', 'page_namespace', 'page_len', 'page_is_redirect', 'cl_sortkey' ),
                        array( $pageCondition,
                               'cl_from          =  page_id',
                               'cl_to'           => $this->title->getDBKey()),
@@ -187,6 +205,7 @@ class CategoryViewer {
                        #+ $pageCondition,
                        __METHOD__,
                        array( 'ORDER BY' => $this->flip ? 'cl_sortkey DESC' : 'cl_sortkey',
+                              'USE INDEX' => 'cl_sortkey', 
                               'LIMIT'    => $this->limit + 1 ) );
 
                $count = 0;
@@ -203,10 +222,10 @@ class CategoryViewer {
 
                        if( $title->getNamespace() == NS_CATEGORY ) {
                                $this->addSubcategory( $title, $x->cl_sortkey, $x->page_len );
-                       } elseif( $title->getNamespace() == NS_IMAGE ) {
-                               $this->addImage( $title, $x->cl_sortkey, $x->page_len );
+                       } elseif( $this->showGallery && $title->getNamespace() == NS_IMAGE ) {
+                               $this->addImage( $title, $x->cl_sortkey, $x->page_len, $x->page_is_redirect );
                        } else {
-                               $this->addPage( $title, $x->cl_sortkey, $x->page_len );
+                               $this->addPage( $title, $x->cl_sortkey, $x->page_len, $x->page_is_redirect );
                        }
                }
                $dbr->freeResult( $res );
@@ -225,11 +244,12 @@ class CategoryViewer {
        function getSubcategorySection() {
                # Don't show subcategories section if there are none.
                $r = '';
-               if( count( $this->children ) > 0 ) {
+               $c = count( $this->children );
+               if( $c > 0 ) {
                        # Showing subcategories
                        $r .= "<div id=\"mw-subcategories\">\n";
                        $r .= '<h2>' . wfMsg( 'subcategories' ) . "</h2>\n";
-                       $r .= wfMsgExt( 'subcategorycount', array( 'parse' ), count( $this->children) );
+                       $r .= wfMsgExt( 'subcategorycount', array( 'parse' ), $c );
                        $r .= $this->formatList( $this->children, $this->children_start_char );
                        $r .= "\n</div>";
                }
@@ -238,17 +258,25 @@ class CategoryViewer {
 
        function getPagesSection() {
                $ti = htmlspecialchars( $this->title->getText() );
-               $r = "<div id=\"mw-pages\">\n";
-               $r .= '<h2>' . wfMsg( 'category_header', $ti ) . "</h2>\n";
-               $r .= wfMsgExt( 'categoryarticlecount', array( 'parse' ), count( $this->articles) );
-               $r .= $this->formatList( $this->articles, $this->articles_start_char );
-               $r .= "\n</div>";
+               # Don't show articles section if there are none.
+               $r = '';
+               $c = count( $this->articles );
+               if( $c > 0 ) {
+                       $r = "<div id=\"mw-pages\">\n";
+                       $r .= '<h2>' . wfMsg( 'category_header', $ti ) . "</h2>\n";
+                       $r .= wfMsgExt( 'categoryarticlecount', array( 'parse' ), $c );
+                       $r .= $this->formatList( $this->articles, $this->articles_start_char );
+                       $r .= "\n</div>";
+               }
                return $r;
        }
 
        function getImageSection() {
                if( $this->showGallery && ! $this->gallery->isEmpty() ) {
-                       return $this->gallery->toHTML();
+                       return "<div id=\"mw-category-media\">\n" .
+                       '<h2>' . wfMsg( 'category-media-header', htmlspecialchars($this->title->getText()) ) . "</h2>\n" .
+                       wfMsgExt( 'category-media-count', array( 'parse' ), $this->gallery->count() ) .
+                       $this->gallery->toHTML() . "\n</div>";
                } else {
                        return '';
                }
@@ -379,16 +407,17 @@ class CategoryViewer {
         */
        function pagingLinks( $title, $first, $last, $limit, $query = array() ) {
                global $wgUser, $wgLang;
+               $sk = $this->getSkin();
                $limitText = $wgLang->formatNum( $limit );
 
                $prevLink = htmlspecialchars( wfMsg( 'prevn', $limitText ) );
                if( $first != '' ) {
-                       $prevLink = Linker::makeLinkObj( $title, $prevLink,
+                       $prevLink = $sk->makeLinkObj( $title, $prevLink,
                                wfArrayToCGI( $query + array( 'until' => $first ) ) );
                }
                $nextLink = htmlspecialchars( wfMsg( 'nextn', $limitText ) );
                if( $last != '' ) {
-                       $nextLink = Linker::makeLinkObj( $title, $nextLink,
+                       $nextLink = $sk->makeLinkObj( $title, $nextLink,
                                wfArrayToCGI( $query + array( 'from' => $last ) ) );
                }