MediaWiki  master
ImageGalleryBase Class Reference

Image gallery. More...

Inheritance diagram for ImageGalleryBase:
Collaboration diagram for ImageGalleryBase:

Public Member Functions

 __construct ( $mode='traditional', IContextSource $context=null)
 Create a new image gallery object. More...
 
 add ( $title, $html='', $alt='', $link='', $handlerOpts=[], $loading=self::LOADING_DEFAULT)
 Add an image to the gallery. More...
 
 count ()
 
 getContextTitle ()
 Get the contextual title, if applicable. More...
 
 getImages ()
 Returns the list of images this gallery contains. More...
 
 insert ( $title, $html='', $alt='', $link='', $handlerOpts=[], $loading=self::LOADING_DEFAULT)
 Add an image at the beginning of the gallery. More...
 
 isEmpty ()
 isEmpty() returns true if the gallery contains no images More...
 
 setAdditionalOptions ( $options)
 Allow setting additional options. More...
 
 setAttributes ( $attribs)
 Set arbitrary attributes to go on the HTML gallery output element. More...
 
 setCaption ( $caption)
 Set the caption (as plain text) More...
 
 setCaptionHtml ( $caption)
 Set the caption (as HTML) More...
 
 setContextTitle ( $title)
 Set the contextual title. More...
 
 setHeights ( $num)
 Set how high each image will be, in pixels. More...
 
 setHideBadImages ( $flag=true)
 Set bad image flag. More...
 
 setParser ( $parser)
 Register a parser object. More...
 
 setPerRow ( $num)
 Set how many images will be displayed per row. More...
 
 setShowBytes ( $f)
 Enable/Disable showing of the file size of an image in the gallery. More...
 
 setShowDimensions ( $f)
 Enable/Disable showing of the dimensions of an image in the gallery. More...
 
 setShowFilename ( $f)
 Enable/Disable showing of the filename of an image in the gallery. More...
 
 setWidths ( $num)
 Set how wide each image will be, in pixels. More...
 
 toHTML ()
 Display an html representation of the gallery. More...
 
- Public Member Functions inherited from ContextSource
 canUseWikiPage ()
 Check whether a WikiPage object can be get with getWikiPage(). More...
 
 exportSession ()
 Export the resolved user IP, HTTP headers, user ID, and session ID. More...
 
 getConfig ()
 
 getContext ()
 Get the base IContextSource object. More...
 
 getLanguage ()
 
 getOutput ()
 
 getRequest ()
 
 getSkin ()
 
 getStats ()
 
 getTiming ()
 
 getTitle ()
 
 getUser ()
 Stable to override. More...
 
 getWikiPage ()
 Get the WikiPage object. More...
 
 msg ( $key,... $params)
 Get a Message object with context set Parameters are the same as wfMessage() More...
 
 setContext (IContextSource $context)
 

Static Public Member Functions

static factory ( $mode=false, IContextSource $context=null)
 Get a new image gallery. More...
 

Public Attributes

Parser false $mParser
 Registered parser object for output callbacks. More...
 
const LOADING_DEFAULT = 1
 
const LOADING_LAZY = 2
 

Protected Member Functions

 getRenderLang ()
 Determines the correct language to be used for this image gallery. More...
 

Protected Attributes

Title null $contextTitle = null
 Contextual title, used when images are being screened against the bad image list. More...
 
array $mAttribs = []
 
bool string $mCaption = false
 Gallery caption. More...
 
bool int $mCaptionLength = true
 Length to truncate filename to in caption when using "showfilename". More...
 
int $mHeights
 
bool $mHideBadImages
 Hide blacklisted images? More...
 
array[] $mImages
 Gallery images -var array<int,array{0:Title,1:string,2:string,3:string,4:array,5:int}> More...
 
string $mMode
 Gallery mode. More...
 
int $mPerRow
 
bool $mShowBytes
 Whether to show the filesize in bytes in categories. More...
 
bool $mShowDimensions
 Whether to show the dimensions in categories. More...
 
bool $mShowFilename
 Whether to show the filename. More...
 
int $mWidths
 

Static Private Member Functions

static loadModes ()
 

Static Private Attributes

static array $modeMapping
 

Detailed Description

Image gallery.

Add images to the gallery using add(), then render that list to HTML using toHTML(). Stable to extend

Definition at line 32 of file ImageGalleryBase.php.

Constructor & Destructor Documentation

◆ __construct()

ImageGalleryBase::__construct (   $mode = 'traditional',
IContextSource  $context = null 
)

Create a new image gallery object.

You should not call this directly, but instead use ImageGalleryBase::factory().

Stable to call

Note
constructors of subclasses must have a compatible signature for use by the factory() method.
Parameters
string$mode
IContextSource | null$context

Reimplemented in PackedImageGallery, and SlideshowImageGallery.

Definition at line 164 of file ImageGalleryBase.php.

References ContextSource\$context, ContextSource\getConfig(), and ContextSource\setContext().

Member Function Documentation

◆ add()

