https://www.mediawiki.org/wiki/Special:Code/MediaWiki/105436
Revision: 105436 Author: jeroendedauw Date: 2011-12-07 16:39:25 +0000 (Wed, 07 Dec 2011) Log Message: ----------- bug 24702: added new config option that allows choosing the default license type rather then limiting selection to one and also changed the 3 user preferences into one as per Neils suggestion Modified Paths: -------------- trunk/extensions/UploadWizard/UploadWizard.config.php trunk/extensions/UploadWizard/UploadWizard.i18n.php trunk/extensions/UploadWizard/UploadWizardHooks.php trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php trunk/extensions/UploadWizard/resources/mw.UploadWizardDeed.js Modified: trunk/extensions/UploadWizard/UploadWizard.config.php =================================================================== --- trunk/extensions/UploadWizard/UploadWizard.config.php 2011-12-07 16:26:25 UTC (rev 105435) +++ trunk/extensions/UploadWizard/UploadWizard.config.php 2011-12-07 16:39:25 UTC (rev 105436) @@ -43,6 +43,10 @@ // When not provided, the message mwe-upwiz-thanks-intro will be used. 'thanksLabelPage' => '', + // Default license type. + // Possible values: choice, ownwork, thirdparty + 'defaultLicenseType' => 'choice', + // 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-12-07 16:26:25 UTC (rev 105435) +++ trunk/extensions/UploadWizard/UploadWizard.i18n.php 2011-12-07 16:39:25 UTC (rev 105436) @@ -368,12 +368,10 @@ // Preferences 'prefs-uploads' => 'Uploads', - 'mwe-upwiz-prefs-def-license' => 'Default own work license', + 'mwe-upwiz-prefs-def-license' => 'Default license', 'mwe-upwiz-prefs-def-license-def' => 'Use whatever the default is', - 'mwe-upwiz-prefs-def-licensetype' => 'Default license type', - 'mwe-upwiz-prefs-def-3rdparty' => 'Default third party license', - 'mwe-upwiz-prefs-def-license-ownwork' => 'Own work', - 'mwe-upwiz-prefs-def-license-3rdparty' => 'Third party', + 'mwe-upwiz-prefs-license-own' => 'Own work - $1', + 'mwe-upwiz-prefs-license-thirdparty' => "Someone else's work - $1", ); /** Message documentation (Message documentation) Modified: trunk/extensions/UploadWizard/UploadWizardHooks.php =================================================================== --- trunk/extensions/UploadWizard/UploadWizardHooks.php 2011-12-07 16:26:25 UTC (rev 105435) +++ trunk/extensions/UploadWizard/UploadWizardHooks.php 2011-12-07 16:39:25 UTC (rev 105436) @@ -505,48 +505,26 @@ if ( UploadWizardConfig::getSetting( 'enableLicensePreference' ) ) { $licenseConfig = UploadWizardConfig::getSetting( 'licenses' ); - $defOption = array( wfMsg( 'mwe-upwiz-prefs-def-license-def' ) => 'default' ); - - $preferences['upwiz_deflicensetype'] = array( - 'type' => 'radio', - 'label-message' => 'mwe-upwiz-prefs-def-licensetype', - 'section' => 'uploads', - 'options' => $defOption + array( - wfMsg( 'mwe-upwiz-prefs-def-license-ownwork' ) => 'ownwork', - wfMsg( 'mwe-upwiz-prefs-def-license-3rdparty' ) => 'thirdparty', - ) - ); - - $ownWork = UploadWizardConfig::getSetting( 'licensesOwnWork' ); - $licenses = array(); - + + $ownWork = UploadWizardConfig::getSetting( 'licensesOwnWork' ); foreach ( $ownWork['licenses'] as $license ) { - $licenses[wfMsg( $licenseConfig[$license]['msg'] )] = $license; + $licenseMessage = self::getLicenseMessage( $license, $licenseConfig ); + $licenses[wfMsgExt( 'mwe-upwiz-prefs-license-own', 'parsemag', $licenseMessage )] = 'ownwork-' . $license; } - $licenses = array_merge( $defOption, $licenses ); - - $preferences['upwiz_deflicense'] = array( - 'type' => 'radio', - 'label-message' => 'mwe-upwiz-prefs-def-license', - 'section' => 'uploads', - 'options' => $licenses - ); - - $thirdParty = UploadWizardConfig::getSetting( 'licensesThirdParty' ); - - $licenses = array(); - foreach ( UploadWizardConfig::getThirdPartyLicenses() as $license ) { - $licenses[wfMsg( $licenseConfig[$license]['msg'] )] = $license; + if ( $license !== 'custom' ) { + $licenseMessage = self::getLicenseMessage( $license, $licenseConfig ); + $licenses[wfMsgExt( 'mwe-upwiz-prefs-license-thirdparty', 'parsemag', $licenseMessage )] = 'thirdparty-' . $license; + } } - $licenses = array_merge( $defOption, $licenses ); + $licenses = array_merge( array( wfMsg( 'mwe-upwiz-prefs-def-license-def' ) => 'default' ), $licenses ); - $preferences['upwiz_def3rdparty'] = array( + $preferences['upwiz_deflicense'] = array( 'type' => 'radio', - 'label-message' => 'mwe-upwiz-prefs-def-3rdparty', + 'label-message' => 'mwe-upwiz-prefs-def-license', 'section' => 'uploads', 'options' => $licenses ); @@ -554,5 +532,24 @@ return true; } + + /** + * Helper function to get the message for a license. + * + * @since 1.2 + * + * @param string $licenseName + * @param array $licenseConfig + * + * @return string + */ + protected static function getLicenseMessage( $licenseName, array &$licenseConfig ) { + if ( array_key_exists( 'url', $licenseConfig[$licenseName] ) ) { + return wfMsgExt( $licenseConfig[$licenseName]['msg'], 'parseinline', '', $licenseConfig[$licenseName]['url'] ); + } + else { + return wfMsg( $licenseConfig[$licenseName]['msg'] ); + } + } } Modified: trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php =================================================================== --- trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php 2011-12-07 16:26:25 UTC (rev 105435) +++ trunk/extensions/UploadWizard/includes/specials/SpecialUploadWizard.php 2011-12-07 16:39:25 UTC (rev 105436) @@ -144,22 +144,20 @@ $defaultLicense = $this->getUser()->getOption( 'upwiz_deflicense' ); - if ( $defaultLicense !== 'default' && in_array( $defaultLicense, $config['licensesOwnWork']['licenses'] ) ) { - $config['licensesOwnWork']['defaults'] = array( $defaultLicense ); + if ( $defaultLicense !== 'default' ) { + $defaultLicense = explode( '-', $defaultLicense, 2 ); + $licenseType = $defaultLicense[0]; + $defaultLicense = $defaultLicense[1]; + + if ( in_array( $defaultLicense, $config['licensesOwnWork']['licenses'] ) + || in_array( $defaultLicense, UploadWizardConfig::getThirdPartyLicenses() ) ) { + + $licenseGroup = $licenseType === 'ownwork' ? 'licensesOwnWork' : 'licensesThirdParty'; + $config[$licenseGroup]['defaults'] = array( $defaultLicense ); + $config['defaultLicenseType'] = $licenseType; + } } - $thirdPartyDefault = $this->getUser()->getOption( 'upwiz_def3rdparty' ); - - if ( $thirdPartyDefault !== 'default' && in_array( $thirdPartyDefault, UploadWizardConfig::getThirdPartyLicenses() ) ) { - $config['licensesThirdParty']['defaults'] = array( $thirdPartyDefault ); - } - - $licenseTypeDefault = $this->getUser()->getOption( 'upwiz_deflicensetype' ); - - if ( $licenseTypeDefault !== 'default' && $config['ownWorkOption'] === 'choice' ) { - $config['ownWorkOption'] = $licenseTypeDefault === 'ownwork' ? 'own' : 'notown'; - } - $this->getOutput()->addScript( Skin::makeVariablesScript( array( Modified: trunk/extensions/UploadWizard/resources/mw.UploadWizardDeed.js =================================================================== --- trunk/extensions/UploadWizard/resources/mw.UploadWizardDeed.js 2011-12-07 16:26:25 UTC (rev 105435) +++ trunk/extensions/UploadWizard/resources/mw.UploadWizardDeed.js 2011-12-07 16:39:25 UTC (rev 105436) @@ -386,14 +386,19 @@ deed.setFormFields( $deedInterface.find( '.mwe-upwiz-deed-form' ) ); + var selectDeedFunction = function() { + _this.choose( deed ); + _this.selectDeedInterface( $deedInterface ); + $deedInterface.find( 'span.mwe-upwiz-deed-header input' ).attr( 'checked', true ); + }; + if ( deeds.length == 1 ) { - _this.onLayoutReady = function() { - _this.choose( deed ); - _this.selectDeedInterface( $deedInterface ); - $deedInterface.find( 'span.mwe-upwiz-deed-header input' ).attr( 'checked', true ); - }; + _this.onLayoutReady = selectDeedFunction; } else { + if ( mw.UploadWizard.config.defaultLicenseType === deed.name ) { + _this.onLayoutReady = selectDeedFunction; + } $deedInterface.find( 'span.mwe-upwiz-deed-header input' ).click( function() { if ( $j( this ).is( ':checked' ) ) { _this.choose( deed ); _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs