MediaWiki
REL1_22
|
00001 <?php 00030 abstract class ImageGalleryBase extends ContextSource { 00031 var $mImages, $mShowBytes, $mShowFilename, $mMode; 00032 var $mCaption = false; 00033 00037 var $mHideBadImages; 00038 00043 var $mParser; 00044 00049 protected $contextTitle = false; 00050 00051 protected $mAttribs = array(); 00052 00053 static private $modeMapping = false; 00054 00061 static function factory( $mode = false ) { 00062 global $wgGalleryOptions, $wgContLang; 00063 self::loadModes(); 00064 if ( !$mode ) { 00065 $mode = $wgGalleryOptions['mode']; 00066 } 00067 00068 $mode = $wgContLang->lc( $mode ); 00069 00070 if ( isset( self::$modeMapping[$mode] ) ) { 00071 return new self::$modeMapping[$mode]( $mode ); 00072 } else { 00073 throw new MWException( "No gallery class registered for mode $mode" ); 00074 } 00075 } 00076 00077 static private function loadModes() { 00078 if ( self::$modeMapping === false ) { 00079 self::$modeMapping = array( 00080 'traditional' => 'TraditionalImageGallery', 00081 'nolines' => 'NolinesImageGallery', 00082 'packed' => 'PackedImageGallery', 00083 'packed-hover' => 'PackedHoverImageGallery', 00084 'packed-overlay' => 'PackedOverlayImageGallery', 00085 ); 00086 // Allow extensions to make a new gallery format. 00087 wfRunHooks( 'GalleryGetModes', self::$modeMapping ); 00088 } 00089 } 00090 00097 function __construct( $mode = 'traditional' ) { 00098 global $wgGalleryOptions; 00099 $this->mImages = array(); 00100 $this->mShowBytes = $wgGalleryOptions['showBytes']; 00101 $this->mShowFilename = true; 00102 $this->mParser = false; 00103 $this->mHideBadImages = false; 00104 $this->mPerRow = $wgGalleryOptions['imagesPerRow']; 00105 $this->mWidths = $wgGalleryOptions['imageWidth']; 00106 $this->mHeights = $wgGalleryOptions['imageHeight']; 00107 $this->mCaptionLength = $wgGalleryOptions['captionLength']; 00108 $this->mMode = $mode; 00109 } 00110 00121 function setParser( $parser ) { 00122 $this->mParser = $parser; 00123 } 00124 00128 function setHideBadImages( $flag = true ) { 00129 $this->mHideBadImages = $flag; 00130 } 00131 00137 function setCaption( $caption ) { 00138 $this->mCaption = htmlspecialchars( $caption ); 00139 } 00140 00146 public function setCaptionHtml( $caption ) { 00147 $this->mCaption = $caption; 00148 } 00149 00156 public function setPerRow( $num ) { 00157 if ( $num >= 0 ) { 00158 $this->mPerRow = (int)$num; 00159 } 00160 } 00161 00167 public function setWidths( $num ) { 00168 if ( $num > 0 ) { 00169 $this->mWidths = (int)$num; 00170 } 00171 } 00172 00178 public function setHeights( $num ) { 00179 if ( $num > 0 ) { 00180 $this->mHeights = (int)$num; 00181 } 00182 } 00183 00191 public function setAdditionalOptions( $options ) { } 00192 00199 function useSkin( $skin ) { 00200 wfDeprecated( __METHOD__, '1.18' ); 00201 /* no op */ 00202 } 00203 00213 function add( $title, $html = '', $alt = '', $link = '', $handlerOpts = array() ) { 00214 if ( $title instanceof File ) { 00215 // Old calling convention 00216 $title = $title->getTitle(); 00217 } 00218 $this->mImages[] = array( $title, $html, $alt, $link, $handlerOpts ); 00219 wfDebug( 'ImageGallery::add ' . $title->getText() . "\n" ); 00220 } 00221 00231 function insert( $title, $html = '', $alt = '', $link = '', $handlerOpts = array() ) { 00232 if ( $title instanceof File ) { 00233 // Old calling convention 00234 $title = $title->getTitle(); 00235 } 00236 array_unshift( $this->mImages, array( &$title, $html, $alt, $link, $handlerOpts ) ); 00237 } 00238 00243 function isEmpty() { 00244 return empty( $this->mImages ); 00245 } 00246 00253 function setShowBytes( $f ) { 00254 $this->mShowBytes = (bool)$f; 00255 } 00256 00263 function setShowFilename( $f ) { 00264 $this->mShowFilename = (bool)$f; 00265 } 00266 00276 function setAttributes( $attribs ) { 00277 $this->mAttribs = $attribs; 00278 } 00279 00285 abstract public function toHTML(); 00286 00290 public function count() { 00291 return count( $this->mImages ); 00292 } 00293 00299 public function setContextTitle( $title ) { 00300 $this->contextTitle = $title; 00301 } 00302 00308 public function getContextTitle() { 00309 return is_object( $this->contextTitle ) && $this->contextTitle instanceof Title 00310 ? $this->contextTitle 00311 : false; 00312 } 00313 00318 protected function getRenderLang() { 00319 return $this->mParser 00320 ? $this->mParser->getTargetLanguage() 00321 : $this->getLanguage(); 00322 } 00323 00324 /* Old constants no longer used. 00325 const THUMB_PADDING = 30; 00326 const GB_PADDING = 5; 00327 const GB_BORDERS = 8; 00328 */ 00329 00330 } 00331