jenkins-bot has submitted this change and it was merged.
Change subject: Use config instead of globals for ImageGallery
......................................................................
Use config instead of globals for ImageGallery
Have to pass a context to the constructor to acutally use it for
settings.
Also adds a RequestContext::getMainAndWarn to get a default warning,
when using the main request, but it would be better to pass one.
Change-Id: I1628a1790c45d44aa4239701486b8b1b7c59a0e6
---
M includes/CategoryViewer.php
M includes/context/RequestContext.php
M includes/gallery/ImageGalleryBase.php
M includes/specialpage/ImageQueryPage.php
M includes/specials/SpecialNewimages.php
M includes/specials/SpecialUpload.php
6 files changed, 41 insertions(+), 21 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/CategoryViewer.php b/includes/CategoryViewer.php
index 22eb3d1..ec8efae 100644
--- a/includes/CategoryViewer.php
+++ b/includes/CategoryViewer.php
@@ -154,14 +154,13 @@
// 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();
diff --git a/includes/context/RequestContext.php
b/includes/context/RequestContext.php
index 00733d8..be786e4 100644
--- a/includes/context/RequestContext.php
+++ b/includes/context/RequestContext.php
@@ -422,6 +422,20 @@
}
/**
+ * 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.
*/
public static function resetMain() {
diff --git a/includes/gallery/ImageGalleryBase.php
b/includes/gallery/ImageGalleryBase.php
index 2d3ea5a..b61a352 100644
--- a/includes/gallery/ImageGalleryBase.php
+++ b/includes/gallery/ImageGalleryBase.php
@@ -86,19 +86,24 @@
* 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" );
}
@@ -124,18 +129,23 @@
* 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;
}
diff --git a/includes/specialpage/ImageQueryPage.php
b/includes/specialpage/ImageQueryPage.php
index 3ff281f..272d533 100644
--- a/includes/specialpage/ImageQueryPage.php
+++ b/includes/specialpage/ImageQueryPage.php
@@ -42,8 +42,7 @@
*/
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]
diff --git a/includes/specials/SpecialNewimages.php
b/includes/specials/SpecialNewimages.php
index aff5947..546c191 100644
--- a/includes/specials/SpecialNewimages.php
+++ b/includes/specials/SpecialNewimages.php
@@ -140,12 +140,11 @@
// 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 '';
diff --git a/includes/specials/SpecialUpload.php
b/includes/specials/SpecialUpload.php
index 4fd7cd4..5c5026c 100644
--- a/includes/specials/SpecialUpload.php
+++ b/includes/specials/SpecialUpload.php
@@ -725,8 +725,7 @@
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() );
--
To view, visit https://gerrit.wikimedia.org/r/155811
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1628a1790c45d44aa4239701486b8b1b7c59a0e6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Umherirrender <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits