jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/401093 )

Change subject: Add source DL link to popup, fix $needMidi cond
......................................................................


Add source DL link to popup, fix $needMidi cond

Add storing LilyPond source file and add ability
to download by creating a DL link in score's popup.

Also, fixed condition of setting $needMidi, previous
one was invalid and was giving true when it shouldn't.
It's correct now.

Bug: T183736
Change-Id: Ie80bda1f30d1b7046669ffa6353fc7f5328e7be0
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/Score.php
M modules/ext.score.popup.css
M modules/ext.score.popup.js
6 files changed, 69 insertions(+), 17 deletions(-)

Approvals:
  Ebe123: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index 29b7755..a64d03f 100644
--- a/extension.json
+++ b/extension.json
@@ -64,7 +64,8 @@
                                "mediawiki.api"
                        ],
                        "messages": [
-                               "score-download-midi-file"
+                               "score-download-midi-file",
+                               "score-download-source-file"
                        ]
                }
        },
diff --git a/i18n/en.json b/i18n/en.json
index 0129a0b..b42c585 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -10,6 +10,7 @@
        "score-backend-error": "Unable to copy the generated files to their 
final location:\n$1",
        "score-desc": "Adds a tag for rendering musical scores with LilyPond",
        "score-download-midi-file": "Download MIDI file",
+       "score-download-source-file": "Download lilypond file",
        "score-error-category": "Pages with score rendering errors",
        "score-error-category-desc": "There was an error while rendering the 
score.",
        "score-getcwderr": "Unable to obtain current working directory",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index b2fb0bc..7fb2a39 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -16,6 +16,7 @@
        "score-backend-error": "Parameters:\n* $1 - result message which was 
returned",
        "score-desc": 
"{{desc|name=Score|url=https://www.mediawiki.org/wiki/Extension:Score}}";,
        "score-download-midi-file": "Content of link to download MIDI file of 
score shown in score popup",
+       "score-download-source-file": "Content of link to download the lilypond 
file of score shown in score popup",
        "score-error-category": "Name of [[mw:Help:Tracking categories|tracking 
category]] to list pages where there was an error rendering the 
<code><nowiki><score></nowiki></code> tag.",
        "score-error-category-desc": "Description on 
[[Special:TrackingCategories]] for the {{msg-mw|score-error-category}} tracking 
category.",
        "score-getcwderr": "Displayed if the extension cannot obtain the 
current working directory.",
diff --git a/includes/Score.php b/includes/Score.php
index 854deb1..de9d970 100644
--- a/includes/Score.php
+++ b/includes/Score.php
@@ -472,19 +472,29 @@
 
                self::eraseFactory( $options['factory_directory'] );
 
-               // Wrap score in div container.
-               $link = HTML::rawElement( 'div', [
-                       'class' => 'mw-ext-score',
-                       'data-midi' => $options['override_midi'] ?
+               $attributes = [
+                       'class' => 'mw-ext-score'
+               ];
+
+               if ( $options['override_midi']
+                       || isset( 
$existingFiles["{$options['file_name_prefix']}.midi"] ) ) {
+                       $attributes['data-midi'] = $options['override_midi'] ?
                                $options['midi_file']->getUrl()
-                               : 
"{$options['dest_url']}/{$options['file_name_prefix']}.midi"
-               ], $link );
+                               : 
"{$options['dest_url']}/{$options['file_name_prefix']}.midi";
+               }
+
+               if ( isset( $existingFiles["{$options['file_name_prefix']}.ly"] 
) ) {
+                       $attributes['data-source'] = 
"{$options['dest_url']}/{$options['file_name_prefix']}.ly";
+               }
+
+               // Wrap score in div container.
+               $link = HTML::rawElement( 'div', $attributes, $link );
 
                return $link;
        }
 
        /**
-        * Generates score PNG file(s) and a MIDI file.
+        * Generates score PNG file(s) and a MIDI file. Stores lilypond file.
         *
         * @param string $code Score code.
         * @param array $options Rendering options. They are the same as for
@@ -567,9 +577,7 @@
                                $options['factory_directory'] );
                }
                $needMidi = false;
-               if ( !$options['raw'] ||
-                       ( $options['generate_ogg'] || 
!$options['override_midi'] )
-               ) {
+               if ( !$options['raw'] || $options['generate_ogg'] && 
!$options['override_midi'] ) {
                        $needMidi = true;
                        if ( !file_exists( $factoryMidi ) ) {
                                throw new ScoreException( wfMessage( 
'score-nomidi' ) );
@@ -604,6 +612,14 @@
                // Backend operation batch
                $ops = [];
 
+               // Add LY source to its file
+               $ops[] = [
+                       'op' => 'store',
+                       'src' => $factoryLy,
+                       'dst' => 
"{$options['dest_storage_path']}/{$options['file_name_prefix']}.ly"
+               ];
+               $newFiles["{$options['file_name_prefix']}.ly"] = true;
+
                if ( $needMidi ) {
                        // Add the MIDI file to the batch
                        $ops[] = [
diff --git a/modules/ext.score.popup.css b/modules/ext.score.popup.css
index 61802b7..9b32891 100644
--- a/modules/ext.score.popup.css
+++ b/modules/ext.score.popup.css
@@ -42,3 +42,21 @@
        background: #fff;
        transform: rotate( 45deg );
 }
+
+.mw-ext-score-popup a {
+       pointer-events: none;
+}
+
+.mw-ext-score-popup a span {
+       pointer-events: all;
+}
+
+.mw-ext-score-popup a:not( :first-child ) {
+       margin-left: 0.5em;
+}
+
+.mw-ext-score-popup a:not( :first-child ):before {
+       content: '•';
+       display: inline-block;
+       margin-right: 0.5em;
+}
diff --git a/modules/ext.score.popup.js b/modules/ext.score.popup.js
index ab81595..c46a3a6 100644
--- a/modules/ext.score.popup.js
+++ b/modules/ext.score.popup.js
@@ -2,17 +2,32 @@
        var popupShown = false;
 
        function showPopup( $score ) {
-               var $popup, midi = $score.data( 'midi' );
+               var $popup, midi = $score.data( 'midi' ), source = $score.data( 
'source' );
+
+               // Don't show popup when there is no midi or source.
+               if ( typeof midi === 'undefined' && typeof source === 
'undefined' ) {
+                       return;
+               }
+
                $popup = $( '<div>' )
                        .addClass( 'mw-ext-score-popup' )
                        .attr( 'id', 'mw-ext-score-popup' )
-                       .html(
-                               $( '<a>' )
-                                       .attr( 'href', midi )
-                                       .text( mw.msg( 
'score-download-midi-file' ) )
-                       )
                        .css( 'opacity', 0 );
 
+               if ( typeof midi !== 'undefined' ) {
+                       $popup.append( $( '<a>' )
+                               .attr( 'href', midi )
+                               .html( $( '<span>' ).text( mw.msg( 
'score-download-midi-file' ) ) )
+                       );
+               }
+
+               if ( typeof source !== 'undefined' ) {
+                       $popup.append( $( '<a>' )
+                               .attr( 'href', source )
+                               .html( $( '<span>' ).text( mw.msg( 
'score-download-source-file' ) ) )
+                       );
+               }
+
                $score.append( $popup );
 
                $popup.animate( {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie80bda1f30d1b7046669ffa6353fc7f5328e7be0
Gerrit-PatchSet: 14
Gerrit-Project: mediawiki/extensions/Score
Gerrit-Branch: master
Gerrit-Owner: Albert221 <w.albert...@gmail.com>
Gerrit-Reviewer: Ebe123 <beauleetien...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to