Albert221 (Code Review)
2017-12-30 00:58:07 UTC
Albert221 has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/400834 )
Change subject: Add popup with score stuff
......................................................................
Add popup with score stuff
Bug: T183736
Change-Id: Id9b213d073ba9ea7cc4c753a714f0b3aafbb0f63
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/Score.php
A modules/ext.score.popup.css
A modules/ext.score.popup.js
6 files changed, 117 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Score refs/changes/34/400834/1
diff --git a/extension.json b/extension.json
index 64d1677..29b7755 100644
--- a/extension.json
+++ b/extension.json
@@ -55,6 +55,17 @@
"desktop",
"mobile"
]
+ },
+ "ext.score.popup": {
+ "scripts": "ext.score.popup.js",
+ "styles": "ext.score.popup.css",
+ "position": "bottom",
+ "dependencies": [
+ "mediawiki.api"
+ ],
+ "messages": [
+ "score-download-midi-file"
+ ]
}
},
"ResourceFileModulePaths": {
diff --git a/i18n/en.json b/i18n/en.json
index f454639..0129a0b 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -9,6 +9,7 @@
"score-compilererr": "Unable to compile LilyPond input file:\n$1",
"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-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 c87c392..b2fb0bc 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -15,6 +15,7 @@
"score-compilererr": "Displayed if the LilyPond code could not be compiled. $1 is the error (generally big block of text in a pre tag)",
"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-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 778467b..7eeebe7 100644
--- a/includes/Score.php
+++ b/includes/Score.php
@@ -105,7 +105,7 @@
throw new ScoreException( wfMessage( 'score-notexecutable', $wgScoreLilyPond ) );
}
- $result = Shell::command( $wgScoreLilyPond, '--version' )
+ $result = Shell::command( $wgScoreLilyPond . ' --version' )
->includeStderr()
->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK )
->execute();
@@ -198,6 +198,8 @@
global $wgTmpDirectory;
try {
+ $parser->getOutput()->addModules( 'ext.score.popup' );
+
$baseUrl = self::getBaseUrl();
$baseStoragePath = self::getBackend()->getRootStoragePath() . '/score-render';
@@ -241,9 +243,6 @@
// Raw rendering?
$options['raw'] = array_key_exists( 'raw', $args );
-
- /* Midi linking? */
- $options['link_midi'] = array_key_exists( 'midi', $args );
/* Override OGG file? */
if ( array_key_exists( 'override_ogg', $args ) ) {
@@ -324,7 +323,6 @@
* - file_name_prefix: The filename prefix used for all files
* in the default destination directory. Required.
* - lang: string Score language. Required.
- * - link_midi: bool Whether to link to a MIDI file. Required.
* - override_midi: bool Whether to use a user-provided MIDI file.
* Required.
* - midi_file: If override_midi is true, MIDI file object.
@@ -449,14 +447,6 @@
/* No images; this may happen in raw mode or when the user omits the score code */
throw new ScoreException( wfMessage( 'score-noimages' ) );
}
- if ( $options['link_midi'] ) {
- if ( $options['override_midi'] ) {
- $url = $options['midi_file']->getUrl();
- } else {
- $url = "{$options['dest_url']}/{$options['file_name_prefix']}.midi";
- }
- $link = Html::rawElement( 'a', [ 'href' => $url ], $link );
- }
if ( $options['generate_ogg'] ) {
$length = $metaData[basename( $oggPath )]['length'];
$player = new TimedMediaTransformOutput( [
@@ -482,6 +472,14 @@
self::eraseFactory( $options['factory_directory'] );
+ // Wrap score in div container.
+ $link = HTML::rawElement( 'div', [
+ 'class' => 'mw-ext-score',
+ 'data-midi' => $options['override_midi'] ?
+ $options['midi_file']->getUrl()
+ : "{$options['dest_url']}/{$options['file_name_prefix']}.midi"
+ ], $link );
+
return $link;
}
diff --git a/modules/ext.score.popup.css b/modules/ext.score.popup.css
new file mode 100644
index 0000000..8a79125
--- /dev/null
+++ b/modules/ext.score.popup.css
@@ -0,0 +1,36 @@
+.mw-ext-score {
+ position: relative;
+ display: inline-block;
+}
+
+.mw-ext-score img {
+ cursor: pointer;
+}
+
+.mw-ext-score-popup {
+ box-sizing: border-box;
+ position: absolute;
+ top: calc( 100% + 7.5px );
+ left: 0;
+ right: 0;
+ width: 300px;
+ max-width: 100%;
+ margin: 0 auto;
+ border-radius: 3px;
+ padding: 15px;
+ background: #eee;
+}
+
+/* Triangle on the top of popup */
+.mw-ext-score-popup:before {
+ content: '';
+ position: absolute;
+ top: -7.5px;
+ right: 0;
+ left: 0;
+ margin: auto;
+ width: 15px;
+ height: 15px;
+ background: #eee;
+ transform: rotate( 45deg );
+}
diff --git a/modules/ext.score.popup.js b/modules/ext.score.popup.js
new file mode 100644
index 0000000..c49ae22
--- /dev/null
+++ b/modules/ext.score.popup.js
@@ -0,0 +1,57 @@
+( function ( $ ) {
+ var popupShown = false;
+
+ function showPopup( $score ) {
+ var $popup, midi = $score.data( 'midi' );
+ $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' ) )
+ )
+ .hide();
+
+ $score.append( $popup );
+ $popup.show( 'fast' );
+ popupShown = true;
+ $score.children( 'img' ).attr( 'aria-describedby', 'mw-ext-score-popup' );
+ }
+
+ function hidePopup( $score ) {
+ var $popup = $score.children( '.mw-ext-score-popup' );
+
+ $popup.hide( 'fast', function () {
+ $score.children( 'img' ).removeAttr( 'aria-describedby' );
+ $popup.remove();
+ popupShown = false;
+ } );
+ }
+
+ $( document ).on( 'click', '.mw-ext-score img', function ( e ) {
+ var $target = $( e.target ),
+ $score = $target.parent();
+
+ e.stopPropagation();
+
+ // Hide popup on second click.
+ if ( popupShown ) {
+ hidePopup( $score );
+ return;
+ }
+
+ showPopup( $score );
+ } );
+
+ $( document ).click( 'click', function ( e ) {
+ var $score = $( '.mw-ext-score' ), $target = $( e.target );
+
+ // Don't hide popup when clicked inside it.
+ if ( $target.closest( '.mw-ext-score-popup' ).length ) {
+ return;
+ }
+
+ hidePopup( $score );
+ } );
+}( jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/400834
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9b213d073ba9ea7cc4c753a714f0b3aafbb0f63
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Score
Gerrit-Branch: master
Gerrit-Owner: Albert221 <***@gmail.com>
Change subject: Add popup with score stuff
......................................................................
Add popup with score stuff
Bug: T183736
Change-Id: Id9b213d073ba9ea7cc4c753a714f0b3aafbb0f63
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/Score.php
A modules/ext.score.popup.css
A modules/ext.score.popup.js
6 files changed, 117 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Score refs/changes/34/400834/1
diff --git a/extension.json b/extension.json
index 64d1677..29b7755 100644
--- a/extension.json
+++ b/extension.json
@@ -55,6 +55,17 @@
"desktop",
"mobile"
]
+ },
+ "ext.score.popup": {
+ "scripts": "ext.score.popup.js",
+ "styles": "ext.score.popup.css",
+ "position": "bottom",
+ "dependencies": [
+ "mediawiki.api"
+ ],
+ "messages": [
+ "score-download-midi-file"
+ ]
}
},
"ResourceFileModulePaths": {
diff --git a/i18n/en.json b/i18n/en.json
index f454639..0129a0b 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -9,6 +9,7 @@
"score-compilererr": "Unable to compile LilyPond input file:\n$1",
"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-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 c87c392..b2fb0bc 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -15,6 +15,7 @@
"score-compilererr": "Displayed if the LilyPond code could not be compiled. $1 is the error (generally big block of text in a pre tag)",
"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-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 778467b..7eeebe7 100644
--- a/includes/Score.php
+++ b/includes/Score.php
@@ -105,7 +105,7 @@
throw new ScoreException( wfMessage( 'score-notexecutable', $wgScoreLilyPond ) );
}
- $result = Shell::command( $wgScoreLilyPond, '--version' )
+ $result = Shell::command( $wgScoreLilyPond . ' --version' )
->includeStderr()
->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK )
->execute();
@@ -198,6 +198,8 @@
global $wgTmpDirectory;
try {
+ $parser->getOutput()->addModules( 'ext.score.popup' );
+
$baseUrl = self::getBaseUrl();
$baseStoragePath = self::getBackend()->getRootStoragePath() . '/score-render';
@@ -241,9 +243,6 @@
// Raw rendering?
$options['raw'] = array_key_exists( 'raw', $args );
-
- /* Midi linking? */
- $options['link_midi'] = array_key_exists( 'midi', $args );
/* Override OGG file? */
if ( array_key_exists( 'override_ogg', $args ) ) {
@@ -324,7 +323,6 @@
* - file_name_prefix: The filename prefix used for all files
* in the default destination directory. Required.
* - lang: string Score language. Required.
- * - link_midi: bool Whether to link to a MIDI file. Required.
* - override_midi: bool Whether to use a user-provided MIDI file.
* Required.
* - midi_file: If override_midi is true, MIDI file object.
@@ -449,14 +447,6 @@
/* No images; this may happen in raw mode or when the user omits the score code */
throw new ScoreException( wfMessage( 'score-noimages' ) );
}
- if ( $options['link_midi'] ) {
- if ( $options['override_midi'] ) {
- $url = $options['midi_file']->getUrl();
- } else {
- $url = "{$options['dest_url']}/{$options['file_name_prefix']}.midi";
- }
- $link = Html::rawElement( 'a', [ 'href' => $url ], $link );
- }
if ( $options['generate_ogg'] ) {
$length = $metaData[basename( $oggPath )]['length'];
$player = new TimedMediaTransformOutput( [
@@ -482,6 +472,14 @@
self::eraseFactory( $options['factory_directory'] );
+ // Wrap score in div container.
+ $link = HTML::rawElement( 'div', [
+ 'class' => 'mw-ext-score',
+ 'data-midi' => $options['override_midi'] ?
+ $options['midi_file']->getUrl()
+ : "{$options['dest_url']}/{$options['file_name_prefix']}.midi"
+ ], $link );
+
return $link;
}
diff --git a/modules/ext.score.popup.css b/modules/ext.score.popup.css
new file mode 100644
index 0000000..8a79125
--- /dev/null
+++ b/modules/ext.score.popup.css
@@ -0,0 +1,36 @@
+.mw-ext-score {
+ position: relative;
+ display: inline-block;
+}
+
+.mw-ext-score img {
+ cursor: pointer;
+}
+
+.mw-ext-score-popup {
+ box-sizing: border-box;
+ position: absolute;
+ top: calc( 100% + 7.5px );
+ left: 0;
+ right: 0;
+ width: 300px;
+ max-width: 100%;
+ margin: 0 auto;
+ border-radius: 3px;
+ padding: 15px;
+ background: #eee;
+}
+
+/* Triangle on the top of popup */
+.mw-ext-score-popup:before {
+ content: '';
+ position: absolute;
+ top: -7.5px;
+ right: 0;
+ left: 0;
+ margin: auto;
+ width: 15px;
+ height: 15px;
+ background: #eee;
+ transform: rotate( 45deg );
+}
diff --git a/modules/ext.score.popup.js b/modules/ext.score.popup.js
new file mode 100644
index 0000000..c49ae22
--- /dev/null
+++ b/modules/ext.score.popup.js
@@ -0,0 +1,57 @@
+( function ( $ ) {
+ var popupShown = false;
+
+ function showPopup( $score ) {
+ var $popup, midi = $score.data( 'midi' );
+ $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' ) )
+ )
+ .hide();
+
+ $score.append( $popup );
+ $popup.show( 'fast' );
+ popupShown = true;
+ $score.children( 'img' ).attr( 'aria-describedby', 'mw-ext-score-popup' );
+ }
+
+ function hidePopup( $score ) {
+ var $popup = $score.children( '.mw-ext-score-popup' );
+
+ $popup.hide( 'fast', function () {
+ $score.children( 'img' ).removeAttr( 'aria-describedby' );
+ $popup.remove();
+ popupShown = false;
+ } );
+ }
+
+ $( document ).on( 'click', '.mw-ext-score img', function ( e ) {
+ var $target = $( e.target ),
+ $score = $target.parent();
+
+ e.stopPropagation();
+
+ // Hide popup on second click.
+ if ( popupShown ) {
+ hidePopup( $score );
+ return;
+ }
+
+ showPopup( $score );
+ } );
+
+ $( document ).click( 'click', function ( e ) {
+ var $score = $( '.mw-ext-score' ), $target = $( e.target );
+
+ // Don't hide popup when clicked inside it.
+ if ( $target.closest( '.mw-ext-score-popup' ).length ) {
+ return;
+ }
+
+ hidePopup( $score );
+ } );
+}( jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/400834
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id9b213d073ba9ea7cc4c753a714f0b3aafbb0f63
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Score
Gerrit-Branch: master
Gerrit-Owner: Albert221 <***@gmail.com>