* @package MediaWiki
*/
+if ( $wgCategoryMagicGallery )
+ require_once('ImageGallery.php');
+
/**
* @package MediaWiki
*/
}
function newCategoryMagic () {
- global $wgContLang,$wgUser;
+ global $wgContLang,$wgUser, $wgCategoryMagicGallery;
$sk =& $wgUser->getSkin();
$data = array () ;
$id = $this->mTitle->getArticleID() ;
+ if ( $wgCategoryMagicGallery ) {
+ $ig = new ImageGallery();
+ }
+
# FIXME: add limits
$dbr =& wfGetDB( DB_SLAVE );
$cur = $dbr->tableName( 'cur' );
$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
} 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 ) ) ;
}
}
$r .= '</ul>';
}
+
+ if ( $wgCategoryMagicGallery && ! $ig->isEmpty() ) {
+ $r.= $ig->toHTML();
+ }
+
return $r ;
}
}
/**
* 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;
//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>' : '');