From: Jens Frank Date: Thu, 30 Sep 2004 21:36:12 +0000 (+0000) Subject: On Category: pages, show images as thumbnail gallery, and not X-Git-Tag: 1.5.0alpha1~1723 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=aee58e0985704eae2cdbd0c013bea6b6fc787abb;p=lhc%2Fweb%2Fwiklou.git On Category: pages, show images as thumbnail gallery, and not as articles. Can be disabled by setting $wgCategoryMagicGallery to false --- diff --git a/includes/CategoryPage.php b/includes/CategoryPage.php index cd864e7104..3e89a5fec2 100644 --- a/includes/CategoryPage.php +++ b/includes/CategoryPage.php @@ -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 .= ''; } + + if ( $wgCategoryMagicGallery && ! $ig->isEmpty() ) { + $r.= $ig->toHTML(); + } + return $r ; } } diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index a07faa1213..ea89a14488 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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(); diff --git a/includes/ImageGallery.php b/includes/ImageGallery.php index d29cf0d07e..7c6c153354 100644 --- a/includes/ImageGallery.php +++ b/includes/ImageGallery.php @@ -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 = '' . $nt->getText() . ''; $nb = wfMsg( "nbytes", $wgLang->formatNum( $img->getSize() ) ); $s .= ($i%4==0) ? '' : ''; $s .= '' . ''. '
' . - '
' . - '(' . $sk->makeKnownLinkObj( $nt, wfMsg( "imgdesc" ) ) . - ") {$ilink}
{$text}{$nb}
" ; + $sk->makeKnownLinkObj( $nt, '' ) . ' ' . + $sk->makeKnownLinkObj( $nt, Language::truncate( $nt->getText(), 20, '...' ) ) . + "
{$text}{$nb}
" ; $s .= '' . (($i%4==3) ? '' : '');