108 private static $modeMapping;
125 $galleryOptions = $context->getConfig()->get( MainConfigNames::GalleryOptions );
126 $mode = $galleryOptions[
'mode'];
129 $mode = MediaWikiServices::getInstance()->getContentLanguage()->lc( $mode );
131 if ( isset( self::$modeMapping[$mode] ) ) {
132 $class = self::$modeMapping[$mode];
133 return new $class( $mode, $context );
139 private static function loadModes() {
140 if ( self::$modeMapping ===
null ) {
141 self::$modeMapping = [
142 'traditional' => TraditionalImageGallery::class,
143 'nolines' => NolinesImageGallery::class,
144 'packed' => PackedImageGallery::class,
145 'packed-hover' => PackedHoverImageGallery::class,
146 'packed-overlay' => PackedOverlayImageGallery::class,
147 'slideshow' => SlideshowImageGallery::class,
150 (
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )
151 ->onGalleryGetModes( self::$modeMapping );
173 $galleryOptions = $this->
getConfig()->get( MainConfigNames::GalleryOptions );
175 $this->mShowBytes = $galleryOptions[
'showBytes'];
176 $this->mShowDimensions = $galleryOptions[
'showDimensions'];
177 $this->mShowFilename =
true;
178 $this->mParser =
false;
179 $this->mHideBadImages =
false;
180 $this->mPerRow = $galleryOptions[
'imagesPerRow'];
181 $this->mWidths = $galleryOptions[
'imageWidth'];
182 $this->mHeights = $galleryOptions[
'imageHeight'];
183 $this->mCaptionLength = $galleryOptions[
'captionLength'];
184 $this->mMode = $mode;
198 $this->mParser = $parser;
205 $this->mHideBadImages = $flag;
214 $this->mCaption = htmlspecialchars( $caption );
223 $this->mCaption = $caption;
234 $this->mPerRow = (int)$num;
246 if ( isset( $parsed[
'width'] ) && $parsed[
'width'] > 0 ) {
247 $this->mWidths = $parsed[
'width'];
259 if ( isset( $parsed[
'width'] ) && $parsed[
'width'] > 0 ) {
260 $this->mHeights = $parsed[
'width'];
294 $loading = self::LOADING_DEFAULT,
295 ?array $imageOptions =
null
297 if ( $title instanceof
File ) {
299 $title = $title->getTitle();
301 $this->mImages[] = [ $title, $html, $alt, $link, $handlerOpts, $loading, $imageOptions ];
302 wfDebug(
'ImageGallery::add ' . $title->getText() );
323 $loading = self::LOADING_DEFAULT,
324 ?array $imageOptions =
null
326 if ( $title instanceof
File ) {
328 $title = $title->getTitle();
330 array_unshift( $this->mImages, [ &$title, $html, $alt, $link, $handlerOpts, $loading, $imageOptions ] );
347 return $this->mImages === [];
357 $this->mShowDimensions = (bool)$f;
367 $this->mShowBytes = (bool)$f;
377 $this->mShowFilename = (bool)$f;
390 $this->mAttribs = $attribs;
404 return count( $this->mImages );
413 $this->contextTitle = $title;
430 return $this->mParser
431 ? $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...
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.
__construct( $mode='traditional', IContextSource $context=null)
Create a new image gallery object.
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)
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.
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.
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().
A class containing constants representing the names of configuration variables.
static parseWidthParam( $value, $parseHeight=true)
Parsed a width param of imagelink like 300px or 200x300px.
static getMainAndWarn( $func=__METHOD__)
Get the RequestContext object associated with the main request and gives a warning to the log,...
Interface for objects which can provide a MediaWiki context on request.