diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2014-12-27 15:41:37 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2014-12-31 11:43:28 +0100 |
commit | c1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch) | |
tree | 2b38796e738dd74cb42ecd9bfd151803108386bc /includes/gallery/ImageGalleryBase.php | |
parent | b88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff) |
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/gallery/ImageGalleryBase.php')
-rw-r--r-- | includes/gallery/ImageGalleryBase.php | 165 |
1 files changed, 100 insertions, 65 deletions
diff --git a/includes/gallery/ImageGalleryBase.php b/includes/gallery/ImageGalleryBase.php index f8b8c505..b0a593de 100644 --- a/includes/gallery/ImageGalleryBase.php +++ b/includes/gallery/ImageGalleryBase.php @@ -28,53 +28,89 @@ * @ingroup Media */ abstract class ImageGalleryBase extends ContextSource { - var $mImages, $mShowBytes, $mShowFilename, $mMode; - var $mCaption = false; + /** + * @var array Gallery images + * @deprecated since 1.23 (was declared "var") and will be removed in 1.24 + */ + public $mImages; + + /** + * @var bool Whether to show the filesize in bytes in categories + * @deprecated since 1.23 (was declared "var") and will be removed in 1.24 + */ + public $mShowBytes; + + /** + * @var bool Whether to show the filename. Default: true + * @deprecated since 1.23 (was declared "var") and will be removed in 1.24 + */ + public $mShowFilename; + + /** + * @var string Gallery mode. Default: traditional + * @deprecated since 1.23 (was declared "var") and will be removed in 1.24 + */ + public $mMode; + + /** + * @var bool|string Gallery caption. Default: false + * @deprecated since 1.23 (was declared "var") and will be removed in 1.24 + */ + public $mCaption = false; /** - * Hide blacklisted images? + * @var bool Hide blacklisted images? + * @deprecated since 1.23 (was declared "var") and will be removed in 1.24 */ - var $mHideBadImages; + public $mHideBadImages; /** - * Registered parser object for output callbacks - * @var Parser + * @var Parser Registered parser object for output callbacks */ - var $mParser; + public $mParser; /** - * Contextual title, used when images are being screened - * against the bad image list + * @var Title Contextual title, used when images are being screened against + * the bad image list */ protected $contextTitle = false; + /** @var array */ protected $mAttribs = array(); + /** @var bool */ static private $modeMapping = false; /** * Get a new image gallery. This is the method other callers * should use to get a gallery. * - * @param String|bool $mode Mode to use. False to use the default. + * @param string|bool $mode Mode to use. False to use the default + * @param IContextSource|null $context + * @return ImageGalleryBase + * @throws MWException */ - static function factory( $mode = false ) { - global $wgGalleryOptions, $wgContLang; + static function factory( $mode = false, IContextSource $context = null ) { + global $wgContLang; self::loadModes(); + if ( !$context ) { + $context = RequestContext::getMainAndWarn( __METHOD__ ); + } if ( !$mode ) { - $mode = $wgGalleryOptions['mode']; + $galleryOpions = $context->getConfig()->get( 'GalleryOptions' ); + $mode = $galleryOpions['mode']; } $mode = $wgContLang->lc( $mode ); if ( isset( self::$modeMapping[$mode] ) ) { - return new self::$modeMapping[$mode]( $mode ); + return new self::$modeMapping[$mode]( $mode, $context ); } else { throw new MWException( "No gallery class registered for mode $mode" ); } } - static private function loadModes() { + private static function loadModes() { if ( self::$modeMapping === false ) { self::$modeMapping = array( 'traditional' => 'TraditionalImageGallery', @@ -93,18 +129,24 @@ abstract class ImageGalleryBase extends ContextSource { * * You should not call this directly, but instead use * ImageGalleryBase::factory(). + * @param string $mode + * @param IContextSource|null $context */ - function __construct( $mode = 'traditional' ) { - global $wgGalleryOptions; + function __construct( $mode = 'traditional', IContextSource $context = null ) { + if ( $context ) { + $this->setContext( $context ); + } + + $galleryOptions = $this->getConfig()->get( 'GalleryOptions' ); $this->mImages = array(); - $this->mShowBytes = $wgGalleryOptions['showBytes']; + $this->mShowBytes = $galleryOptions['showBytes']; $this->mShowFilename = true; $this->mParser = false; $this->mHideBadImages = false; - $this->mPerRow = $wgGalleryOptions['imagesPerRow']; - $this->mWidths = $wgGalleryOptions['imageWidth']; - $this->mHeights = $wgGalleryOptions['imageHeight']; - $this->mCaptionLength = $wgGalleryOptions['captionLength']; + $this->mPerRow = $galleryOptions['imagesPerRow']; + $this->mWidths = $galleryOptions['imageWidth']; + $this->mHeights = $galleryOptions['imageHeight']; + $this->mCaptionLength = $galleryOptions['captionLength']; $this->mMode = $mode; } @@ -116,7 +158,7 @@ abstract class ImageGalleryBase extends ContextSource { * @note This also triggers using the page's target * language instead of the user language. * - * @param $parser Parser + * @param Parser $parser */ function setParser( $parser ) { $this->mParser = $parser; @@ -124,6 +166,7 @@ abstract class ImageGalleryBase extends ContextSource { /** * Set bad image flag + * @param bool $flag */ function setHideBadImages( $flag = true ) { $this->mHideBadImages = $flag; @@ -150,8 +193,8 @@ abstract class ImageGalleryBase extends ContextSource { /** * Set how many images will be displayed per row. * - * @param $num Integer >= 0; If perrow=0 the gallery layout will adapt to screensize - * invalid numbers will be rejected + * @param int $num Integer >= 0; If perrow=0 the gallery layout will adapt + * to screensize invalid numbers will be rejected */ public function setPerRow( $num ) { if ( $num >= 0 ) { @@ -162,7 +205,7 @@ abstract class ImageGalleryBase extends ContextSource { /** * Set how wide each image will be, in pixels. * - * @param $num Integer > 0; invalid numbers will be ignored + * @param int $num Integer > 0; invalid numbers will be ignored */ public function setWidths( $num ) { if ( $num > 0 ) { @@ -173,7 +216,7 @@ abstract class ImageGalleryBase extends ContextSource { /** * Set how high each image will be, in pixels. * - * @param $num Integer > 0; invalid numbers will be ignored + * @param int $num Integer > 0; invalid numbers will be ignored */ public function setHeights( $num ) { if ( $num > 0 ) { @@ -186,29 +229,20 @@ abstract class ImageGalleryBase extends ContextSource { * to allow extensions to add additional parameters to * <gallery> parser tag. * - * @param Array $options Attributes of gallery tag. - */ - public function setAdditionalOptions( $options ) { } - - /** - * Instruct the class to use a specific skin for rendering - * - * @param $skin Skin object - * @deprecated since 1.18 Not used anymore + * @param array $options Attributes of gallery tag */ - function useSkin( $skin ) { - wfDeprecated( __METHOD__, '1.18' ); - /* no op */ + public function setAdditionalOptions( $options ) { } /** * Add an image to the gallery. * - * @param $title Title object of the image that is added to the gallery - * @param $html String: Additional HTML text to be shown. The name and size of the image are always shown. - * @param $alt String: Alt text for the image - * @param $link String: Override image link (optional) - * @param $handlerOpts Array: Array of options for image handler (aka page number) + * @param Title $title Title object of the image that is added to the gallery + * @param string $html Additional HTML text to be shown. The name and size + * of the image are always shown. + * @param string $alt Alt text for the image + * @param string $link Override image link (optional) + * @param array $handlerOpts Array of options for image handler (aka page number) */ function add( $title, $html = '', $alt = '', $link = '', $handlerOpts = array() ) { if ( $title instanceof File ) { @@ -222,11 +256,12 @@ abstract class ImageGalleryBase extends ContextSource { /** * Add an image at the beginning of the gallery. * - * @param $title Title object of the image that is added to the gallery - * @param $html String: Additional HTML text to be shown. The name and size of the image are always shown. - * @param $alt String: Alt text for the image - * @param $link String: Override image link (optional) - * @param $handlerOpts Array: Array of options for image handler (aka page number) + * @param Title $title Title object of the image that is added to the gallery + * @param string $html Additional HTML text to be shown. The name and size + * of the image are always shown. + * @param string $alt Alt text for the image + * @param string $link Override image link (optional) + * @param array $handlerOpts Array of options for image handler (aka page number) */ function insert( $title, $html = '', $alt = '', $link = '', $handlerOpts = array() ) { if ( $title instanceof File ) { @@ -237,6 +272,14 @@ abstract class ImageGalleryBase extends ContextSource { } /** + * Returns the list of images this gallery contains + * @return array + */ + public function getImages() { + return $this->mImages; + } + + /** * isEmpty() returns true if the gallery contains no images * @return bool */ @@ -248,7 +291,7 @@ abstract class ImageGalleryBase extends ContextSource { * Enable/Disable showing of the file size of an image in the gallery. * Enabled by default. * - * @param $f Boolean: set to false to disable. + * @param bool $f Set to false to disable */ function setShowBytes( $f ) { $this->mShowBytes = (bool)$f; @@ -258,7 +301,7 @@ abstract class ImageGalleryBase extends ContextSource { * Enable/Disable showing of the filename of an image in the gallery. * Enabled by default. * - * @param $f Boolean: set to false to disable. + * @param bool $f Set to false to disable */ function setShowFilename( $f ) { $this->mShowFilename = (bool)$f; @@ -271,7 +314,7 @@ abstract class ImageGalleryBase extends ContextSource { * Note -- if taking from user input, you should probably run through * Sanitizer::validateAttributes() first. * - * @param array $attribs of HTML attribute pairs + * @param array $attribs Array of HTML attribute pairs */ function setAttributes( $attribs ) { $this->mAttribs = $attribs; @@ -280,12 +323,12 @@ abstract class ImageGalleryBase extends ContextSource { /** * Display an html representation of the gallery * - * @return String The html + * @return string The html */ abstract public function toHTML(); /** - * @return Integer: number of images in the gallery + * @return int Number of images in the gallery */ public function count() { return count( $this->mImages ); @@ -294,7 +337,7 @@ abstract class ImageGalleryBase extends ContextSource { /** * Set the contextual title * - * @param $title Title: contextual title + * @param Title $title Contextual title */ public function setContextTitle( $title ) { $this->contextTitle = $title; @@ -303,7 +346,7 @@ abstract class ImageGalleryBase extends ContextSource { /** * Get the contextual title, if applicable * - * @return mixed Title or false + * @return Title|bool Title or false */ public function getContextTitle() { return is_object( $this->contextTitle ) && $this->contextTitle instanceof Title @@ -313,19 +356,11 @@ abstract class ImageGalleryBase extends ContextSource { /** * Determines the correct language to be used for this image gallery - * @return Language object + * @return Language */ protected function getRenderLang() { return $this->mParser ? $this->mParser->getTargetLanguage() : $this->getLanguage(); } - - /* Old constants no longer used. - const THUMB_PADDING = 30; - const GB_PADDING = 5; - const GB_BORDERS = 8; - */ - } - |