http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95033
Revision: 95033
Author: jeroendedauw
Date: 2011-08-19 19:29:34 +0000 (Fri, 19 Aug 2011)
Log Message:
-----------
added warnings when trying to use invalid or disabled campaign and added
headerLabelPage setting
Modified Paths:
--------------
trunk/extensions/UploadWizard/UploadWizard.config.php
trunk/extensions/UploadWizard/UploadWizard.i18n.php
trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php
trunk/extensions/UploadWizard/includes/UploadWizardConfig.php
trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php
Modified: trunk/extensions/UploadWizard/UploadWizard.config.php
===================================================================
--- trunk/extensions/UploadWizard/UploadWizard.config.php 2011-08-19
19:22:58 UTC (rev 95032)
+++ trunk/extensions/UploadWizard/UploadWizard.config.php 2011-08-19
19:29:34 UTC (rev 95033)
@@ -27,6 +27,10 @@
// WikiText to automatically (and silently) add to all uploaded images.
'autoWikiText' => '',
+ // Page containing the (wiki)text to display above the UploadWizard UI.
+ // $1 is replaced by the language code.
+ 'headerLabelPage' => '',
+
// Should the own work option be shown, and if not, what option should
be set?
// Possible values: choice, own, notown
'ownWorkOption' => 'choice',
Modified: trunk/extensions/UploadWizard/UploadWizard.i18n.php
===================================================================
--- trunk/extensions/UploadWizard/UploadWizard.i18n.php 2011-08-19 19:22:58 UTC
(rev 95032)
+++ trunk/extensions/UploadWizard/UploadWizard.i18n.php 2011-08-19 19:29:34 UTC
(rev 95033)
@@ -287,6 +287,9 @@
'mwe-upwiz-errordialog-title' => 'There was an error in your
submission',
'mwe-upwiz-errordialog-ok' => 'OK',
+ 'mwe-upwiz-error-nosuchcampaign' => 'There is no campaign with name
"$1".',
+ 'mwe-upwiz-error-campaigndisabled' => 'Campaign "$1" has not been
enabled.',
+
// Special:UploadCampaigns
'mwe-upwiz-campaigns-name' => 'Campaign name',
'mwe-upwiz-campaigns-status' => 'Status',
@@ -308,21 +311,22 @@
'mwe-upwiz-campaign-name' => 'Campaign name',
'mwe-upwiz-campaign-enabled' => 'Campaign enabled',
'mwe-upwiz-campaign-conf-skipTutorial' => 'Skip the licensing tutorial',
- 'mwe-upwiz-campaign-conf-autoCategories' => 'Categories to add the
files to automatically and silently',
- 'mwe-upwiz-campaign-conf-defaultCategories' => 'Default categories to
list in the describe tab',
+ 'mwe-upwiz-campaign-conf-autoCategories' => 'Categories to add the
files to automatically and silently (comma separated)',
+ 'mwe-upwiz-campaign-conf-defaultCategories' => 'Default categories to
list in the describe tab (comma separated)',
'mwe-upwiz-campaign-conf-autoWikiText' => 'WikiText to automatically
add to all uploaded images',
'mwe-upwiz-campaign-conf-ownWorkOption' => 'How to handle own-work or
not own-work',
'mwe-upwiz-campaign-owner-choice' => 'Allow the user to choose between
own work and non-own work',
'mwe-upwiz-campaign-owner-own' => 'Only allow for own work uploads',
'mwe-upwiz-campaign-owner-notown' => 'Only allow for non-own work
uploads',
'mwe-upwiz-campaign-conf-licensesOwnWork' => 'The licences that should
be choosable for own-work',
- 'mwe-upwiz-campaign-conf-tutorialTemplate' => 'Name of the tutorial on
Wikimedia Commons. "$1" is replaced with a language code',
+ 'mwe-upwiz-campaign-conf-tutorialTemplate' => 'Name of the tutorial on
Wikimedia Commons. $1 is replaced with the language code',
'mwe-upwiz-campaign-conf-tutorialWidth' => 'The width to scale the
tutorial to',
'mwe-upwiz-campaign-conf-tutorialHelpdeskCoords' => 'Imagemap
coordinates of the tutorial "helpdesk" button',
'mwe-upwiz-campaign-conf-defaultOwnWorkLicence' => 'The default own
work license',
'mwe-upwiz-campaign-conf-idField' => 'Id field wikitext. Example:
<nowiki>{{Rijksmonument|$1}}</nowiki>. Blank to not display field',
'mwe-upwiz-campaign-conf-idFieldLabel' => 'Id field label text',
- 'mwe-upwiz-campaign-conf-idFieldLabelPage' => 'Page name with text for
the id field label ($1 for lang code)',
+ 'mwe-upwiz-campaign-conf-idFieldLabelPage' => 'Page name with text for
the id field label. $1 is replaced with the language code',
+ 'mwe-upwiz-campaign-conf-headerLabelPage' => 'Page containing text to
display above the UploadWizard interface. $1 is replaced with the language
code',
// Coolcats
'mw-coolcats-confirm-new-title' => 'Confirm new category',
Modified: trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php
===================================================================
--- trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php
2011-08-19 19:22:58 UTC (rev 95032)
+++ trunk/extensions/UploadWizard/includes/UploadWizardCampaign.php
2011-08-19 19:29:34 UTC (rev 95033)
@@ -153,6 +153,9 @@
$globalConfig = UploadWizardConfig::getConfig();
$config = array(
+ 'headerLabelPage' => array(
+ 'type' => 'text',
+ ),
'skipTutorial' => array(
'type' => 'check'
),
@@ -361,20 +364,36 @@
$config['licensesOwnWork']['defaults'] = array(
$config['defaultOwnWorkLicence'] );
unset( $config['defaultOwnWorkLicence'] );
- $labelPage = $config['idFieldLabelPage'];
- $config['idFieldLabelPage'] = false;
+ $config['idFieldLabelPage'] = $this->getPageContent(
$config['idFieldLabelPage'] );
+ $config['headerLabelPage'] = $this->getPageContent(
$config['headerLabelPage'] );
- if ( trim( $labelPage ) != '' ) {
+ return $config;
+ }
+
+ /**
+ * Gets content of the specified page, or false if there is no such
page.
+ * '$1' in $pageName is replaced by the code of the current language.
+ *
+ * @since 1.2
+ *
+ * @param string $pageName
+ *
+ * @return string|false
+ */
+ protected function getPageContent( $pageName ) {
+ $content = false;
+
+ if ( trim( $pageName ) != '' ) {
global $wgLang;
- $labelPage = Title::newFromText( str_replace( '$1',
$wgLang->getCode(), $labelPage ) );
+ $page = Title::newFromText( str_replace( '$1',
$wgLang->getCode(), $pageName ) );
- if ( !is_null( $labelPage ) && $labelPage->exists() ) {
- $article = new Article( $labelPage );
- $config['idFieldLabelPage'] =
$article->getContent();
+ if ( !is_null( $page ) && $page->exists() ) {
+ $article = new Article( $page );
+ $content = $article->getContent();
}
}
- return $config;
+ return $content;
}
/**
Modified: trunk/extensions/UploadWizard/includes/UploadWizardConfig.php
===================================================================
--- trunk/extensions/UploadWizard/includes/UploadWizardConfig.php
2011-08-19 19:22:58 UTC (rev 95032)
+++ trunk/extensions/UploadWizard/includes/UploadWizardConfig.php
2011-08-19 19:29:34 UTC (rev 95033)
@@ -100,10 +100,12 @@
* @return array
*/
protected static function getCampaignConfig( $campaignName ) {
- $campaign = UploadWizardCampaign::newFromName( $campaignName );
-
- if ( $campaign !== false && $campaign->getIsEnabled() ) {
- return $campaign->getConfigForGlobalMerge();
+ if ( !is_null( $campaignName ) ) {
+ $campaign = UploadWizardCampaign::newFromName(
$campaignName );
+
+ if ( $campaign !== false && $campaign->getIsEnabled() )
{
+ return $campaign->getConfigForGlobalMerge();
+ }
}
return array();
Modified:
trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php
===================================================================
--- trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php
2011-08-19 19:22:58 UTC (rev 95032)
+++ trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php
2011-08-19 19:29:34 UTC (rev 95033)
@@ -19,15 +19,11 @@
* @since 1.2
* @var string|null
*/
- protected $campaign;
+ protected $campaign = null;
// $request is the request (usually wgRequest)
// $par is everything in the URL after Special:UploadWizard. Not sure
what we can use it for
public function __construct( $request = null, $par = null ) {
- global $wgRequest;
- // here we would configure ourselves based on stuff in $request
and $wgRequest, but so far, we
- // don't have such things
-
parent::__construct( 'UploadWizard', 'upload' );
// create a simple form for non-JS fallback, which targets the
old Special:Upload page.
@@ -56,13 +52,13 @@
$this->setHeaders();
$this->outputHeader();
- $this->campaign = $wgRequest->getVal( 'campaign' );
-
// if query string includes 'skiptutorial=true' set config
variable to true
if ( $wgRequest->getCheck( 'skiptutorial' ) ) {
$skip = in_array( $wgRequest->getText( 'skiptutorial'
), array( '1', 'true' ) );
UploadWizardConfig::setUrlSetting( 'skipTutorial',
$skip );
}
+
+ $this->handleCampaign();
// fallback for non-JS
$wgOut->addHTML( '<noscript>' );
@@ -83,6 +79,48 @@
}
/**
+ * Handles the campaign parameter.
+ *
+ * @since 1.2
+ */
+ protected function handleCampaign() {
+ global $wgRequest;
+ $campaignName = $wgRequest->getVal( 'campaign' );
+
+ if ( $campaignName != '' ) {
+ $campaign = UploadWizardCampaign::newFromName(
$campaignName, false );
+
+ if ( $campaign === false ) {
+ $this->displayError( wfMsgExt(
'mwe-upwiz-error-nosuchcampaign', 'parsemag', $campaignName ) );
+ }
+ else {
+ if ( $campaign->getIsEnabled() ) {
+ $this->campaign = $campaignName;
+ }
+ else {
+ $this->displayError( wfMsgExt(
'mwe-upwiz-error-campaigndisabled', 'parsemag', $campaignName ) );
+ }
+ }
+ }
+ }
+
+ /**
+ * Display an error message.
+ *
+ * @since 1.2
+ *
+ * @param string $message
+ */
+ protected function displayError( $message ) {
+ global $wgOut;
+ $wgOut->addHTML( Html::element(
+ 'span',
+ array( 'class' => 'errorbox' ),
+ $message
+ ) . '<br /><br /><br />' );
+ }
+
+ /**
* Adds some global variables for our use, as well as initializes the
UploadWizard
*
* TODO once bug https://bugzilla.wikimedia.org/show_bug.cgi?id=26901
@@ -174,6 +212,11 @@
$globalConf = UploadWizardConfig::getConfig( $this->campaign );
+ if ( $globalConf['headerLabelPage'] !== false ) {
+ global $wgOut;
+ $wgOut->addWikiText( $globalConf['headerLabelPage'] );
+ }
+
if ( array_key_exists( 'fallbackToAltUploadForm', $globalConf )
&& array_key_exists( 'altUploadForm', $globalConf )
&& $globalConf['altUploadForm'] != ''
@@ -206,7 +249,7 @@
// TODO move this into UploadWizard.js or some other javascript
resource so the upload wizard
// can be dynamically included ( for example the add media
wizard )
- return
+ return
'<div id="upload-wizard" class="upload-section">'
// if loading takes > 2 seconds display spinner. Note
we are evading Resource Loader here, and linking directly. Because we want an
image to appear if RL's package is late.
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs