Topic on Project:Support desk

How do I add custom license to Extension:UploadWizard?

2
Summary by Spas.Z.Spasov

I've achieved the desired result by using of $wgResourceModules, $wgMessagesDirs and $wgHooks['BeforePageDisplay'].

Spas.Z.Spasov (talkcontribs)

Hello,

In order to add a custom license type for Extension:UploadWizard, I've added the following configuration settings in LocalSettings.php:

wfLoadExtension( 'UploadWizard' );

// Needed to make UploadWizard work in IE, see https://phabricator.wikimedia.org/T41877
$wgApiFrameOptions = 'SAMEORIGIN';

//$wgUploadNavigationUrl = '/index.php/Special:UploadWizard';

$wgUseInstantCommons = true;
$wgExtensionFunctions[] = function() {

$GLOBALS['wgUploadNavigationUrl'] = SpecialPage::getTitleFor( 'UploadWizard' )->getLocalURL();
        return true;
};

$wgUploadWizardConfig = array(
        'debug' => false,

        'altUploadForm' => 'Special:Upload',
        'fallbackToAltUploadForm' => false,
        'enableFormData' => true, 
        'enableMultipleFiles' => true,
        'enableMultiFileSelect' => true,
        'uwLanguages' => array(
                'ru' => 'Русский',
                'bg' => 'Български',
                'en' => 'English'
        ), 
        'uwLanguages' => empty( $uwLanguages ) ? [ 'bg' => 'Български' ] : $uwLanguages,
        'tutorial' => array( 'skip' => false ),
        'maxUploads' => 15,
        'fileExtensions' => $wgFileExtensions,

        'licenses' => array(
                'cc-by-nc-sa-4.0' => [
                        'msg' => 'mwe-upwiz-license-cc-by-nc-sa-4.0',
                        'icons' => [ 'cc-by', 'cc-nc', 'cc-sa' ],
                        'url' => '//creativecommons.org/licenses/by-nc-sa/4.0/',
                        'languageCodePrefix' => 'deed.'
                ],
        ),

        'licensing' => array(
                'defaultType' => 'ownwork',
                'ownWorkDefault' => 'choice',
                'ownWork' => array(
                        'type' => 'or',
                        'template' => 'self',
                        'defaults' => 'cc-by-nc-sa-4.0',
                        'licenses' => array(
                                'cc-by-nc-sa-4.0',
                                'cc-by-sa-4.0',
                                'cc-by-sa-3.0',
                                'cc-by-4.0',
                                'cc-by-3.0',
                                'cc-zero'
                        )
                ),
        ),
);

Everything works except the custom messages for the new license type, as you can see on this screenshot. I've created:

  • MediaWiki:Mwe-upwiz-license-cc-by-nc-sa-4.0
  • MediaWiki:Mwe-upwiz-source-ownwork-assert-cc-by-nc-sa-4.0
  • MediaWiki:Mwe-upwiz-source-ownwork-cc-by-nc-sa-4.0-explain

But Extension:UploadWizard doesn't accept them until they are not registered in $IP/extensions/UploadWizard/extension.json, under the messages section. The same issue is described and illustrated here. So my question is:

Is there any elegant way to append (register) my messages to the UploadWizard's messages list without modify its extension.json file?

Spas.Z.Spasov (talkcontribs)

Fortunately I've managed to solve my problem by adding the following code in LocalSettings.php (reference):

// register a ResourceLoader module...
$wgResourceModules['myUploadWizardResources'] = array(
        //'scripts' => array( 'resourcesCustom/UploadWizard/myUploadWizard.js' ),

        'styles' => array( 'resourcesCustom/UploadWizard/myUploadWizard.css' ),

        'messages' => array(
                'mwe-upwiz-license-cc-by-nc-sa-4.0',
                'mwe-upwiz-source-ownwork-assert-cc-by-nc-sa-4.0',
                'mwe-upwiz-source-ownwork-cc-by-nc-sa-4.0-explain',
        ),

);

// The content of the messages (based on  $IP/extensions/UploadWizard/i18n/*.json)
$wgMessagesDirs['myUploadWizardResources'] = 'resourcesCustom/UploadWizard/i18n';

// Set up a hook to add our resource loader module to every page
function myUploadWizardResourcesLoader( &$out ) {
        $out->addModules( 'myUploadWizardResources' );
        return true;
}

// Register the hook
$wgHooks['BeforePageDisplay'][] = 'myUploadWizardResourcesLoader';

In addition, by myUploadWizard.css I'm creating the new 'cc-nc' icon:

$ ls $IP/resourcesCustom/UploadWizard/
18px-Cc-nc_white.svg.png  i18n/  myUploadWizard.css

$ cat $IP/resourcesCustom/UploadWizard/myUploadWizard.css
.mwe-upwiz-cc-nc-icon {
        /* @embed */
        background: url( 18px-Cc-nc_white.svg.png ) no-repeat center center;
}

The actual messages are involved and translated by $wgMessagesDirs['myUploadWizardResources'] = 'resourcesCustom/UploadWizard/i18n';:

ls $IP/resourcesCustom/UploadWizard/i18n/
bg.json  en.json  ru.json

$ cat $IP/resourcesCustom/UploadWizard/i18n/en.json
{
    "mwe-upwiz-source-ownwork-assert-cc-by-nc-sa-4.0": "I, $2, {{GENDER:$4|the copyright holder}} of {{PLURAL:$1|this work|these works}}, irrevocably grant anyone the right to use {{PLURAL:$1|this work|these works}} under the Creative Commons Attribution NonCommercial ShareAlike 4.0 license ([$3 legal code]).",
    "mwe-upwiz-source-ownwork-cc-by-nc-sa-4.0-explain": "(Anyone may use, share or remix {{PLURAL:$1|this work|these works}} with NonCommercial purposes, as long as they credit me and share any derivative work under this license.)",
    "mwe-upwiz-license-cc-by-nc-sa-4.0": "Creative Commons Attribution NonCommercial ShareAlike 4.0 ([$2 legal code])"
}