ImageGalleryBase::add (   $title,
  $html = '',
  $alt = '',
  $link = '',
  $handlerOpts = [],
  $loading = self::LOADING_DEFAULT 
)

Add an image to the gallery.

Parameters
Title$titleTitle object of the image that is added to the gallery
string$htmlAdditional HTML text to be shown. The name and size of the image are always shown.
string$altAlt text for the image
string$linkOverride image link (optional)
array$handlerOptsArray of options for image handler (aka page number)
int$loadingSets loading attribute of the underlying (optional)

Definition at line 284 of file ImageGalleryBase.php.

References $title, and wfDebug().

◆ count()

ImageGalleryBase::count ( )
Returns
int Number of images in the gallery

Definition at line 396 of file ImageGalleryBase.php.

◆ factory()

static ImageGalleryBase::factory (   $mode = false,
IContextSource  $context = null 
)
static

Get a new image gallery.

This is the method other callers should use to get a gallery.

Parameters
string | bool$modeMode to use. False to use the default
IContextSource | null$context
Returns
ImageGalleryBase
Exceptions
MWException

Definition at line 116 of file ImageGalleryBase.php.

References ContextSource\$context, IContextSource\getConfig(), RequestContext\getMainAndWarn(), and loadModes().

Referenced by CategoryViewer\clearCategoryState(), SpecialUpload\getDupeWarning(), NewFilesPager\getStartBody(), ImageQueryPage\outputResults(), and Parser\renderImageGallery().

◆ getContextTitle()

ImageGalleryBase::getContextTitle ( )

Get the contextual title, if applicable.

Returns
Title|null

Definition at line 414 of file ImageGalleryBase.php.

References $contextTitle.

◆ getImages()

ImageGalleryBase::getImages ( )

Returns the list of images this gallery contains.

Returns
array[] -return array<int,array{0:Title,1:string,2:string,3:string,4:array}>

Definition at line 331 of file ImageGalleryBase.php.

References $mImages.

◆ getRenderLang()

ImageGalleryBase::getRenderLang ( )
protected

Determines the correct language to be used for this image gallery.

Returns
Language

Definition at line 422 of file ImageGalleryBase.php.

References ContextSource\getLanguage().

Referenced by TraditionalImageGallery\toHTML().

◆ insert()

ImageGalleryBase::insert (   $title,
  $html = '',
  $alt = '',
  $link = '',
  $handlerOpts = [],
  $loading = self::LOADING_DEFAULT 
)

Add an image at the beginning of the gallery.

Parameters
Title$titleTitle object of the image that is added to the gallery
string$htmlAdditional HTML text to be shown. The name and size of the image are always shown.
string$altAlt text for the image
string$linkOverride image link (optional)
array$handlerOptsArray of options for image handler (aka page number)
int$loadingSets loading attribute of the underlying (optional)

Definition at line 311 of file ImageGalleryBase.php.

References $title.

◆ isEmpty()

ImageGalleryBase::isEmpty ( )

isEmpty() returns true if the gallery contains no images

Returns
bool

Definition at line 339 of file ImageGalleryBase.php.

◆ loadModes()

static ImageGalleryBase::loadModes ( )
staticprivate

Definition at line 136 of file ImageGalleryBase.php.

References Hooks\runner().

Referenced by factory().

◆ setAdditionalOptions()

ImageGalleryBase::setAdditionalOptions (   $options)

Allow setting additional options.

This is meant to allow extensions to add additional parameters to <gallery> parser tag.

Stable to override

Parameters
array$optionsAttributes of gallery tag

Reimplemented in SlideshowImageGallery.

Definition at line 270 of file ImageGalleryBase.php.

◆ setAttributes()

ImageGalleryBase::setAttributes (   $attribs)

Set arbitrary attributes to go on the HTML gallery output element.

Should be suitable for a

.

Note – if taking from user input, you should probably run through Sanitizer::validateAttributes() first.

Parameters
array$attribsArray of HTML attribute pairs

Definition at line 382 of file ImageGalleryBase.php.

◆ setCaption()

ImageGalleryBase::setCaption (   $caption)

Set the caption (as plain text)

Parameters
string$caption

Definition at line 210 of file ImageGalleryBase.php.

◆ setCaptionHtml()

ImageGalleryBase::setCaptionHtml (   $caption)

Set the caption (as HTML)

Parameters
string$caption

Definition at line 219 of file ImageGalleryBase.php.

◆ setContextTitle()

ImageGalleryBase::setContextTitle (   $title)

Set the contextual title.

Parameters
Title | null$titleContextual title

Definition at line 405 of file ImageGalleryBase.php.

References $title.

◆ setHeights()

ImageGalleryBase::setHeights (   $num)

Set how high each image will be, in pixels.

Parameters
string$numNumber. Unit other than 'px is invalid. Invalid numbers and those below 0 are ignored.

Definition at line 254 of file ImageGalleryBase.php.

References Parser\parseWidthParam().

◆ setHideBadImages()

ImageGalleryBase::setHideBadImages (   $flag = true)

Set bad image flag.

Parameters
bool$flag

Definition at line 201 of file ImageGalleryBase.php.

