MediaWiki  1.23.8
ImageGalleryBase.php
Go to the documentation of this file.
1 <?php
30 abstract class ImageGalleryBase extends ContextSource {
32  public $mImages;
33 
35  public $mShowBytes;
36 
38  public $mShowFilename;
39 
41  public $mMode;
42 
44  public $mCaption = false;
45 
49  public $mHideBadImages;
50 
54  public $mParser;
55 
60  protected $contextTitle = false;
61 
63  protected $mAttribs = array();
64 
66  static private $modeMapping = false;
67 
75  static function factory( $mode = false ) {
76  global $wgGalleryOptions, $wgContLang;
78  if ( !$mode ) {
79  $mode = $wgGalleryOptions['mode'];
80  }
81 
82  $mode = $wgContLang->lc( $mode );
83 
84  if ( isset( self::$modeMapping[$mode] ) ) {
85  return new self::$modeMapping[$mode]( $mode );
86  } else {
87  throw new MWException( "No gallery class registered for mode $mode" );
88  }
89  }
90 
91  private static function loadModes() {
92  if ( self::$modeMapping === false ) {
93  self::$modeMapping = array(
94  'traditional' => 'TraditionalImageGallery',
95  'nolines' => 'NolinesImageGallery',
96  'packed' => 'PackedImageGallery',
97  'packed-hover' => 'PackedHoverImageGallery',
98  'packed-overlay' => 'PackedOverlayImageGallery',
99  );
100  // Allow extensions to make a new gallery format.
101  wfRunHooks( 'GalleryGetModes', self::$modeMapping );
102  }
103  }
104 
111  function __construct( $mode = 'traditional' ) {
112  global $wgGalleryOptions;
113  $this->mImages = array();
114  $this->mShowBytes = $wgGalleryOptions['showBytes'];
115  $this->mShowFilename = true;
116  $this->mParser = false;
117  $this->mHideBadImages = false;
118  $this->mPerRow = $wgGalleryOptions['imagesPerRow'];
119  $this->mWidths = $wgGalleryOptions['imageWidth'];
120  $this->mHeights = $wgGalleryOptions['imageHeight'];
121  $this->mCaptionLength = $wgGalleryOptions['captionLength'];
122  $this->mMode = $mode;
123  }
124 
135  function setParser( $parser ) {
136  $this->mParser = $parser;
137  }
138 
142  function setHideBadImages( $flag = true ) {
143  $this->mHideBadImages = $flag;
144  }
145 
151  function setCaption( $caption ) {
152  $this->mCaption = htmlspecialchars( $caption );
153  }
154 
160  public function setCaptionHtml( $caption ) {
161  $this->mCaption = $caption;
162  }
163 
170  public function setPerRow( $num ) {
171  if ( $num >= 0 ) {
172  $this->mPerRow = (int)$num;
173  }
174  }
175 
181  public function setWidths( $num ) {
182  if ( $num > 0 ) {
183  $this->mWidths = (int)$num;
184  }
185  }
186 
192  public function setHeights( $num ) {
193  if ( $num > 0 ) {
194  $this->mHeights = (int)$num;
195  }
196  }
197 
205  public function setAdditionalOptions( $options ) {
206  }
207 
214  function useSkin( $skin ) {
215  wfDeprecated( __METHOD__, '1.18' );
216  /* no op */
217  }
218 
229  function add( $title, $html = '', $alt = '', $link = '', $handlerOpts = array() ) {
230  if ( $title instanceof File ) {
231  // Old calling convention
232  $title = $title->getTitle();
233  }
234  $this->mImages[] = array( $title, $html, $alt, $link, $handlerOpts );
235  wfDebug( 'ImageGallery::add ' . $title->getText() . "\n" );
236  }
237 
248  function insert( $title, $html = '', $alt = '', $link = '', $handlerOpts = array() ) {
249  if ( $title instanceof File ) {
250  // Old calling convention
251  $title = $title->getTitle();
252  }
253  array_unshift( $this->mImages, array( &$title, $html, $alt, $link, $handlerOpts ) );
254  }
255 
260  function isEmpty() {
261  return empty( $this->mImages );
262  }
263 
270  function setShowBytes( $f ) {
271  $this->mShowBytes = (bool)$f;
272  }
273 
280  function setShowFilename( $f ) {
281  $this->mShowFilename = (bool)$f;
282  }
283 
293  function setAttributes( $attribs ) {
294  $this->mAttribs = $attribs;
295  }
296 
302  abstract public function toHTML();
303 
307  public function count() {
308  return count( $this->mImages );
309  }
310 
316  public function setContextTitle( $title ) {
317  $this->contextTitle = $title;
318  }
319 
325  public function getContextTitle() {
326  return is_object( $this->contextTitle ) && $this->contextTitle instanceof Title
327  ? $this->contextTitle
328  : false;
329  }
330 
335  protected function getRenderLang() {
336  return $this->mParser
337  ? $this->mParser->getTargetLanguage()
338  : $this->getLanguage();
339  }
340 }
ImageGalleryBase\setShowBytes
setShowBytes( $f)
Enable/Disable showing of the file size of an image in the gallery.
Definition: ImageGalleryBase.php:261
ImageGalleryBase\setParser
setParser( $parser)
Register a parser object.
Definition: ImageGalleryBase.php:126
ImageGalleryBase\$modeMapping
static $modeMapping
Definition: ImageGalleryBase.php:57
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1530
ImageGalleryBase\setHeights
setHeights( $num)
Set how high each image will be, in pixels.
Definition: ImageGalleryBase.php:183
ImageGalleryBase\setContextTitle
setContextTitle( $title)
Set the contextual title.
Definition: ImageGalleryBase.php:307
ImageGalleryBase\$mMode
string $mMode
Gallery mode.
Definition: ImageGalleryBase.php:37
ImageGalleryBase
Image gallery.
Definition: ImageGalleryBase.php:30
$f
$f
Definition: UtfNormalTest2.php:38
ImageGalleryBase\setWidths
setWidths( $num)
Set how wide each image will be, in pixels.
Definition: ImageGalleryBase.php:172
ImageGalleryBase\setCaption
setCaption( $caption)
Set the caption (as plain text)
Definition: ImageGalleryBase.php:142
ImageGalleryBase\getContextTitle
getContextTitle()
Get the contextual title, if applicable.
Definition: ImageGalleryBase.php:316
ImageGalleryBase\setShowFilename
setShowFilename( $f)
Enable/Disable showing of the filename of an image in the gallery.
Definition: ImageGalleryBase.php:271
ImageGalleryBase\$mCaption
bool string $mCaption
Gallery caption.
Definition: ImageGalleryBase.php:39
ImageGalleryBase\factory
static factory( $mode=false)
Get a new image gallery.
Definition: ImageGalleryBase.php:66
ImageGalleryBase\setAdditionalOptions
setAdditionalOptions( $options)
Allow setting additional options.
Definition: ImageGalleryBase.php:196
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
$link
set to $title object and return false for a match for latest after cache objects are set use the ContentHandler facility to handle CSS and JavaScript for highlighting & $link
Definition: hooks.txt:2149
ContextSource\getLanguage
getLanguage()
Get the Language object.
Definition: ContextSource.php:154
ImageGalleryBase\setAttributes
setAttributes( $attribs)
Set arbitrary attributes to go on the HTML gallery output element.
Definition: ImageGalleryBase.php:284
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:50
ImageGalleryBase\setHideBadImages
setHideBadImages( $flag=true)
Set bad image flag.
Definition: ImageGalleryBase.php:133
ImageGalleryBase\setPerRow
setPerRow( $num)
Set how many images will be displayed per row.
Definition: ImageGalleryBase.php:161
MWException
MediaWiki exception.
Definition: MWException.php:26
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1127
ImageGalleryBase\$mShowFilename
bool $mShowFilename
Whether to show the filename.
Definition: ImageGalleryBase.php:35
$parser
do that in ParserLimitReportFormat instead $parser
Definition: hooks.txt:1956
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:30
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4010
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ImageGalleryBase\$contextTitle
Title $contextTitle
Contextual title, used when images are being screened against the bad image list.
Definition: ImageGalleryBase.php:52
$options
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Definition: hooks.txt:1530
ImageGalleryBase\insert
insert( $title, $html='', $alt='', $link='', $handlerOpts=array())
Add an image at the beginning of the gallery.
Definition: ImageGalleryBase.php:239
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
ImageGalleryBase\$mImages
array $mImages
Gallery images *.
Definition: ImageGalleryBase.php:31
ImageGalleryBase\loadModes
static loadModes()
Definition: ImageGalleryBase.php:82
ImageGalleryBase\$mShowBytes
bool $mShowBytes
Whether to show the filesize in bytes in categories *.
Definition: ImageGalleryBase.php:33
ImageGalleryBase\__construct
__construct( $mode='traditional')
Create a new image gallery object.
Definition: ImageGalleryBase.php:102
ImageGalleryBase\setCaptionHtml
setCaptionHtml( $caption)
Set the caption (as HTML)
Definition: ImageGalleryBase.php:151
$skin
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
Definition: hooks.txt:1530
ImageGalleryBase\getRenderLang
getRenderLang()
Determines the correct language to be used for this image gallery.
Definition: ImageGalleryBase.php:326
ImageGalleryBase\add
add( $title, $html='', $alt='', $link='', $handlerOpts=array())
Add an image to the gallery.
Definition: ImageGalleryBase.php:220
Title
Represents a title within MediaWiki.
Definition: Title.php:35
ImageGalleryBase\isEmpty
isEmpty()
isEmpty() returns true if the gallery contains no images
Definition: ImageGalleryBase.php:251
ImageGalleryBase\useSkin
useSkin( $skin)
Instruct the class to use a specific skin for rendering.
Definition: ImageGalleryBase.php:205
ImageGalleryBase\count
count()
Definition: ImageGalleryBase.php:298
$attribs
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing & $attribs
Definition: hooks.txt:1530
ImageGalleryBase\toHTML
toHTML()
Display an html representation of the gallery.
ImageGalleryBase\$mHideBadImages
bool $mHideBadImages
Hide blacklisted images?
Definition: ImageGalleryBase.php:43
ImageGalleryBase\$mParser
Parser $mParser
Registered parser object for output callbacks.
Definition: ImageGalleryBase.php:47
ImageGalleryBase\$mAttribs
array $mAttribs
Definition: ImageGalleryBase.php:54