Discussion:
[MediaWiki-commits] [Gerrit] mediawiki...Score[master]: Add source DL link to popup
Albert221 (Code Review)
2017-12-30 20:06:16 UTC
Permalink
Albert221 has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/401093 )

Change subject: Add source DL link to popup
......................................................................

Add source DL link to popup

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

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, 29 insertions(+), 8 deletions(-)


git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Score refs/changes/93/401093/1

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..2e41273 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 source 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..52941cc 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 source .ly 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..ece621e 100644
--- a/includes/Score.php
+++ b/includes/Score.php
@@ -477,14 +477,15 @@
'class' => 'mw-ext-score',
'data-midi' => $options['override_midi'] ?
$options['midi_file']->getUrl()
- : "{$options['dest_url']}/{$options['file_name_prefix']}.midi"
+ : "{$options['dest_url']}/{$options['file_name_prefix']}.midi",
+ 'data-source' => "{$options['dest_url']}/{$options['file_name_prefix']}.ly"
], $link );

return $link;
}

/**
- * Generates score PNG file(s) and a MIDI file.
+ * Generates score PNG file(s), LY source and a MIDI file.
*
* @param string $code Score code.
* @param array $options Rendering options. They are the same as for
@@ -604,6 +605,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..9d8bd1d 100644
--- a/modules/ext.score.popup.css
+++ b/modules/ext.score.popup.css
@@ -42,3 +42,9 @@
background: #fff;
transform: rotate( 45deg );
}
+
+.mw-ext-score-popup a:last-child:before {
+ content: "•";
+ display: inline-block;
+ margin: 0 0.5em;
+}
diff --git a/modules/ext.score.popup.js b/modules/ext.score.popup.js
index ab81595..d3c32ab 100644
--- a/modules/ext.score.popup.js
+++ b/modules/ext.score.popup.js
@@ -2,14 +2,17 @@
var popupShown = false;

function showPopup( $score ) {
- var $popup, midi = $score.data( 'midi' );
+ var $popup, midi = $score.data( 'midi' ), source = $score.data( 'source' );
$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' ) )
+ .append( $( '<a>' )
+ .attr( 'href', midi )
+ .text( mw.msg( 'score-download-midi-file' ) )
+ )
+ .append( $( '<a>' )
+ .attr( 'href', source )
+ .text( mw.msg( 'score-download-source-file' ) )
)
.css( 'opacity', 0 );
--
To view, visit https://gerrit.wikimedia.org/r/401093
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie80bda1f30d1b7046669ffa6353fc7f5328e7be0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Score
Gerrit-Branch: master
Gerrit-Owner: Albert221 <***@gmail.com>
jenkins-bot (Code Review)
2017-12-31 00:07:49 UTC
Permalink
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 <***@gmail.com>
Gerrit-Reviewer: Ebe123 <***@gmail.com>
Gerrit-Reviewer: Siebrand <***@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>
Loading...