◆ setParser()

ImageGalleryBase::setParser (   $parser)

Register a parser object.

If you do not set this and the output of this gallery ends up in parser cache, the javascript will break!

Note
This also triggers using the page's target language instead of the user language.
Parameters
Parser$parser

Definition at line 193 of file ImageGalleryBase.php.

◆ setPerRow()

ImageGalleryBase::setPerRow (   $num)

Set how many images will be displayed per row.

Parameters
int$numInteger >= 0; If perrow=0 the gallery layout will adapt to screensize invalid numbers will be rejected

Reimplemented in PackedImageGallery.

Definition at line 229 of file ImageGalleryBase.php.

◆ setShowBytes()

ImageGalleryBase::setShowBytes (   $f)

Enable/Disable showing of the file size of an image in the gallery.

Enabled by default.

Parameters
bool$fSet to false to disable

Definition at line 359 of file ImageGalleryBase.php.

◆ setShowDimensions()

ImageGalleryBase::setShowDimensions (   $f)

Enable/Disable showing of the dimensions of an image in the gallery.

Enabled by default.

Parameters
bool$fSet to false to disable

Definition at line 349 of file ImageGalleryBase.php.

◆ setShowFilename()

ImageGalleryBase::setShowFilename (   $f)

Enable/Disable showing of the filename of an image in the gallery.

Enabled by default.

Parameters
bool$fSet to false to disable

Definition at line 369 of file ImageGalleryBase.php.

◆ setWidths()

ImageGalleryBase::setWidths (   $num)

Set how wide each image will be, in pixels.

Parameters
string$numNumber. Unit other than 'px is invalid. Invalid numbers and those below 0 are ignored.

Definition at line 241 of file ImageGalleryBase.php.

References Parser\parseWidthParam().

◆ toHTML()

ImageGalleryBase::toHTML ( )
abstract

Display an html representation of the gallery.

Returns
string The html

Reimplemented in TraditionalImageGallery.

Member Data Documentation

◆ $contextTitle

Title null ImageGalleryBase::$contextTitle = null
protected

Contextual title, used when images are being screened against the bad image list.

Definition at line 90 of file ImageGalleryBase.php.

Referenced by getContextTitle().

◆ $mAttribs

array ImageGalleryBase::$mAttribs = []
protected

Definition at line 93 of file ImageGalleryBase.php.

◆ $mCaption

bool string ImageGalleryBase::$mCaption = false
protected

Gallery caption.

Default: false

Definition at line 65 of file ImageGalleryBase.php.

◆ $mCaptionLength

bool int ImageGalleryBase::$mCaptionLength = true
protected

Length to truncate filename to in caption when using "showfilename".

A value of 'true' will truncate the filename to one line using CSS and will be the behaviour after deprecation.

Definition at line 74 of file ImageGalleryBase.php.

Referenced by TraditionalImageGallery\getCaptionLength().

◆ $mHeights

int ImageGalleryBase::$mHeights
protected

◆ $mHideBadImages

bool ImageGalleryBase::$mHideBadImages
protected

Hide blacklisted images?

Definition at line 79 of file ImageGalleryBase.php.

◆ $mImages

array [] ImageGalleryBase::$mImages
protected

Gallery images -var array<int,array{0:Title,1:string,2:string,3:string,4:array,5:int}>

Definition at line 40 of file ImageGalleryBase.php.

Referenced by getImages().

◆ $mMode

string ImageGalleryBase::$mMode
protected

Gallery mode.

Default: traditional

Definition at line 60 of file ImageGalleryBase.php.

◆ $modeMapping

array ImageGalleryBase::$modeMapping
staticprivate

Definition at line 105 of file ImageGalleryBase.php.

◆ $mParser

Parser false ImageGalleryBase::$mParser

Registered parser object for output callbacks.

Definition at line 84 of file ImageGalleryBase.php.

◆ $mPerRow

int ImageGalleryBase::$mPerRow
protected

Definition at line 96 of file ImageGalleryBase.php.

◆ $mShowBytes

bool ImageGalleryBase::$mShowBytes
protected

Whether to show the filesize in bytes in categories.

Definition at line 45 of file ImageGalleryBase.php.

◆ $mShowDimensions

bool ImageGalleryBase::$mShowDimensions
protected

Whether to show the dimensions in categories.

Definition at line 50 of file ImageGalleryBase.php.

◆ $mShowFilename

bool ImageGalleryBase::$mShowFilename
protected

Whether to show the filename.

Default: true

Definition at line 55 of file ImageGalleryBase.php.

◆ $mWidths

int ImageGalleryBase::$mWidths
protected

◆ LOADING_DEFAULT

const ImageGalleryBase::LOADING_DEFAULT = 1

Definition at line 33 of file ImageGalleryBase.php.

◆ LOADING_LAZY

const ImageGalleryBase::LOADING_LAZY = 2

Definition at line 34 of file ImageGalleryBase.php.

Referenced by NewFilesPager\formatRow(), and TraditionalImageGallery\toHTML().


The documentation for this class was generated from the following file: