// Note that null for mode is taken to mean use default.
$mode = $this->getRequest()->getVal( 'gallerymode', null );
try {
- $this->gallery = ImageGalleryBase::factory( $mode );
+ $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
} catch ( MWException $e ) {
// User specified something invalid, fallback to default.
- $this->gallery = ImageGalleryBase::factory();
+ $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
}
$this->gallery->setHideBadImages();
- $this->gallery->setContext( $this->getContext() );
} else {
$this->imgsNoGallery = array();
$this->imgsNoGallery_start_char = array();
return self::$instance;
}
+ /**
+ * Get the RequestContext object associated with the main request
+ * and gives a warning to the log, to find places, where a context maybe is missing.
+ *
+ * @return RequestContext
+ * @since 1.24
+ */
+ public static function getMainAndWarn( $func = __METHOD__ ) {
+ wfDebug( $func . ' called without context. ' .
+ "Using RequestContext::getMain() for sanity\n" );
+
+ return self::getMain();
+ }
+
/**
* Resets singleton returned by getMain(). Should be called only from unit tests.
*/
* should use to get a gallery.
*
* @param string|bool $mode Mode to use. False to use the default
+ * @param IContextSource|null $context
* @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" );
}
* 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;
}
*/
protected function outputResults( $out, $skin, $dbr, $res, $num, $offset ) {
if ( $num > 0 ) {
- $gallery = ImageGalleryBase::factory();
- $gallery->setContext( $this->getContext() );
+ $gallery = ImageGalleryBase::factory( false, $this->getContext() );
# $res might contain the whole 1,000 rows, so we read up to
# $num [should update this to use a Pager]
// Note that null for mode is taken to mean use default.
$mode = $this->getRequest()->getVal( 'gallerymode', null );
try {
- $this->gallery = ImageGalleryBase::factory( $mode );
+ $this->gallery = ImageGalleryBase::factory( $mode, $this->getContext() );
} catch ( MWException $e ) {
// User specified something invalid, fallback to default.
- $this->gallery = ImageGalleryBase::factory();
+ $this->gallery = ImageGalleryBase::factory( false, $this->getContext() );
}
- $this->gallery->setContext( $this->getContext() );
}
return '';
return '';
}
- $gallery = ImageGalleryBase::factory();
- $gallery->setContext( $this->getContext() );
+ $gallery = ImageGalleryBase::factory( false, $this->getContext() );
$gallery->setShowBytes( false );
foreach ( $dupes as $file ) {
$gallery->add( $file->getTitle() );