jenkins-bot has submitted this change and it was merged.

Change subject: [UploadWizard] Introducing the usage of an object reference
......................................................................


[UploadWizard] Introducing the usage of an object reference

The parameter objref will be used to have a bot updating the
lists of monuments with a thumbnail image of one of the uploaded
images.

This patch also adds the keyword 'useObjref' to the home button
and the keyword 'dropObjref' to the begin button configuration.

If it is set and there is an objref parameter passed with the request,
clicking the home button leads to the page passed as the reference (this
may be any page in any wiki defined for interwiki links; it is intended
to be the referer, though). If the begin button is configured to drop the
object reference, it will reload the Upload Wizard page, but will drop
the listUpdate parameter from the URL.

Independently from the button configuration, if the objref parameter is
set, the Upload Wizard adds the reference parameter to the description
page inside a comment tag. This will later be used by a bot that
supplements an image thumbnail to monument lists.

Bug: T105281
Change-Id: Ia974a148a6326dbca17a70c54a0cffcd2e4a39ac
---
M includes/UploadWizardCampaign.php
M includes/specials/SpecialUploadWizard.php
M resources/mw.UploadWizardDetails.js
M resources/ui/uw.ui.Thanks.js
A tests/phpunit/UploadWizardConfigTest.php
M tests/qunit/controller/uw.controller.Thanks.test.js
6 files changed, 121 insertions(+), 1 deletion(-)

Approvals:
  MarkTraceur: Looks good to me, approved
  Bartosz Dziewoński: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/includes/UploadWizardCampaign.php 
b/includes/UploadWizardCampaign.php
index b58ebd9..feff16b 100755
--- a/includes/UploadWizardCampaign.php
+++ b/includes/UploadWizardCampaign.php
@@ -337,9 +337,14 @@
                        }
 
                        $this->parsedConfig = $parsedConfig;
+
                        $cache->set( $memKey, array( 'timestamp' => time(), 
'config' => $parsedConfig ) );
                }
 
+               $uwDefaults = UploadWizardConfig::getSetting( 'defaults' );
+               if ( array_key_exists( 'objref', $uwDefaults ) ) {
+                       $this->applyObjectReferenceToButtons( 
$uwDefaults['objref'] );
+               }
                $this->modifyIfNecessary();
 
                return $this->parsedConfig;
@@ -431,4 +436,38 @@
 
                return $start === null || $start <= $today;
        }
+
+       /**
+        * Generate the URL out of the object reference
+        *
+        * @param string $objRef
+        * @return bool|string
+        */
+       private function getButtonHrefByObjectReference( $objRef ) {
+               list( $wiki, $title ) = explode( '|', $objRef );
+               if ( Interwiki::isValidInterwiki( $wiki ) ) {
+                       return str_replace( '$1', $title, Interwiki::fetch( 
$wiki )->getURL() );
+               }
+               return false;
+       }
+
+       /**
+        * Apply given object reference to buttons configured to use it as href
+        *
+        * @param string $objRef
+        */
+       private function applyObjectReferenceToButtons( $objRef ) {
+               $customizableButtons = array( 'homeButton', 'beginButton' );
+
+               foreach( $customizableButtons as $button ) {
+                       if ( array_key_exists( $button, 
$this->parsedConfig['display'] ) &&
+                                
$this->parsedConfig['display'][$button]['target'] === 'useObjref'
+                       ) {
+                               $validUrl = 
$this->getButtonHrefByObjectReference( $objRef );
+                               if ( $validUrl ) {
+                                       
$this->parsedConfig['display'][$button]['target'] = $validUrl;
+                               }
+                       }
+               }
+       }
 }
diff --git a/includes/specials/SpecialUploadWizard.php 
b/includes/specials/SpecialUploadWizard.php
index 3015f36..645f14e 100644
--- a/includes/specials/SpecialUploadWizard.php
+++ b/includes/specials/SpecialUploadWizard.php
@@ -77,6 +77,8 @@
                        $urlDefaults['categories'] = explode( '|', $categories 
);
                }
 
+               $urlDefaults['objref'] = $req->getText( 'objref' ) ?: '';
+
                UploadWizardConfig::setUrlSetting( 'defaults', $urlDefaults );
 
                $fields = $req->getArray( 'fields' );
diff --git a/resources/mw.UploadWizardDetails.js 
b/resources/mw.UploadWizardDetails.js
index 5a50321..98b9b65 100644
--- a/resources/mw.UploadWizardDetails.js
+++ b/resources/mw.UploadWizardDetails.js
@@ -1467,6 +1467,14 @@
                                        wikiText += 
mw.UploadWizard.config.autoAdd.wikitext;
                                }
 
