119 $context = RequestContext::getMainAndWarn( __METHOD__ );
123 $mode = $galleryOptions[
'mode'];
126 $mode = MediaWikiServices::getInstance()->getContentLanguage()->lc( $mode );
128 if ( isset( self::$modeMapping[$mode] ) ) {
129 $class = self::$modeMapping[$mode];
130 return new $class( $mode,
$context );
132 throw new MWException(
"No gallery class registered for mode $mode" );
137 if ( self::$modeMapping ===
null ) {
138 self::$modeMapping = [
139 'traditional' => TraditionalImageGallery::class,
140 'nolines' => NolinesImageGallery::class,
141 'packed' => PackedImageGallery::class,
142 'packed-hover' => PackedHoverImageGallery::class,
143 'packed-overlay' => PackedOverlayImageGallery::class,
144 'slideshow' => SlideshowImageGallery::class,
147 Hooks::runner()->onGalleryGetModes( self::$modeMapping );
169 $galleryOptions = $this->
getConfig()->get(
'GalleryOptions' );
171 $this->mShowBytes = $galleryOptions[
'showBytes'];
172 $this->mShowDimensions = $galleryOptions[
'showDimensions'];
173 $this->mShowFilename =
true;
174 $this->mParser =
false;
175 $this->mHideBadImages =
false;
176 $this->mPerRow = $galleryOptions[
'imagesPerRow'];
177 $this->mWidths = $galleryOptions[
'imageWidth'];
178 $this->mHeights = $galleryOptions[
'imageHeight'];
179 $this->mCaptionLength = $galleryOptions[
'captionLength'];
180 $this->mMode = $mode;
194 $this->mParser = $parser;
201 $this->mHideBadImages = $flag;
210 $this->mCaption = htmlspecialchars( $caption );
219 $this->mCaption = $caption;
230 $this->mPerRow = (int)$num;
242 if ( isset( $parsed[
'width'] ) && $parsed[
'width'] > 0 ) {
243 $this->mWidths = $parsed[
'width'];
255 if ( isset( $parsed[
'width'] ) && $parsed[
'width'] > 0 ) {
256 $this->mHeights = $parsed[
'width'];
289 $loading = self::LOADING_DEFAULT
295 $this->mImages[] = [
$title, $html, $alt, $link, $handlerOpts, $loading ];
316 $loading = self::LOADING_DEFAULT
322 array_unshift( $this->mImages, [ &
$title, $html, $alt, $link, $handlerOpts, $loading ] );
331 return $this->mImages;
339 return empty( $this->mImages );
349 $this->mShowDimensions = (bool)$f;
359 $this->mShowBytes = (bool)$f;
369 $this->mShowFilename = (bool)$f;
382 $this->mAttribs = $attribs;
396 return count( $this->mImages );
405 $this->contextTitle =
$title;
414 return $this->contextTitle;
422 return $this->mParser
423 ? $this->mParser->getTargetLanguage()
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
setContext(IContextSource $context)
Implements some public methods and some protected utility functions which are required by multiple ch...
insert( $title, $html='', $alt='', $link='', $handlerOpts=[], $loading=self::LOADING_DEFAULT)
Add an image at the beginning of the gallery.
setShowDimensions( $f)
Enable/Disable showing of the dimensions of an image in the gallery.
bool string $mCaption
Gallery caption.
Parser false $mParser
Registered parser object for output callbacks.
setHeights( $num)
Set how high each image will be, in pixels.
bool $mShowDimensions
Whether to show the dimensions in categories.
__construct( $mode='traditional', IContextSource $context=null)
Create a new image gallery object.
isEmpty()
isEmpty() returns true if the gallery contains no images
add( $title, $html='', $alt='', $link='', $handlerOpts=[], $loading=self::LOADING_DEFAULT)
Add an image to the gallery.
setAttributes( $attribs)
Set arbitrary attributes to go on the HTML gallery output element.
bool $mHideBadImages
Hide bad images?
setCaption( $caption)
Set the caption (as plain text)
setHideBadImages( $flag=true)
static array $modeMapping
Title null $contextTitle
Contextual title, used when images are being screened against the bad image list.
setCaptionHtml( $caption)
Set the caption (as HTML)
bool int $mCaptionLength
Length to truncate filename to in caption when using "showfilename".
getContextTitle()
Get the contextual title, if applicable.
string $mMode
Gallery mode.
setAdditionalOptions( $options)
Allow setting additional options.
setPerRow( $num)
Set how many images will be displayed per row.
setContextTitle( $title)
Set the contextual title.
bool $mShowFilename
Whether to show the filename.
setParser( $parser)
Register a parser object.
static factory( $mode=false, IContextSource $context=null)
Get a new image gallery.
bool $mShowBytes
Whether to show the filesize in bytes in categories.
toHTML()
Display an html representation of the gallery.
setShowBytes( $f)
Enable/Disable showing of the file size of an image in the gallery.
getRenderLang()
Determines the correct language to be used for this image gallery.
setWidths( $num)
Set how wide each image will be, in pixels.
getImages()
Returns the list of images this gallery contains.
array[] $mImages
Gallery images.
setShowFilename( $f)
Enable/Disable showing of the filename of an image in the gallery.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
static parseWidthParam( $value, $parseHeight=true)
Parsed a width param of imagelink like 300px or 200x300px.
Represents a title within MediaWiki.
Interface for objects which can provide a MediaWiki context on request.
getConfig()
Get the site configuration.