83 protected $mCaptionLength =
true;
102 protected $mAttribs = [];
114 private static $modeMapping;
128 $context = RequestContext::getMainAndWarn( __METHOD__ );
131 $galleryOptions = $context->getConfig()->get( MainConfigNames::GalleryOptions );
132 $mode = $galleryOptions[
'mode'];
135 $mode = MediaWikiServices::getInstance()->getContentLanguage()->lc( $mode );
137 if ( isset( self::$modeMapping[$mode] ) ) {
138 $class = self::$modeMapping[$mode];
139 return new $class( $mode, $context );
145 private static function loadModes() {
146 if ( self::$modeMapping ===
null ) {
147 self::$modeMapping = [
148 'traditional' => TraditionalImageGallery::class,
149 'nolines' => NolinesImageGallery::class,
150 'packed' => PackedImageGallery::class,
151 'packed-hover' => PackedHoverImageGallery::class,
152 'packed-overlay' => PackedOverlayImageGallery::class,
153 'slideshow' => SlideshowImageGallery::class,
156 (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
157 ->onGalleryGetModes( self::$modeMapping );
179 $galleryOptions = $this->
getConfig()->get( MainConfigNames::GalleryOptions );
181 $this->mShowBytes = $galleryOptions[
'showBytes'];
182 $this->mShowDimensions = $galleryOptions[
'showDimensions'];
183 $this->mShowFilename =
true;
184 $this->mParser =
false;
185 $this->mHideBadImages =
false;
186 $this->mPerRow = $galleryOptions[
'imagesPerRow'];
187 $this->mWidths = $galleryOptions[
'imageWidth'];
188 $this->mHeights = $galleryOptions[
'imageHeight'];
189 $this->mCaptionLength = $galleryOptions[
'captionLength'];
190 $this->mMode = $mode;
204 $this->mParser = $parser;
211 $this->mHideBadImages = $flag;
220 $this->mCaption = htmlspecialchars( $caption );
229 $this->mCaption = $caption;
240 $this->mPerRow = (int)$num;
251 $parser = $this->mParser;
254 $parser = MediaWikiServices::getInstance()->getParser();
256 $parsed = $parser->parseWidthParam( $num,
false );
257 if ( isset( $parsed[
'width'] ) && $parsed[
'width'] > 0 ) {
258 $this->mWidths = $parsed[
'width'];
269 $parser = $this->mParser;
272 $parser = MediaWikiServices::getInstance()->getParser();
274 $parsed = $parser->parseWidthParam( $num,
false );
275 if ( isset( $parsed[
'width'] ) && $parsed[
'width'] > 0 ) {
276 $this->mHeights = $parsed[
'width'];
310 $loading = self::LOADING_DEFAULT,
311 ?array $imageOptions =
null
313 if ( $title instanceof
File ) {
315 $title = $title->getTitle();
317 $this->mImages[] = [ $title, $html, $alt, $link, $handlerOpts, $loading, $imageOptions ];
318 wfDebug(
'ImageGallery::add ' . $title->getText() );
339 $loading = self::LOADING_DEFAULT,
340 ?array $imageOptions =
null
342 if ( $title instanceof
File ) {
344 $title = $title->getTitle();
346 array_unshift( $this->mImages, [ $title, $html, $alt, $link, $handlerOpts, $loading, $imageOptions ] );
355 return $this->mImages;
363 return $this->mImages === [];
373 $this->mShowDimensions = (bool)$f;
383 $this->mShowBytes = (bool)$f;
393 $this->mShowFilename = (bool)$f;
406 $this->mAttribs = $attribs;
420 return count( $this->mImages );
429 $this->contextTitle = $title;
438 return $this->contextTitle;
446 return $this->mParser
447 ? $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.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
setShowDimensions( $f)
Enable/Disable showing of the dimensions of an image in the gallery.
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.
isEmpty()
isEmpty() returns true if the gallery contains no images
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)
__construct( $mode='traditional', ?IContextSource $context=null)
Create a new image gallery object.
string false $mCaption
Gallery caption.
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.
static factory( $mode=false, ?IContextSource $context=null)
Get a new image gallery.
setContextTitle( $title)
Set the contextual title.
bool $mShowFilename
Whether to show the filename.
setParser( $parser)
Register a parser object.
insert( $title, $html='', $alt='', $link='', $handlerOpts=[], $loading=self::LOADING_DEFAULT, ?array $imageOptions=null)
Add an image at the beginning of the 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.
add( $title, $html='', $alt='', $link='', $handlerOpts=[], $loading=self::LOADING_DEFAULT, ?array $imageOptions=null)
Add an image to the gallery.
array[] $mImages
Gallery images.
setShowFilename( $f)
Enable/Disable showing of the filename of an image in the gallery.
Class for exceptions thrown by ImageGalleryBase::factory().
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
setContext(IContextSource $context)
Group all the pieces relevant to the context of a request into one instance.
A class containing constants representing the names of configuration variables.
Interface for objects which can provide a MediaWiki context on request.