MediaWiki
REL1_23
|
00001 <?php 00030 abstract class ImageGalleryBase extends ContextSource { 00032 public $mImages; 00033 00035 public $mShowBytes; 00036 00038 public $mShowFilename; 00039 00041 public $mMode; 00042 00044 public $mCaption = false; 00045 00049 public $mHideBadImages; 00050 00054 public $mParser; 00055 00060 protected $contextTitle = false; 00061 00063 protected $mAttribs = array(); 00064 00066 static private $modeMapping = false; 00067 00075 static function factory( $mode = false ) { 00076 global $wgGalleryOptions, $wgContLang; 00077 self::loadModes(); 00078 if ( !$mode ) { 00079 $mode = $wgGalleryOptions['mode']; 00080 } 00081 00082 $mode = $wgContLang->lc( $mode ); 00083 00084 if ( isset( self::$modeMapping[$mode] ) ) { 00085 return new self::$modeMapping[$mode]( $mode ); 00086 } else { 00087 throw new MWException( "No gallery class registered for mode $mode" ); 00088 } 00089 } 00090 00091 private static function loadModes() { 00092 if ( self::$modeMapping === false ) { 00093 self::$modeMapping = array( 00094 'traditional' => 'TraditionalImageGallery', 00095 'nolines' => 'NolinesImageGallery', 00096 'packed' => 'PackedImageGallery', 00097 'packed-hover' => 'PackedHoverImageGallery', 00098 'packed-overlay' => 'PackedOverlayImageGallery', 00099 ); 00100 // Allow extensions to make a new gallery format. 00101 wfRunHooks( 'GalleryGetModes', self::$modeMapping ); 00102 } 00103 } 00104 00111 function __construct( $mode = 'traditional' ) { 00112 global $wgGalleryOptions; 00113 $this->mImages = array(); 00114 $this->mShowBytes = $wgGalleryOptions['showBytes']; 00115 $this->mShowFilename = true; 00116 $this->mParser = false; 00117 $this->mHideBadImages = false; 00118 $this->mPerRow = $wgGalleryOptions['imagesPerRow']; 00119 $this->mWidths = $wgGalleryOptions['imageWidth']; 00120 $this->mHeights = $wgGalleryOptions['imageHeight']; 00121 $this->mCaptionLength = $wgGalleryOptions['captionLength']; 00122 $this->mMode = $mode; 00123 } 00124 00135 function setParser( $parser ) { 00136 $this->mParser = $parser; 00137 } 00138 00142 function setHideBadImages( $flag = true ) { 00143 $this->mHideBadImages = $flag; 00144 } 00145 00151 function setCaption( $caption ) { 00152 $this->mCaption = htmlspecialchars( $caption ); 00153 } 00154 00160 public function setCaptionHtml( $caption ) { 00161 $this->mCaption = $caption; 00162 } 00163 00170 public function setPerRow( $num ) { 00171 if ( $num >= 0 ) { 00172 $this->mPerRow = (int)$num; 00173 } 00174 } 00175 00181 public function setWidths( $num ) { 00182 if ( $num > 0 ) { 00183 $this->mWidths = (int)$num; 00184 } 00185 } 00186 00192 public function setHeights( $num ) { 00193 if ( $num > 0 ) { 00194 $this->mHeights = (int)$num; 00195 } 00196 } 00197 00205 public function setAdditionalOptions( $options ) { 00206 } 00207 00214 function useSkin( $skin ) { 00215 wfDeprecated( __METHOD__, '1.18' ); 00216 /* no op */ 00217 } 00218 00229 function add( $title, $html = '', $alt = '', $link = '', $handlerOpts = array() ) { 00230 if ( $title instanceof File ) { 00231 // Old calling convention 00232 $title = $title->getTitle(); 00233 } 00234 $this->mImages[] = array( $title, $html, $alt, $link, $handlerOpts ); 00235 wfDebug( 'ImageGallery::add ' . $title->getText() . "\n" ); 00236 } 00237 00248 function insert( $title, $html = '', $alt = '', $link = '', $handlerOpts = array() ) { 00249 if ( $title instanceof File ) { 00250 // Old calling convention 00251 $title = $title->getTitle(); 00252 } 00253 array_unshift( $this->mImages, array( &$title, $html, $alt, $link, $handlerOpts ) ); 00254 } 00255 00260 function isEmpty() { 00261 return empty( $this->mImages ); 00262 } 00263 00270 function setShowBytes( $f ) { 00271 $this->mShowBytes = (bool)$f; 00272 } 00273 00280 function setShowFilename( $f ) { 00281 $this->mShowFilename = (bool)$f; 00282 } 00283 00293 function setAttributes( $attribs ) { 00294 $this->mAttribs = $attribs; 00295 } 00296 00302 abstract public function toHTML(); 00303 00307 public function count() { 00308 return count( $this->mImages ); 00309 } 00310 00316 public function setContextTitle( $title ) { 00317 $this->contextTitle = $title; 00318 } 00319 00325 public function getContextTitle() { 00326 return is_object( $this->contextTitle ) && $this->contextTitle instanceof Title 00327 ? $this->contextTitle 00328 : false; 00329 } 00330 00335 protected function getRenderLang() { 00336 return $this->mParser 00337 ? $this->mParser->getTargetLanguage() 00338 : $this->getLanguage(); 00339 } 00340 }