+                               // add parameters for list callback bot
+                               // this cue will be used to supplement a wiki 
page with an image thumbnail
+                               if ( mw.UploadWizard.config.defaults.objref !== 
undefined ) {
+                                       wikiText += '\n<!-- 
WIKIPAGE_UPDATE_PARAMS ' +
+                                               
mw.UploadWizard.config.defaults.objref +
+                                               ' -->\n\n';
+                               }
+
                                // add categories
                                wikiText += this.div.find( '.categoryInput' 
).get(0).getWikiText() + '\n\n';
 
diff --git a/resources/ui/uw.ui.Thanks.js b/resources/ui/uw.ui.Thanks.js
index 428e066..279ffc0 100644
--- a/resources/ui/uw.ui.Thanks.js
+++ b/resources/ui/uw.ui.Thanks.js
@@ -64,13 +64,16 @@
                        flags: [ 'progressive', 'primary' ]
                } );
 
-               // TODO: make the step order configurable by campaign 
definitions instead of using this hack
+               // TODO: make the step order configurable by campaign 
definitions instead of using these hacks
                beginButtonTarget = this.getButtonConfig( 'beginButton', 
'target' );
                if ( !beginButtonTarget ) {
                        this.beginButton.on( 'click', function () {
                                thanks.emit( 'next-step' );
                        } );
                } else {
+                       if ( beginButtonTarget === 'dropObjref' ) {
+                               beginButtonTarget = this.dropParameterFromURL( 
location.href, 'updateList' );
+                       }
                        this.beginButton.setHref( beginButtonTarget );
                }
 
@@ -185,5 +188,21 @@
                return this.config.display[buttonName][configField];
        };
 
+       /**
+        * Drops a parameter from the given url
+        * @param url
+        * @param paramName parameter to be dropped
+        * @return {string}
+        * @private
+        */
+       TP.dropParameterFromURL = function ( url, paramName ) {
+               var newUrl = new mw.Uri( url );
+               if ( newUrl.query ) {
+                       delete newUrl.query[paramName];
+                       delete newUrl.query[paramName + '[]'];
+               }
+               return newUrl.toString();
+       };
+
        ui.Thanks = Thanks;
 }( mediaWiki, jQuery, mediaWiki.uploadWizard.ui, OO ) );
diff --git a/tests/phpunit/UploadWizardConfigTest.php 
b/tests/phpunit/UploadWizardConfigTest.php
new file mode 100644
index 0000000..c511606
--- /dev/null
+++ b/tests/phpunit/UploadWizardConfigTest.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * Test the Upload Wizard Configuration
+ * @group Upload
+ */
+
+class UploadWizardConfigTest extends MediaWikiTestCase {
+
+       public function 
testButtonTargetIsSetToUseObjRef_buttonHrefMatchesRefPage() {
+               global $wgUploadWizardConfig;
+               ParserTest::setupInterwikis();
+
+               $this->setMwGlobals( array(
+                       'wgUploadWizardConfig' => array_merge( 
$wgUploadWizardConfig, array(
+                               'defaults' => array( 'objref' => 'es|My 
Monuments|12345' ),
+                       ) ),
+               ) );
+
+               $campaign = new UploadWizardCampaign(
+                       Title::newFromText( 'uw-test-campaign', NS_CAMPAIGN ),
+                       array(
+                               'enabled' => true,
+                               'display' => array(
+                                       'homeButton' => array(
+                                               'label' => 'Back to that list 
page',
+                                               'target' => 'useObjref'
+                                       )
+                               )
+                       )
+               );
+               $config = $campaign->getParsedConfig();
+
+               $this->assertEquals(
+                       'http://es.wikipedia.org/wiki/My Monuments',
+                       $config['display']['homeButton']['target']
+               );
+       }
+
+}
diff --git a/tests/qunit/controller/uw.controller.Thanks.test.js 
b/tests/qunit/controller/uw.controller.Thanks.test.js
index 20966b4..3249708 100644
--- a/tests/qunit/controller/uw.controller.Thanks.test.js
+++ b/tests/qunit/controller/uw.controller.Thanks.test.js
@@ -79,4 +79,16 @@
                );
 
        } );
+
+       QUnit.test( 'Method drops the given parameter', 1, function ( assert ) {
+               var uiThanks = new uw.ui.Thanks(),
+                       locationHref = 
'https://commons.wikimedia.org/wiki/Special:UploadWizard?campaign=somecampaign&objref=testRef|MyPage|342&updateList=1&somevar=someval';
+
+               assert.equal(
+                       uiThanks.dropParameterFromURL( locationHref, 
'updateList' ),
+                       
'https://commons.wikimedia.org/wiki/Special:UploadWizard?campaign=somecampaign&objref=testRef%7CMyPage%7C342&somevar=someval',
+                       'The href of the begin button does not contain the 
updateList parameter.'
+               );
+
+       } );
 }( mediaWiki.uploadWizard ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/227984
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia974a148a6326dbca17a70c54a0cffcd2e4a39ac
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Kai Nissen (WMDE) <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Kai Nissen (WMDE) <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to