On Category: pages, show images as thumbnail gallery, and not
authorJens Frank <jeluf@users.mediawiki.org>
Thu, 30 Sep 2004 21:36:12 +0000 (21:36 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Thu, 30 Sep 2004 21:36:12 +0000 (21:36 +0000)
as articles. Can be disabled by setting $wgCategoryMagicGallery to false

includes/CategoryPage.php
includes/DefaultSettings.php
includes/ImageGallery.php

index cd864e7..3e89a5f 100644 (file)
@@ -6,6 +6,9 @@
  * @package MediaWiki
  */
 
+if ( $wgCategoryMagicGallery ) 
+       require_once('ImageGallery.php');
+
 /**
  * @package MediaWiki 
  */
@@ -103,7 +106,7 @@ class CategoryPage extends Article {
        }
 
         function newCategoryMagic () {
-                global $wgContLang,$wgUser;
+                global $wgContLang,$wgUser, $wgCategoryMagicGallery;
 
                $sk =& $wgUser->getSkin();
 
@@ -116,6 +119,10 @@ class CategoryPage extends Article {
                 $data = array () ;
                 $id = $this->mTitle->getArticleID() ;
 
+               if ( $wgCategoryMagicGallery ) {
+                       $ig = new ImageGallery();
+               }
+
                 # FIXME: add limits
                 $dbr =& wfGetDB( DB_SLAVE );
                 $cur = $dbr->tableName( 'cur' );
@@ -130,9 +137,9 @@ class CategoryPage extends Article {
                         $t = $ns = $wgContLang->getNsText ( $x->cur_namespace ) ;
                         if ( $t != '' ) $t .= ':' ;
                         $t .= $x->cur_title ;
+                       $ctitle = str_replace( '_',' ',$x->cur_title );
 
                         if ( $x->cur_namespace == NS_CATEGORY ) {
-                                $ctitle = str_replace( '_',' ',$x->cur_title );
                                 array_push ( $children, $sk->makeKnownLink ( $t, $ctitle ) ) ; # Subcategory
 
                                 // If there's a link from Category:A to Category:B, the sortkey of the resulting
@@ -144,7 +151,9 @@ class CategoryPage extends Article {
                                 } else {
                                         array_push ( $children_start_char, $wgContLang->firstChar( $x->cl_sortkey ) ) ;
                                 }
-                        } else {
+                        } elseif ( $wgCategoryMagicGallery && $x->cur_namespace == NS_IMAGE ) {
+                               $ig->add( new Image( $x->cur_title ) );
+                       } else {
                                 array_push ( $articles , $sk->makeKnownLink ( $t ) ) ; # Page in this category
                                 array_push ( $articles_start_char, $wgContLang->firstChar( $x->cl_sortkey ) ) ;
                         }
@@ -286,6 +295,11 @@ class CategoryPage extends Article {
                         }
                         $r .= '</ul>';
                 }
+
+               if ( $wgCategoryMagicGallery && ! $ig->isEmpty() ) {
+                       $r.= $ig->toHTML();
+               }
+
                 return $r ;
         }
 }
index a07faa1..ea89a14 100644 (file)
@@ -732,6 +732,10 @@ $wgNavigationLinks = array (
        array( 'text'=>'sitesupport',   'href'=>'sitesupport-url' ),
 );
 
+# On category pages, show thumbnail gallery for images belonging to that category
+# instead of listing them as articles.
+$wgCategoryMagicGallery = true;
+
 
 } else {
        die();
index d29cf0d..7c6c153 100644 (file)
@@ -12,20 +12,49 @@ if( defined( 'MEDIAWIKI' ) ) {
 
 /**
  * Image gallery
+ * 
+ * Add images to the gallery using add(), then render that list to HTML using toHTML().
+ *
  * @package MediaWiki
  */
 class ImageGallery
 {
        var $mImages;
 
+       /** 
+        * Create a new image gallery object.
+        */
        function ImageGallery( ) {
                $this->mImages=array();
        }
 
+       /**
+        * Add an image to the gallery.
+        *
+        * @param Image  $image  Image object that is added to the gallery
+        * @param string $text   Additional text to be shown. The name and size of the image are always shown.
+        */
        function add( $image, $text='' ) {
                $this->mImages[] = array( &$image, $text );
        }
 
+       /**
+        * isEmpty() returns false iff the gallery doesn't contain any images
+        */
+       function isEmpty() {
+               return empty( $this->mImages );
+       }
+
+       /**
+        * Return a HTML representation of the image gallery
+        * 
+        * For each image in the gallery, display
+        * - a thumbnail
+        * - the image name
+        * - the additional text provided when adding the image
+        * - the size of the image
+        *
+        */
        function toHTML() {
                global $wgLang, $wgContLang, $wgUser;
 
@@ -43,16 +72,15 @@ class ImageGallery
                        //TODO
                        //$ul = $sk->makeLink( $wgContLang->getNsText( Namespace::getUser() ) . ":{$ut}", $ut );
 
-                       $ilink = '<a href="' . $img->getURL() .  '">' . $nt->getText() . '</a>';
                        $nb = wfMsg( "nbytes", $wgLang->formatNum( $img->getSize() ) );
 
                        $s .= ($i%4==0) ? '<tr>' : '';
                        $s .= '<td valign="top" width="150px" style="background-color:#F0F0F0;">' .
                                '<table width="100%" height="150px">'.
                                '<tr><td align="center" valign="center" style="background-color:#F8F8F8;border:solid 1px #888888;">' .
-                               '<img  src="'.$img->createThumb(120,120).'" alt=""></td></tr></table> ' .
-                               '(' .  $sk->makeKnownLinkObj( $nt, wfMsg( "imgdesc" ) ) .
-                               ") {$ilink}<br />{$text}{$nb}<br />" ;
+                               $sk->makeKnownLinkObj( $nt, '<img  src="'.$img->createThumb(120,120).'" alt="">' ) . '</td></tr></table> ' .
+                               $sk->makeKnownLinkObj( $nt, Language::truncate( $nt->getText(), 20, '...' ) ) .
+                               "<br />{$text}{$nb}<br />" ;
 
                        $s .= '</td>' .  (($i%4==3) ? '</tr>' : '');