[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Reintroduce lexicon tool special page, commits e559d75 and 0...

2017-12-20 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399419 )

Change subject: Reintroduce lexicon tool special page, commits e559d75 and 
01f254d
..

Reintroduce lexicon tool special page, commits e559d75 and 01f254d

Bug: T182861
Change-Id: I51ed9bcb96a3a6c1dfe0b277c5a070a49dbe2c6d
---
M Wikispeech.alias.php
M extension.json
M i18n/en.json
M i18n/qqq.json
A specials/SpecialWikispeechLexiconTool.php
5 files changed, 45 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/19/399419/1

diff --git a/Wikispeech.alias.php b/Wikispeech.alias.php
index b0fc561..e2dbf56 100644
--- a/Wikispeech.alias.php
+++ b/Wikispeech.alias.php
@@ -9,4 +9,5 @@
 /** English (English) */
 $specialPageAliases['en'] = array(
'Wikispeech' => array( 'Wikispeech' ),
+   'WikispeechLexiconTool' => array( 'WikispeechLexiconTool' ),
 );
diff --git a/extension.json b/extension.json
index 6f7cebb..b519ff8 100644
--- a/extension.json
+++ b/extension.json
@@ -17,6 +17,7 @@
},
"AutoloadClasses": {
"SpecialWikispeech": "specials/SpecialWikispeech.php",
+   "SpecialWikispeechLexiconTool": 
"specials/SpecialWikispeechLexiconTool.php",
"WikispeechHooks": "Hooks.php",
"CleanedText": "includes/CleanedContent.php",
"SegmentBreak": "includes/CleanedContent.php",
@@ -52,7 +53,8 @@
"remoteExtPath": "Wikispeech/modules"
},
"SpecialPages": {
-   "Wikispeech": "SpecialWikispeech"
+   "Wikispeech": "SpecialWikispeech",
+   "WikispeechLexiconTool": "SpecialWikispeechLexiconTool"
},
"ExtensionMessagesFiles": {
"WikispeechAlias": "Wikispeech.alias.php"
diff --git a/i18n/en.json b/i18n/en.json
index 0e32437..a8d550e 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -8,6 +8,9 @@
"wikispeech-desc": "A text-to-speech tool to make Wikimedia's projects 
more accessible for people that for different reasons have difficulties 
reading.",
"special-wikispeech-intro": "Wikispeech",
"special-wikispeech-title": "Special page introduction.",
+   "wikispeechlexicontool": "Wikispeech Lexicon Tool",
+   "special-wikispeech-lexicon-tool-intro": "Wikispeech Lexicon Tool",
+   "special-wikispeech-lexicon-tool-title": "The tool used to add 
suggested words into the Wikispeech lexicon.",
"apihelp-wikispeech-summary": "Process a page to be used by the 
Wikispeech extension.",
"apihelp-wikispeech-param-page": "The title of the page to process.",
"apihelp-wikispeech-param-output": "The formats of the output, can be a 
combination of the following:",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 80a60a9..711245f 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -1,13 +1,17 @@
 {
"@metadata": {
"authors": [
-   "Sebastian Berlin"
+   "Sebastian Berlin",
+   "Egbe Eugene"
]
},
"wikispeech": "The name of the extension",
"wikispeech-desc": 
"{{desc|name=Wikispeech|url=https://www.mediawiki.org/wiki/Extension:Wikispeech}};,
"special-wikispeech-intro": "Description appearing on top of 
Special:{{ll|Wikispeech}}.",
"special-wikispeech-title": "Title of the special page 
Special:Wikispeech",
+   "wikispeechlexicontool": "The name of the tool which suggests words 
about an article not found in the lexicon and adds them",
+   "special-wikispeech-lexicon-tool-intro": "Description appearing on top 
of Special:{{ll|WikispeechLexiconTool}}.",
+   "special-wikispeech-lexicon-tool-title": "Title of the special page 
Special:WikispeechLexiconTool",
"apihelp-wikispeech-summary": "{{doc-apihelp-summary|wikispeech}}",
"apihelp-wikispeech-param-page": 
"{{doc-apihelp-param|wikispeech|page}}",
"apihelp-wikispeech-param-output": 
"{{doc-apihelp-param|wikispeech|output}}",
diff --git a/specials/SpecialWikispeechLexiconTool.php 
b/specials/SpecialWikispeechLexiconTool.php
new file mode 100644
index 000..704328e
--- /dev/null
+++ b/specials/SpecialWikispeechLexiconTool.php
@@ -0,0 +1,33 @@
+getOutput();
+   $out->setPageTitle( $this->msg( 
'special-wikispeech-lexicon-tool-title' ) );
+   $out->addHelpLink( 'How to become a MediaWiki hacker' );
+   $out->addWikiMsg( 'special-wikispeech-lexicon-tool-intro' );
+   }
+
+   /**
+* @see SpecialPage::getGroupName
+*
+* @return string
+*/
+   protected function getGroupName() {
+   return 'wiki';
+   }
+}

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

Gerrit-MessageType: 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Break out lexicon tool while under development

2017-12-20 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399418 )

Change subject: Break out lexicon tool while under development
..

Break out lexicon tool while under development

This reverts commits e559d7521f36b7aedb1598ae3caf031f9e38b449 and
01f254d951c77f7dc75129e800b1e4c40551ec31.

Bug: T182861
Change-Id: I5e8f53adfe92005dc417676c7cb91185e0d45b00
---
M Wikispeech.alias.php
M extension.json
M i18n/en.json
M i18n/qqq.json
D specials/SpecialWikispeechLexiconTool.php
5 files changed, 2 insertions(+), 45 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/18/399418/1

diff --git a/Wikispeech.alias.php b/Wikispeech.alias.php
index e2dbf56..b0fc561 100644
--- a/Wikispeech.alias.php
+++ b/Wikispeech.alias.php
@@ -9,5 +9,4 @@
 /** English (English) */
 $specialPageAliases['en'] = array(
'Wikispeech' => array( 'Wikispeech' ),
-   'WikispeechLexiconTool' => array( 'WikispeechLexiconTool' ),
 );
diff --git a/extension.json b/extension.json
index b519ff8..6f7cebb 100644
--- a/extension.json
+++ b/extension.json
@@ -17,7 +17,6 @@
},
"AutoloadClasses": {
"SpecialWikispeech": "specials/SpecialWikispeech.php",
-   "SpecialWikispeechLexiconTool": 
"specials/SpecialWikispeechLexiconTool.php",
"WikispeechHooks": "Hooks.php",
"CleanedText": "includes/CleanedContent.php",
"SegmentBreak": "includes/CleanedContent.php",
@@ -53,8 +52,7 @@
"remoteExtPath": "Wikispeech/modules"
},
"SpecialPages": {
-   "Wikispeech": "SpecialWikispeech",
-   "WikispeechLexiconTool": "SpecialWikispeechLexiconTool"
+   "Wikispeech": "SpecialWikispeech"
},
"ExtensionMessagesFiles": {
"WikispeechAlias": "Wikispeech.alias.php"
diff --git a/i18n/en.json b/i18n/en.json
index a8d550e..0e32437 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -8,9 +8,6 @@
"wikispeech-desc": "A text-to-speech tool to make Wikimedia's projects 
more accessible for people that for different reasons have difficulties 
reading.",
"special-wikispeech-intro": "Wikispeech",
"special-wikispeech-title": "Special page introduction.",
-   "wikispeechlexicontool": "Wikispeech Lexicon Tool",
-   "special-wikispeech-lexicon-tool-intro": "Wikispeech Lexicon Tool",
-   "special-wikispeech-lexicon-tool-title": "The tool used to add 
suggested words into the Wikispeech lexicon.",
"apihelp-wikispeech-summary": "Process a page to be used by the 
Wikispeech extension.",
"apihelp-wikispeech-param-page": "The title of the page to process.",
"apihelp-wikispeech-param-output": "The formats of the output, can be a 
combination of the following:",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 711245f..80a60a9 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -1,17 +1,13 @@
 {
"@metadata": {
"authors": [
-   "Sebastian Berlin",
-   "Egbe Eugene"
+   "Sebastian Berlin"
]
},
"wikispeech": "The name of the extension",
"wikispeech-desc": 
"{{desc|name=Wikispeech|url=https://www.mediawiki.org/wiki/Extension:Wikispeech}};,
"special-wikispeech-intro": "Description appearing on top of 
Special:{{ll|Wikispeech}}.",
"special-wikispeech-title": "Title of the special page 
Special:Wikispeech",
-   "wikispeechlexicontool": "The name of the tool which suggests words 
about an article not found in the lexicon and adds them",
-   "special-wikispeech-lexicon-tool-intro": "Description appearing on top 
of Special:{{ll|WikispeechLexiconTool}}.",
-   "special-wikispeech-lexicon-tool-title": "Title of the special page 
Special:WikispeechLexiconTool",
"apihelp-wikispeech-summary": "{{doc-apihelp-summary|wikispeech}}",
"apihelp-wikispeech-param-page": 
"{{doc-apihelp-param|wikispeech|page}}",
"apihelp-wikispeech-param-output": 
"{{doc-apihelp-param|wikispeech|output}}",
diff --git a/specials/SpecialWikispeechLexiconTool.php 
b/specials/SpecialWikispeechLexiconTool.php
deleted file mode 100644
index 704328e..000
--- a/specials/SpecialWikispeechLexiconTool.php
+++ /dev/null
@@ -1,33 +0,0 @@
-getOutput();
-   $out->setPageTitle( $this->msg( 
'special-wikispeech-lexicon-tool-title' ) );
-   $out->addHelpLink( 'How to become a MediaWiki hacker' );
-   $out->addWikiMsg( 'special-wikispeech-lexicon-tool-intro' );
-   }
-
-   /**
-* @see SpecialPage::getGroupName
-*
-* @return string
-*/
-   protected function getGroupName() {
-   return 'wiki';
-   }
-}

-- 
To view, visit https://gerrit.wikimedia.org/r/399418
To 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Refactor Javascript modules

2017-12-18 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/398851 )

Change subject: Refactor Javascript modules
..

Refactor Javascript modules

Split up the, at this point quite big, ext.wikispeech. Some methods
were also moved from ext.wikispeech.selectionPlayer. The new modules
are both smaller and have a more specific tasks.

The modules are now (all starting with ext.wikispeech):
* main - initializes the rest of the modules, when approriate.
* storage - holds utterances and does calculation for utterances and DOM.
* player - playback control.
* selectionPlayer - logic for reciting selected text.
* ui - adds GUI and handles user input.
* highlighter - higlights text when reciting.
* util - functions that are used by multiple modules without having a
  strong connection to any of them.

A couple of failing tests are now fixed, possibly as a result over
earlier patches.

Bug: T182205
Bug: T174799
Change-Id: Ic199134bf171ba778048f2461cce1d9a61ff5433
---
M Hooks.php
M extension.json
M modules/ext.wikispeech.highlighter.js
D modules/ext.wikispeech.js
A modules/ext.wikispeech.main.js
A modules/ext.wikispeech.player.js
M modules/ext.wikispeech.selectionPlayer.js
A modules/ext.wikispeech.storage.js
A modules/ext.wikispeech.ui.js
M modules/ext.wikispeech.util.js
M tests/qunit/ext.wikispeech.highlighter.test.js
A tests/qunit/ext.wikispeech.main.test.js
A tests/qunit/ext.wikispeech.player.test.js
M tests/qunit/ext.wikispeech.selectionPlayer.test.js
A tests/qunit/ext.wikispeech.storage.test.js
D tests/qunit/ext.wikispeech.test.js
A tests/qunit/ext.wikispeech.ui.test.js
17 files changed, 4,508 insertions(+), 4,076 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/51/398851/1


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic199134bf171ba778048f2461cce1d9a61ff5433
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Add user preferences

2017-11-13 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/391006 )

Change subject: Add user preferences
..

Add user preferences

Created a tab in user preferences for Wikispeech and added options for
voices. The options are read from the config.

Bug: T149302
Change-Id: I91f0956cffcd5cbf12297802b28abb65da33a76f
---
M Hooks.php
M extension.json
M i18n/en.json
M i18n/qqq.json
M modules/ext.wikispeech.js
M tests/qunit/ext.wikispeech.test.js
6 files changed, 94 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/06/391006/1

diff --git a/Hooks.php b/Hooks.php
index 7b7e011..6cf22b0 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -151,4 +151,42 @@
$wgWikispeechContentSelector;
return true;
}
+
+   /**
+* Add Wikispeech options to Special:Preferences.
+*
+* @param User $user current User object.
+* @param array &$preferences Preferences array.
+* @return bool true
+*/
+   static function onGetPreferences( $user, &$preferences ) {
+   self::addVoicePreferences( $preferences );
+   return true;
+   }
+
+   /**
+* Add preferences for selecting voices per language.
+*
+* @param array &$preferences Preferences array.
+*/
+   static function addVoicePreferences( &$preferences ) {
+   global $wgWikispeechVoices;
+   foreach ( $wgWikispeechVoices as $language => $voices ) {
+   $languageKey = 'wikispeechVoice' . ucfirst( $language );
+   $languageName = Language::getVariantname( $language );
+   $options = [ 'Default' => '' ];
+   foreach ( $voices as $voice ) {
+   $options[$voice] = $voice;
+   }
+   // Set the first voice as default.
+   $default = reset( $options );
+   $preferences[$languageKey] = [
+   'type' => 'select',
+   'label' => $languageName,
+   'section' => 'wikispeech/voice',
+   'options' => $options,
+   'default' => $default
+   ];
+   }
+   }
 }
diff --git a/extension.json b/extension.json
index b519ff8..cc12897 100644
--- a/extension.json
+++ b/extension.json
@@ -68,6 +68,9 @@
],
"ResourceLoaderGetConfigVars": [
"WikispeechHooks::onResourceLoaderGetConfigVars"
+   ],
+   "GetPreferences": [
+   "WikispeechHooks::onGetPreferences"
]
},
"config": {
@@ -115,7 +118,20 @@
"WikispeechSkipBackRewindsThreshold": 3.0,
"WikispeechHelpPage": "Help:Wikispeech",
"WikispeechFeedbackPage": "Wikispeech feedback",
-   "WikispeechContentSelector": "#mw-content-text"
+   "WikispeechContentSelector": "#mw-content-text",
+   "WikispeechVoices": {
+   "ar": [ "ar-nah-hsmm" ],
+   "en": [
+   "dfki-spike-hsmm",
+   "cmu-slt-flite"
+   ],
+   "sv": [ "stts_sv_nst-hsmm" ]
+   }
+   },
+   "DefaultUserOptions": {
+   "wikispeechVoiceAr": "",
+   "wikispeechVoiceEn": "",
+   "wikispeechVoiceSv": ""
},
"APIModules": {
"wikispeech": "ApiWikispeech"
diff --git a/i18n/en.json b/i18n/en.json
index a8d550e..b0b29f3 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -22,5 +22,7 @@
"apihelp-wikispeech-example-1": "Get segments for the Wikispeech 
extension. The tag sup is removed and so is div when 
it has the class toc. The tags h1 and h2 
break segments.",
"apihelp-wikispeech-example-2": "Get original HTML content and cleaned 
text.",
"apierror-wikispeech-removetagsinvalidjson": "removetags is 
not a valid JSON string.",
-   "apierror-wikispeech-removetagsinvalid": "removetags is not 
of a valid format. It must be an object with the values being booleans, strings 
or arrays of strings. To not remove any tags, set removetags to 
empty object, {}."
+   "apierror-wikispeech-removetagsinvalid": "removetags is not 
of a valid format. It must be an object with the values being booleans, strings 
or arrays of strings. To not remove any tags, set removetags to 
empty object, {}.",
+   "prefs-wikispeech": "Wikispeech",
+   "prefs-voice": "Voice"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 711245f..0878dcc 100644
--- a/i18n/qqq.json
+++ 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Recite selected text

2017-10-20 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/385373 )

Change subject: Recite selected text
..

Recite selected text

If any text is selected, only that text is recited. Playback starts
with the first selected word and stops with the last. Partially
selected words are read whole.

Since it proved quite tricky to combine reciting selections and
highlighting, highlighting is disabled when reciting selected text.

Audio elements are now created when utterances are created, rather
when the audio is loaded.

Reworked how request results are handled. Now, jqXHR is used to allow
adding callbacks to requests in progress. This also replaced the
utterance variable `waitingForResponse`.

Added ext.wikispeech.util for functions that are used in any module.

Fixed tokens' offsets, that were sometimes incorrectly calculated.

Bug: T133680
Change-Id: I6fb92bff5947735105f62819017dd6732e7730bd
---
M Hooks.php
M extension.json
M modules/ext.wikispeech.highlighter.js
M modules/ext.wikispeech.js
A modules/ext.wikispeech.util.js
M tests/qunit/ext.wikispeech.highlighter.test.js
M tests/qunit/ext.wikispeech.test.js
A tests/qunit/ext.wikispeech.util.test.js
8 files changed, 1,485 insertions(+), 125 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/73/385373/1

diff --git a/Hooks.php b/Hooks.php
index 7b7e011..fedde9b 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -24,7 +24,8 @@
$testModules['qunit']['ext.wikispeech.test'] = [
'scripts' => [
'tests/qunit/ext.wikispeech.test.js',
-   'tests/qunit/ext.wikispeech.highlighter.test.js'
+   
'tests/qunit/ext.wikispeech.highlighter.test.js',
+   'tests/qunit/ext.wikispeech.util.test.js'
],
'dependencies' => [
// Despite what it says at
diff --git a/extension.json b/extension.json
index 6f7cebb..9922def 100644
--- a/extension.json
+++ b/extension.json
@@ -29,7 +29,8 @@
"ext.wikispeech": {
"scripts": [
"ext.wikispeech.js",
-   "ext.wikispeech.highlighter.js"
+   "ext.wikispeech.highlighter.js",
+   "ext.wikispeech.util.js"
],
"styles": [
"ext.wikispeech.css"
diff --git a/modules/ext.wikispeech.highlighter.js 
b/modules/ext.wikispeech.highlighter.js
index cd3230a..c57425c 100644
--- a/modules/ext.wikispeech.highlighter.js
+++ b/modules/ext.wikispeech.highlighter.js
@@ -24,7 +24,7 @@
var textNodes, span;
 
textNodes = utterance.content.map( function ( item ) {
-   return self.getNodeForItem( item );
+   return mw.wikispeech.util.getNodeForItem( item 
);
} );
span = $( '' )
.addClass( self.utteranceHighlightingClass )
@@ -43,33 +43,6 @@
// highlighting.
this.textPath = utterance.content[ i ].path;
} );
-   };
-
-   /**
-* Find the text node from which a content item was created.
-*
-* The path property of the item is an XPath expression
-* that is used to traverse the DOM tree.
-*
-* @param {Object} item The item to find the text node for.
-* @return {TextNode} The text node associated with the item.
-*/
-
-   this.getNodeForItem = function ( item ) {
-   var node, result, contentSelector;
-
-   // The path should be unambiguous, so just get the first
-   // matching node.
-   contentSelector = mw.config.get( 
'wgWikispeechContentSelector' );
-   result = document.evaluate(
-   item.path,
-   $( contentSelector ).get( 0 ),
-   null,
-   XPathResult.FIRST_ORDERED_NODE_TYPE,
-   null
-   );
-   node = result.singleNodeValue;
-   return node;
};
 
/**
@@ -150,7 +123,7 @@
 */
 
this.highlightToken = function ( token ) {
-   var span, textNodes, utteranceOffset;
+   var span, textNodes, startOffset, endOffset;
 
span = 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Recite article title

2017-09-12 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/377416 )

Change subject: Recite article title
..

Recite article title

Added the article title as first utterance to include it in the
recitation.

Bug: T161097
Change-Id: I8fbac6314bcb2653d840190a45690ecd2a6b0cca
---
M includes/ApiWikispeech.php
M tests/phpunit/ApiWikispeechTest.php
2 files changed, 40 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/16/377416/1

diff --git a/includes/ApiWikispeech.php b/includes/ApiWikispeech.php
index 2862d26..cf2c130 100644
--- a/includes/ApiWikispeech.php
+++ b/includes/ApiWikispeech.php
@@ -18,8 +18,12 @@
if ( empty( $parameters['output'] ) ) {
$this->dieWithError( [ 'apierror-paramempty', 'output' 
] );
}
-   $pageContent = $this->getPageContent( $parameters['page'] );
+   $titleAndContent =
+   $this->getTitleAndContent( $parameters['page'] );
+   $displayTitle = $titleAndContent[ 0 ];
+   $pageContent = $titleAndContent[ 1 ];
$this->processPageContent(
+   $displayTitle,
$pageContent,
$parameters['output'],
json_decode( $parameters['removetags'], true ),
@@ -31,6 +35,7 @@
 * Process HTML and return it as original, cleaned and/or segmented.
 *
 * @since 0.0.1
+* @param string $displayTitle The title as displayed on the page.
 * @param string $pageContent The HTML string to process.
 * @param array $outputFormats Specifies what output formats to
 *  return. Can be any combination of: "originalcontent",
@@ -45,6 +50,7 @@
 *  * "segments": Cleaned and segmented HTML as an array.
 */
public function processPageContent(
+   $displayTitle,
$pageContent,
$outputFormats,
$removeTags,
@@ -77,6 +83,15 @@
if ( $cleanedText == null ) {
$cleanedText = $cleaner->cleanHtml( 
$pageContent );
}
+   // Add the title as a separate utterance.
+   array_unshift( $cleanedText, new SegmentBreak() );
+   array_unshift(
+   $cleanedText,
+   new CleanedText(
+   $displayTitle,
+   '//h1[@id="firstHeading"]/text()'
+   )
+   );
$segments = $segmenter->segmentSentences( $cleanedText 
);
$values['segments'] = $segments;
}
@@ -89,15 +104,16 @@
}
 
/**
-* Get the parsed content of the named page.
+* Get the title and parsed content of the named page.
 *
 * @since 0.0.1
 * @param string $pageTitle The title of the page to get content
 *  from.
-* @return string The parsed content for the page given in the
-*  request to the Wikispeech API.
+* @return array An array containing the displayed title and the
+*  parsed content for the page given in the request to the
+*  Wikispeech API.
 */
-   private function getPageContent( $pageTitle ) {
+   private function getTitleAndContent( $pageTitle ) {
// Get and validate Title
$title = Title::newFromText( $pageTitle );
if ( !$title || $title->isExternal() ) {
@@ -109,6 +125,7 @@
if ( !$title->canExist() ) {
$this->dieWithError( 'apierror-pagecannotexist' );
}
+   $displayTitle = $title->getTitleValue()->getText();
 
// Parse latest revision, using parser cache
$page = WikiPage::factory( $title );
@@ -118,8 +135,8 @@
$this->dieWithError( [ 'apierror-nosuchrevid', 
$page->getLatest() ] );
}
 
-   // Return HTML
-   return $pout->getText();
+   // Return title and HTML.
+   return [ $title, $pout->getText() ];
}
 
/**
diff --git a/tests/phpunit/ApiWikispeechTest.php 
b/tests/phpunit/ApiWikispeechTest.php
index 9da49e9..59baa8d 100644
--- a/tests/phpunit/ApiWikispeechTest.php
+++ b/tests/phpunit/ApiWikispeechTest.php
@@ -11,7 +11,7 @@
 require_once __DIR__ . '/../../includes/ApiWikispeech.php';
 require_once 'Util.php';
 
-define( 'TITLE', 'Talk:Page' );
+define( 'TITLE', 'Talk:Test_Page' );
 
 class ApiWikispeechTest extends ApiTestCase {
public function addDBDataOnce() {
@@ -69,7 +69,20 @@
  

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Validate value of API parameter "removetags"

2017-09-07 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/376493 )

Change subject: Validate value of API parameter "removetags"
..

Validate value of API parameter "removetags"

Checks if the parameter is a valid JSON string and if the parsed
variable is of the correct format.

Bug: T172523
Change-Id: Ib1093eabd4e03fdbe4df272f70e268a93c9fff36
---
M i18n/en.json
M i18n/qqq.json
M includes/ApiWikispeech.php
M tests/phpunit/ApiWikispeechTest.php
4 files changed, 126 insertions(+), 3 deletions(-)


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

diff --git a/i18n/en.json b/i18n/en.json
index fb98d2b..7f8d736 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -17,5 +17,7 @@
"apihelp-wikispeech-param-removetags": "The tags that should be removed 
completely during cleaning, as a JSON object of the format:\n{\n  
\"tagName1\": true,\n  \"tagName2\": \"cssClass\"\n}\nwhere 
tagName1 is always removed and tagName2 is only 
removed if it also has the CSS class cssClass.",
"apihelp-wikispeech-param-segmentbreakingtags": "The tag names for tags 
that should add segment breaks.",
"apihelp-wikispeech-example-1": "Get segments for the Wikispeech 
extension. The tag sup is removed and so is div when 
it has the class toc. The tags h1 and h2 
break segments.",
-   "apihelp-wikispeech-example-2": "Get original HTML content and cleaned 
text."
+   "apihelp-wikispeech-example-2": "Get original HTML content and cleaned 
text.",
+   "apierror-wikispeech-removetagsinvalidjson": "removetags is 
not a valid JSON string.",
+   "apierror-wikispeech-removetagsinvalid": "removetags is not 
of a valid format. It should be an object with the values being boolean, string 
or array of strings."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 17b1b58..80a60a9 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -17,5 +17,7 @@
"apihelp-wikispeech-param-removetags": 
"{{doc-apihelp-param|wikispeech|removetags}}",
"apihelp-wikispeech-param-segmentbreakingtags": 
"{{doc-apihelp-param|wikispeech|segmentbreakingtags}}",
"apihelp-wikispeech-example-1": "{{doc-apihelp-example|wikispeech}}",
-   "apihelp-wikispeech-example-2": "{{doc-apihelp-example|wikispeech}}"
+   "apihelp-wikispeech-example-2": "{{doc-apihelp-example|wikispeech}}",
+   "apierror-wikispeech-removetagsinvalidjson": "{{doc-apierror}}",
+   "apierror-wikispeech-removetagsinvalid": "{{doc-apierror}}"
 }
diff --git a/includes/ApiWikispeech.php b/includes/ApiWikispeech.php
index 2862d26..1a9d326 100644
--- a/includes/ApiWikispeech.php
+++ b/includes/ApiWikispeech.php
@@ -19,15 +19,69 @@
$this->dieWithError( [ 'apierror-paramempty', 'output' 
] );
}
$pageContent = $this->getPageContent( $parameters['page'] );
+$result = FormatJson::parse(
+$parameters['removetags'],
+FormatJson::FORCE_ASSOC
+);
+if ( !$result->isGood() ) {
+$this->dieWithError( [
+'apierror-wikispeech-removetagsinvalidjson',
+'' ]
+);
+}
+$removeTags = $result->getValue();
+if ( !$this->isValidRemoveTags( $removeTags ) ) {
+$this->dieWithError(
+[ 'apierror-wikispeech-removetagsinvalid', '' ]
+);
+}
$this->processPageContent(
$pageContent,
$parameters['output'],
-   json_decode( $parameters['removetags'], true ),
+   $removeTags,
$parameters['segmentbreakingtags']
);
}
 
/**
+* Tests if a variable is valid as "remove tags".
+ *
+ * The variable should be an associative array. Keys should be
+ * strings and values should be either booleans, strings or
+ * sequential arrays containing strings.
+*
+* @since 0.0.1
+* @param mixed $removeTags The variable to test.
+* @return bool true if $removeTags is valid, else false.
+*/
+
+   public function isValidRemoveTags( $removeTags ) {
+if ( !is_array( $removeTags ) ) {
+return false;
+}
+foreach ( $removeTags as $tagName => $rule ) {
+if ( !is_string( $tagName ) ) {
+// A key isn't a string.
+return false;
+}
+if ( is_array( $rule ) ) {
+// Rule is a list of class names.
+foreach ( $rule as $className ) {
+if ( !is_string( $className ) ) {
+// Only strings are valid if the rule is
+// an array.
+return false;
+}
+}
+} 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Rename API

2017-08-25 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/373888 )

Change subject: Rename API
..

Rename API

Renamed API classes and files to match other APIs.

Bug: T172520
Change-Id: I7d3ff337c80ea45a6c14f3d070733df43e9f10cf
---
M extension.json
R includes/ApiWikispeech.php
R tests/phpunit/ApiWikispeechTest.php
3 files changed, 5 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/88/373888/1

diff --git a/extension.json b/extension.json
index f080a3b..6f7cebb 100644
--- a/extension.json
+++ b/extension.json
@@ -23,7 +23,7 @@
"Cleaner": "includes/Cleaner.php",
"HtmlGenerator": "includes/HtmlGenerator.php",
"Segmenter": "includes/Segmenter.php",
-   "WikispeechApi": "includes/WikispeechApi.php"
+   "ApiWikispeech": "includes/ApiWikispeech.php"
},
"ResourceModules": {
"ext.wikispeech": {
@@ -116,6 +116,6 @@
"WikispeechContentSelector": "#mw-content-text"
},
"APIModules": {
-   "wikispeech": "WikispeechApi"
+   "wikispeech": "ApiWikispeech"
}
 }
diff --git a/includes/WikispeechApi.php b/includes/ApiWikispeech.php
similarity index 98%
rename from includes/WikispeechApi.php
rename to includes/ApiWikispeech.php
index 216c63e..e2b25ce 100644
--- a/includes/WikispeechApi.php
+++ b/includes/ApiWikispeech.php
@@ -6,7 +6,7 @@
  * @license GPL-2.0+
  */
 
-class WikispeechApi extends ApiBase {
+class ApiWikispeech extends ApiBase {
 
/**
 * Execute an API request.
diff --git a/tests/phpunit/WikispeechApiTest.php 
b/tests/phpunit/ApiWikispeechTest.php
similarity index 94%
rename from tests/phpunit/WikispeechApiTest.php
rename to tests/phpunit/ApiWikispeechTest.php
index 41da705..9da49e9 100644
--- a/tests/phpunit/WikispeechApiTest.php
+++ b/tests/phpunit/ApiWikispeechTest.php
@@ -8,12 +8,12 @@
  * @license GPL-2.0+
  */
 
-require_once __DIR__ . '/../../includes/WikispeechApi.php';
+require_once __DIR__ . '/../../includes/ApiWikispeech.php';
 require_once 'Util.php';
 
 define( 'TITLE', 'Talk:Page' );
 
-class WikispeechApiTest extends ApiTestCase {
+class ApiWikispeechTest extends ApiTestCase {
public function addDBDataOnce() {
$content = "Text ''italic'' '''bold'''";
$this->addPage( TITLE, $content );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7d3ff337c80ea45a6c14f3d070733df43e9f10cf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Add variable for content wrapper element

2017-06-13 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358587 )

Change subject: Add variable for content wrapper element
..

Add variable for content wrapper element

Added variable for what element to use as root when evaluating XPath
expressions. This was needed as a div ()
wraps the content since If4eb5bf7.

Bug: T164822
Change-Id: I5668f4215860fede252125e1aac766f92056e4a8
---
M Hooks.php
M extension.json
M modules/ext.wikispeech.js
M tests/qunit/ext.wikispeech.test.js
4 files changed, 32 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/87/358587/1

diff --git a/Hooks.php b/Hooks.php
index 8b3b93f..7b9b5e8 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -125,6 +125,9 @@
global $wgWikispeechFeedbackPage;
$vars['wgWikispeechFeedbackPage'] =
$wgWikispeechFeedbackPage;
+   global $wgWikispeechContentWrapperSelector;
+   $vars['wgWikispeechContentWrapperSelector'] =
+   $wgWikispeechContentWrapperSelector;
return true;
}
 }
diff --git a/extension.json b/extension.json
index 89bb41a..806b9d3 100644
--- a/extension.json
+++ b/extension.json
@@ -104,6 +104,7 @@
},
"WikispeechSkipBackRewindsThreshold": 3.0,
"WikispeechHelpPage": "Help:Wikispeech",
-   "WikispeechFeedbackPage": "Wikispeech feedback"
+   "WikispeechFeedbackPage": "Wikispeech feedback",
+   "WikispeechContentWrapperSelector": ".mw-parser-output"
}
 }
diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index f36c9b6..776d646 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -297,14 +297,16 @@
 */
 
this.getNodeForTextElement = function ( textElement ) {
-   var path, node, result;
+   var path, node, result, contentWrapperSelector;
 
path = textElement.getAttribute( 'path' );
+   contentWrapperSelector =
+   mw.config.get( 
'wgWikispeechContentWrapperSelector' );
// The path should be unambiguous, so just get the first
// matching node.
result = document.evaluate(
path,
-   $( '#mw-content-text' ).get( 0 ),
+   $( contentWrapperSelector ).get( 0 ),
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
diff --git a/tests/qunit/ext.wikispeech.test.js 
b/tests/qunit/ext.wikispeech.test.js
index 924b05f..0900ffa 100644
--- a/tests/qunit/ext.wikispeech.test.js
+++ b/tests/qunit/ext.wikispeech.test.js
@@ -1,5 +1,5 @@
 ( function ( mw, $ ) {
-   var wikispeech, server;
+   var wikispeech, server, contentWrapperClass, contentWrapperSelector;
 
QUnit.module( 'ext.wikispeech', {
setup: function () {
@@ -52,6 +52,12 @@
mw.config.set(
'wgWikispeechServerUrl',
'http://server.url/wikispeech/'
+   );
+   contentWrapperClass = 'mw-parser-output';
+   contentWrapperSelector = '.mw-parser-output';
+   mw.config.set(
+   'wgWikispeechContentWrapperSelector',
+   contentWrapperSelector
);
},
teardown: function () {
@@ -963,7 +969,7 @@
assert.expect( 1 );
$( '#qunit-fixture' ).append(
$( '' )
-   .attr( 'id', 'mw-content-text' )
+   .addClass( contentWrapperClass )
.text( 'An utterance.' )
);
$( '#utterance-0' ).append(
@@ -979,7 +985,7 @@
wikispeech.highlightUtterance( $( '#utterance-0' ) );
 
assert.strictEqual(
-   $( '#mw-content-text' ).prop( 'innerHTML' ),
+   $( contentWrapperSelector ).prop( 'innerHTML' ),
'An 
utterance.'
);
} );
@@ -988,7 +994,7 @@
assert.expect( 1 );
$( '#qunit-fixture' ).append(
$( '' )
-   .attr( 'id', 'mw-content-text' )
+   .addClass( contentWrapperClass )
.text( 'Utterance one. Utterance two. Utterance 
three.' )
);
$( '#utterance-0' ).append(
@@ -1004,7 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Add API for segmenting text

2017-06-12 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358378 )

Change subject: Add API for segmenting text
..

Add API for segmenting text

The API will initially be used to clean and segment HTML. It can also
respond with only cleaned text or the original output. This can be
used for debugging or outside Wikispeech.

Cleaner and Segmenter is now instantiated, since there were a few
variables that was passed through multiple functions.

The config variable for removed tags now takes boolean or string as
values (and not objects), as it's currently only allows CSS class to
be specified.

Change-Id: I78db6c6a64e9d04e6907d2eb96af47ca368cf82e
---
M Hooks.php
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/Cleaner.php
M includes/Segmenter.php
A includes/WikispeechApi.php
M tests/phpunit/CleanerTest.php
M tests/phpunit/SegmenterTest.php
A tests/phpunit/WikispeechApiTest.php
10 files changed, 433 insertions(+), 125 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/78/358378/1

diff --git a/Hooks.php b/Hooks.php
index 8b3b93f..54265a8 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -54,12 +54,19 @@
'Wikispeech',
'HTML from onParserAfterTidy(): ' . $text
);
-   $cleanedContents = Cleaner::cleanHtml( $text );
+   global $wgWikispeechRemoveTags;
+   global $wgWikispeechSegmentBreakingTags;
+   $cleaner = new Cleaner(
+   $wgWikispeechRemoveTags,
+   $wgWikispeechSegmentBreakingTags
+   );
+   $cleanedContents = $cleaner->cleanHtml( $text );
wfDebugLog(
'Wikispeech',
'Cleaned text: ' . var_export( 
$cleanedContents, true )
);
-   $utterances = Segmenter::segmentSentences( 
$cleanedContents );
+   $segmenter = new Segmenter();
+   $utterances = $segmenter->segmentSentences( 
$cleanedContents );
wfDebugLog(
'Wikispeech',
'Utterances: ' . var_export( $utterances, true )
diff --git a/extension.json b/extension.json
index dd8a69d..d0a7867 100644
--- a/extension.json
+++ b/extension.json
@@ -22,7 +22,8 @@
"SegmentBreak": "includes/CleanedContent.php",
"Cleaner": "includes/Cleaner.php",
"HtmlGenerator": "includes/HtmlGenerator.php",
-   "Segmenter": "includes/Segmenter.php"
+   "Segmenter": "includes/Segmenter.php",
+   "WikispeechApi": "includes/WikispeechApi.php"
},
"ResourceModules": {
"ext.wikispeech": {
@@ -87,7 +88,7 @@
"h6",
"p",
"br",
-"li"
+   "li"
],
"WikispeechNamespaces": [ "NS_MAIN" ],
"WikispeechKeyboardShortcuts": {
@@ -115,5 +116,8 @@
"WikispeechSkipBackRewindsThreshold": 3.0,
"WikispeechHelpPage": "Help:Wikispeech",
"WikispeechFeedbackPage": "Wikispeech feedback"
+   },
+   "APIModules": {
+   "wikispeech": "WikispeechApi"
}
 }
diff --git a/i18n/en.json b/i18n/en.json
index 39bf852..4db4712 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -7,5 +7,18 @@
"wikispeech": "Wikispeech",
"wikispeech-desc": "A text-to-speech tool to make Wikimedia's projects 
more accessible for people that for different reasons have difficulties 
reading.",
"special-wikispeech-intro": "Wikispeech",
-   "special-wikispeech-title": "Special page introduction."
-}
\ No newline at end of file
+   "special-wikispeech-title": "Special page introduction.",
+   "apihelp-wikispeech-description": "Process the HTML content.",
+   "apihelp-wikispeech-param-page": "The page to process.",
+   "apihelp-wikispeech-param-output": "The formats of the output, can be a 
combination of the following:
+* ''originalcontent'': The original HTML of the page.
+* ''cleanedtext'': The page content with HTML tags removed.
+* ''segments'': The page content segmented into sentence.",
+   "apihelp-wikispeech-param-removetags": "The tags that should be removed 
completely, as a JSON object of the format:
+{
+  \"tagName1\": \"true\",
+  \"tagName2\": \"cssClass\"
+}
+where tagName1 is always removed and tagName2 is 
removed if it also has the CSS class cssClass.",
+   "apihelp-wikispeech-param-segmentbreakingtags": "The tags that should 
add segment breaks."
+}
diff --git a/i18n/qqq.json 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Segment by tags

2017-06-02 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/356827 )

Change subject: Segment by tags
..

Segment by tags

Cleaned text is now split by certain tags. These are specified in by
the config variable WikispeechSegmentBreakingTags. By default, these
tags are h*, p, br and li. Removed ol and ul from
WikispeechRemoveTags, since lists are now recited reasonably well.

During cleaning, SegmentBreak objects are added where the specified
tags are encountered (the tags themselves are still removed). During
segmenting, when a SegmentBreak is encountered, a new segment is
created.

Renamed what "things" (CleanedText and SegmentBreak) in content are
called to "item".

Change-Id: I688f20f6e4a662efb4a74eb2e3e94996b231445f
---
M extension.json
M includes/CleanedContent.php
M includes/Cleaner.php
M includes/HtmlGenerator.php
M includes/Segmenter.php
M modules/ext.wikispeech.js
M tests/phpunit/CleanerTest.php
M tests/phpunit/SegmenterTest.php
8 files changed, 176 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/27/356827/1

diff --git a/extension.json b/extension.json
index 89bb41a..b6ac2f0 100644
--- a/extension.json
+++ b/extension.json
@@ -19,6 +19,7 @@
"SpecialWikispeech": "specials/SpecialWikispeech.php",
"WikispeechHooks": "Hooks.php",
"CleanedText": "includes/CleanedContent.php",
+   "SegmentBreak": "includes/CleanedContent.php",
"Cleaner": "includes/Cleaner.php",
"HtmlGenerator": "includes/HtmlGenerator.php",
"Segmenter": "includes/Segmenter.php"
@@ -79,6 +80,16 @@
"ul": true,
"ol": true
},
+   "WikispeechSegmentBreakingTags": [
+   "h1",
+   "h2",
+   "h3",
+   "h4",
+   "h5",
+   "h6",
+   "p",
+   "br"
+   ],
"WikispeechNamespaces": [ "NS_MAIN" ],
"WikispeechKeyboardShortcuts": {
"playStop": {
diff --git a/includes/CleanedContent.php b/includes/CleanedContent.php
index 5042574..5f02a25 100644
--- a/includes/CleanedContent.php
+++ b/includes/CleanedContent.php
@@ -55,3 +55,6 @@
return $element;
}
 }
+
+class SegmentBreak {
+}
diff --git a/includes/Cleaner.php b/includes/Cleaner.php
index ab58f48..ee9679b 100644
--- a/includes/Cleaner.php
+++ b/includes/Cleaner.php
@@ -25,12 +25,17 @@
// Only add elements below the dummy element. These are the
// elements from the original HTML.
$top = $xpath->evaluate( '/meta/dummy' )->item( 0 );
-   $cleanedContents = [];
+   $cleanedContent = [];
self::addContent(
-   $cleanedContents,
+   $cleanedContent,
$top
);
-   return $cleanedContents;
+   if ( self::lastElement( $cleanedContent ) instanceof 
SegmentBreak ) {
+   // Remove any segment break at the end of the array, 
since
+   // they won't do anything.
+   array_pop( $cleanedContent );
+   }
+   return $cleanedContent;
}
 
/**
@@ -60,12 +65,14 @@
}
 
/**
-* Recursively add content as `CleanedText`s.
+* Recursively add items to the cleaned content.
 *
-* Goes through all the child nodes of $node and adds their content 
text.
+* Goes through all the child nodes of $node and adds their
+* content text. Adds segment breaks for appropriate tags.
 *
 * @since 0.0.1
-* @param array $content The resulting array of `CleanedText`s.
+* @param array $content The resulting array of `CleanedText`s
+*  and `SegmentBreak`s.
 * @param DOMNode $node The top node to add from.
 */
 
@@ -73,11 +80,24 @@
&$content,
$node
) {
+   global $wgWikispeechSegmentBreakingTags;
if ( !self::matchesRemove( $node ) ) {
foreach ( $node->childNodes as $child ) {
+   if (
+   !self::lastElement( $content ) 
instanceof SegmentBreak &&
+   in_array(
+   $child->nodeName,
+   $wgWikispeechSegmentBreakingTags
+   )
+   ) {
+   // Add segment breaks for start tags 

[MediaWiki-commits] [Gerrit] integration/config[master]: Whitelist Eugene233 <agboreug...@gmail.com>

2017-05-17 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/354098 )

Change subject: Whitelist Eugene233 
..

Whitelist Eugene233 

He is a volunteer that will be working on the Wikispeeh project.

Change-Id: I377622933825a2f92895754a0e412dba834303cf
---
M zuul/layout.yaml
1 file changed, 1 insertion(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/integration/config 
refs/changes/98/354098/1

diff --git a/zuul/layout.yaml b/zuul/layout.yaml
index 9dadf62..4e993ed 100644
--- a/zuul/layout.yaml
+++ b/zuul/layout.yaml
@@ -53,6 +53,7 @@
 | alangiderick@gmail\.com
 | cblair91@gmail\.com
 | admin@glados\.cc
+| agboreugene@gmail\.com
 | alexsh@mail2000\.com\.tw
 | amir\.aharoni@mail\.huji\.ac\.il
 | andreas\.burmeister@student\.hpi\.de

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I377622933825a2f92895754a0e412dba834303cf
Gerrit-PatchSet: 1
Gerrit-Project: integration/config
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Add feedback button

2017-05-03 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/351610 )

Change subject: Add feedback button
..

Add feedback button

Added a button in the player that takes the user to a feedback page,
if specified in the config. Refactored and reused logic for the help
button for this.

Bug: T162361
Change-Id: I49cf2498b4b62a46a6760c1cbf88b9a9c62058af
---
M Hooks.php
M extension.json
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M tests/qunit/ext.wikispeech.test.js
5 files changed, 101 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/10/351610/1

diff --git a/Hooks.php b/Hooks.php
index b5c0038..8b3b93f 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -122,6 +122,9 @@
global $wgWikispeechHelpPage;
$vars['wgWikispeechHelpPage'] =
$wgWikispeechHelpPage;
+   global $wgWikispeechFeedbackPage;
+   $vars['wgWikispeechFeedbackPage'] =
+   $wgWikispeechFeedbackPage;
return true;
}
 }
diff --git a/extension.json b/extension.json
index a565827..db9ca0b 100644
--- a/extension.json
+++ b/extension.json
@@ -103,6 +103,7 @@
}
},
"WikispeechSkipBackRewindsThreshold": 3.0,
-   "WikispeechHelpPage": "Help:Wikispeech"
+   "WikispeechHelpPage": "Help:Wikispeech",
+   "WikispeechFeedbackPage": "Feedback"
}
 }
diff --git a/modules/ext.wikispeech.css b/modules/ext.wikispeech.css
index c9777c0..3c145b3 100644
--- a/modules/ext.wikispeech.css
+++ b/modules/ext.wikispeech.css
@@ -42,6 +42,11 @@
content: '\f128';
 }
 
+.ext-wikispeech-feedback:after {
+   font-family: 'Fontawesome';
+   content: '\f075';
+}
+
 .ext-wikispeech-control-panel {
position: fixed;
left: 0;
diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index cced6fd..4865d92 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -13,9 +13,7 @@
 */
 
this.addControlPanel = function () {
-   var $controlPanel, helpPage, helpPagePath;
-
-   $controlPanel = $( '' )
+   $( '' )
.attr( 'id', 'ext-wikispeech-control-panel' )
.addClass( 'ext-wikispeech-control-panel' )
.appendTo( '#content' );
@@ -41,22 +39,24 @@
'ext-wikispeech-skip-ahead-sentence',
self.skipAheadUtterance
);
-   helpPage = mw.config.get( 'wgWikispeechHelpPage' );
-   if ( helpPage ) {
-   // Only add button for help page if it is 
specified in
-   // the config.
+   self.addLinkButton(
+   'ext-wikispeech-help',
+   'wgWikispeechHelpPage'
+   );
+   self.addLinkButton(
+   'ext-wikispeech-feedback',
+   'wgWikispeechFeedbackPage'
+   );
+   if (
+   $( '.ext-wikispeech-help, 
ext-wikispeech-feedback' ).length
+   ) {
+   // Add divider if there are any non-control 
buttons.
$( '' )
.addClass( 'ext-wikispeech-divider' )
-   .appendTo( $controlPanel );
-   helpPagePath = mw.config.get( 'wgArticlePath' )
-   .replace( '$1', helpPage );
-   $( '' )
-   .attr( 'href', helpPagePath )
-   .append(
-   $( '' )
-   .addClass( 
'ext-wikispeech-help' )
-   )
-   .appendTo( 
'#ext-wikispeech-control-panel' );
+   .insertBefore(
+   $( '.ext-wikispeech-help, 
ext-wikispeech-feedback' )
+   .first()
+   );
}
};
 
@@ -130,6 +130,36 @@
};
 
/**
+   * Add a button that takes the user to another page.
+   *
+   * The button gets the link destination from a supplied
+   * config variable. If the 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Highlight recited word

2017-05-03 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/351576 )

Change subject: Highlight recited word
..

Highlight recited word

Span elements are added around the text nodes in the page HTML that
represent the token being recited. Timeouts are used to move the
highlighting when the next token starts. While this is not very
accurate over longer time, it seems to work here as the durations of
tokens aren't very long and the timeout is updated each token.

Token elements were updated with information used to find the
corresponding text in the page HTML. This includes text nodes, through
text elements, and offset for where in the text nodes the token starts
and ends.

Abstracted the logic for wrapping utterances, that was implemented
previously, to be reusable for tokens too.

Broke out the logic for highlighting into a separate module, with
corresponding test module.

Changed the default colours for highlighting to solid, rather than
semitransparent; this didn't work when there were multiple,
overlapping highlightings.

Change-Id: I097b969ce00274b5f8d16d98c9d7ffd8c12f4fe1
Bug: T148623
---
M Hooks.php
M extension.json
M modules/ext.wikispeech.css
A modules/ext.wikispeech.highlighter.js
M modules/ext.wikispeech.js
A tests/qunit/ext.wikispeech.highlighter.test.js
M tests/qunit/ext.wikispeech.test.js
7 files changed, 1,499 insertions(+), 599 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/76/351576/1

diff --git a/Hooks.php b/Hooks.php
index b5c0038..475de42 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -22,15 +22,20 @@
array &$testModules,
ResourceLoader &$resourceLoader
) {
-   $testModules['qunit']['ext.wikispeech.tests'] = [
+   $testModules['qunit']['ext.wikispeech.test'] = [
'scripts' => [
-   'tests/qunit/ext.wikispeech.test.js'
+   'tests/qunit/ext.wikispeech.test.js',
+   'tests/qunit/ext.wikispeech.highlighter.test.js'
],
'dependencies' => [
+   // Despite what it says at
+   // 
https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules,
+   // adding 'ext.wikispeech.highlighter' isn't 
needed
+   // and in fact breaks the testing.
'ext.wikispeech'
],
'localBasePath' => __DIR__,
-   'remoteExtPath' => 'Wikispeech',
+   'remoteExtPath' => 'Wikispeech'
];
return true;
}
@@ -107,7 +112,10 @@
OutputPage &$out,
Skin &$skin
) {
-   $out->addModules( [ 'ext.wikispeech' ] );
+   $out->addModules( [
+   'ext.wikispeech',
+   'ext.wikispeech.highlighter'
+   ] );
}
 
public static function onResourceLoaderGetConfigVars( &$vars ) {
diff --git a/extension.json b/extension.json
index a565827..f6d4662 100644
--- a/extension.json
+++ b/extension.json
@@ -26,7 +26,8 @@
"ResourceModules": {
"ext.wikispeech": {
"scripts": [
-   "ext.wikispeech.js"
+   "ext.wikispeech.js",
+   "ext.wikispeech.highlighter.js"
],
"styles": [
"ext.wikispeech.css"
diff --git a/modules/ext.wikispeech.css b/modules/ext.wikispeech.css
index c9777c0..dc800a8 100644
--- a/modules/ext.wikispeech.css
+++ b/modules/ext.wikispeech.css
@@ -53,6 +53,9 @@
 }
 
 .ext-wikispeech-highlight-sentence {
-   background-color: rgb( 0, 200, 0 );
-   background-color: rgba( 0, 200, 0, 0.5 );
+   background-color: rgb( 200, 170, 255 );
+}
+
+.ext-wikispeech-highlight-word {
+   background-color: rgb( 255, 200, 140 );
 }
diff --git a/modules/ext.wikispeech.highlighter.js 
b/modules/ext.wikispeech.highlighter.js
new file mode 100644
index 000..79976a3
--- /dev/null
+++ b/modules/ext.wikispeech.highlighter.js
@@ -0,0 +1,263 @@
+( function ( mw, $ ) {
+   function Highlighter() {
+   var self = this;
+   self.highlightTokenTimer = null;
+
+   /**
+* Highlight text associated with an utterance.
+*
+* Adds highlight spans to the text nodes from which the
+* tokens of $utterance were created. For first and last node,
+* it's possible that only part of the text is highlighted,
+* since they may contain start/end of 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Hotfix for c40dbee

2017-04-28 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/350838 )

Change subject: Hotfix for c40dbee
..

Hotfix for c40dbee

Implemented some feedback that was given after the merge:
* Changed back to using POST instead of GET.
* Changed callback functions from deprecated ones.

Change-Id: I2fd4a09b8b79df51130435e421aae58d0bfc97b4
---
M modules/ext.wikispeech.js
M tests/qunit/ext.wikispeech.test.js
2 files changed, 12 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/38/350838/1

diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index e828851..298e2df 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -780,6 +780,7 @@
var serverUrl = mw.config.get( 'wgWikispeechServerUrl' 
);
$.ajax( {
url: serverUrl,
+   method: 'POST',
data: {
// jscs:disable 
requireCamelCaseOrUpperCaseIdentifiers
lang: mw.config.get( 
'wgPageContentLanguage' ),
@@ -789,23 +790,23 @@
},
dataType: 'json',
beforeSend: function ( jqXHR, settings ) {
-   mw.log( 'Sending request:', 
settings.url );
+   mw.log( 'Sending request: ' + 
settings.url + '?' + settings.data );
$utterance.prop( 'waitingForResponse', 
true );
-   },
-   success: function ( data ) {
+   }
+   } )
+   .done( function ( data ) {
mw.log( 'Response received:', data );
callback( data );
-   },
-   error: function ( jqXHR, textStatus ) {
+   } )
+   .fail( function ( jqXHR, textStatus ) {
mw.log.warn(
'Request failed, error type "' 
+ textStatus + '":',
this.url
);
-   },
-   complete: function () {
+   } )
+   .always( function () {
$utterance.prop( 'waitingForResponse', 
false );
-   }
-   } );
+   } );
};
 
/**
diff --git a/tests/qunit/ext.wikispeech.test.js 
b/tests/qunit/ext.wikispeech.test.js
index 147a25c..21c13aa 100644
--- a/tests/qunit/ext.wikispeech.test.js
+++ b/tests/qunit/ext.wikispeech.test.js
@@ -166,8 +166,8 @@
 
assert.strictEqual( wikispeech.requestTts.called, true );
assert.strictEqual(
-   server.requests[ 0 ].url,
-   
'http://server.url/wikispeech/?lang=en_type=text=An%20utterance.'
+   server.requests[ 0 ].requestBody,
+   'lang=en_type=text=An+utterance.'
);
} );
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2fd4a09b8b79df51130435e421aae58d0bfc97b4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Use jQuery.ajax() for HTTP requests

2017-04-21 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/349423 )

Change subject: Use jQuery.ajax() for HTTP requests
..

Use jQuery.ajax() for HTTP requests

Modified requestTts() to use jQuery.ajax()
(http://api.jquery.com/jQuery.ajax/). Added some logic for handling
errors. Removed the `requested` property for utterances; the audio
element is used instead, to check if audio has been loaded.

Change-Id: Ifc76c8326cd276212562697b33672e3a12a3f46d
---
M modules/ext.wikispeech.js
M tests/qunit/ext.wikispeech.test.js
2 files changed, 58 insertions(+), 35 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/23/349423/1

diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index 62c9ae0..10f5761 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -686,9 +686,9 @@
this.prepareUtterance = function ( $utterance ) {
var $audio, $nextUtterance;
 
-   if ( !$utterance.prop( 'requested' ) ) {
-   // Only load audio for an utterance if we 
haven't
-   // already sent a request for it.
+   if ( $utterance.children( 'audio' ).length === 0 ) {
+   // Only load audio for an utterance if it isn't
+   // already loaded.
self.loadAudio( $utterance );
$nextUtterance = self.getNextUtterance( 
$utterance );
$audio = $utterance.children( 'audio' );
@@ -739,14 +739,13 @@
}
}
).text();
-   self.requestTts( text, function ( response ) {
+   self.requestTts( text, $utterance, function ( response 
) {
audioUrl = response.audio;
mw.log( 'Setting url for ' + $utterance.attr( 
'id' ) + ': ' +
audioUrl );
$audio.attr( 'src', audioUrl );
self.addTokenElements( $utterance, 
response.tokens );
} );
-   $utterance.prop( 'requested', true );
};
 
/**
@@ -762,35 +761,40 @@
 *
 * @param {string} text The utterance string to send in the
 *  request.
+* @param {jQuery} $uterance The utterance for this request.
 * @param {Function} callback Function to be called when a
 *  response is received.
 */
 
-   this.requestTts = function ( text, callback ) {
-   var request, parameters, serverUrl, response;
-
-   request = new XMLHttpRequest();
-   request.overrideMimeType( 'text/json' );
-   serverUrl = mw.config.get( 'wgWikispeechServerUrl' );
-   request.open( 'POST', serverUrl, true );
-   request.setRequestHeader(
-   'Content-type',
-   'application/x-www-form-urlencoded'
-   );
-   parameters = $.param( {
-   // jscs:disable 
requireCamelCaseOrUpperCaseIdentifiers
-   lang: mw.config.get( 'wgPageContentLanguage' ),
-   input_type: 'text',
-   input: text
-   // jscs:enable 
requireCamelCaseOrUpperCaseIdentifiers
+   this.requestTts = function ( text, $utterance, callback ) {
+   var serverUrl = mw.config.get( 'wgWikispeechServerUrl' 
);
+   $.ajax( {
+   url: serverUrl,
+   data: {
+   // jscs:disable 
requireCamelCaseOrUpperCaseIdentifiers
+   lang: mw.config.get( 
'wgPageContentLanguage' ),
+   input_type: 'text',
+   input: text
+   // jscs:enable 
requireCamelCaseOrUpperCaseIdentifiers
+   },
+   dataType: 'json',
+   beforeSend: function ( jqXHR, settings ) {
+   mw.log( 'Sending request:', 
settings.url );
+   },
+   success: function ( data ) {
+   mw.log( 'Response received:', data );
+   

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Add help button in player GUI

2017-04-11 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/347609 )

Change subject: Add help button in player GUI
..

Add help button in player GUI

The button takes the user to a help page for Wikispeech. The page is
defined by the config variable `WikispeechHelpPage`, "Wikispeech_help"
by default. The button only appears if the variable is set.

Changed button tests to use stubs instead of spies, as the function
for the help button changes redirected the browser.

Bug: T151886
Change-Id: Iba29fcb7f8102bfa3f82ca62794ed6ea4cff5921
---
M Hooks.php
M extension.json
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M tests/qunit/ext.wikispeech.test.js
5 files changed, 84 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/09/347609/1

diff --git a/Hooks.php b/Hooks.php
index 2fa1092..b5c0038 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -119,6 +119,9 @@
global $wgWikispeechSkipBackRewindsThreshold;
$vars['wgWikispeechSkipBackRewindsThreshold'] =
$wgWikispeechSkipBackRewindsThreshold;
+   global $wgWikispeechHelpPage;
+   $vars['wgWikispeechHelpPage'] =
+   $wgWikispeechHelpPage;
return true;
}
 }
diff --git a/extension.json b/extension.json
index 8b1b9d1..499a0d1 100644
--- a/extension.json
+++ b/extension.json
@@ -102,6 +102,7 @@
"modifiers": [ "alt", "shift" ]
}
},
-   "WikispeechSkipBackRewindsThreshold": 3.0
+   "WikispeechSkipBackRewindsThreshold": 3.0,
+   "WikispeechHelpPage": "Wikispeech_help"
}
 }
diff --git a/modules/ext.wikispeech.css b/modules/ext.wikispeech.css
index 98d0148..c9777c0 100644
--- a/modules/ext.wikispeech.css
+++ b/modules/ext.wikispeech.css
@@ -32,6 +32,16 @@
content: '\f050';
 }
 
+.ext-wikispeech-divider {
+   border-left: solid 1px rgb( 150, 150, 150 );
+   margin: 3px;
+}
+
+.ext-wikispeech-help:after {
+   font-family: 'Fontawesome';
+   content: '\f128';
+}
+
 .ext-wikispeech-control-panel {
position: fixed;
left: 0;
diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index 62c9ae0..6849474 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -10,7 +10,9 @@
 */
 
this.addControlPanel = function () {
-   $( '' )
+   var $controlPanel, helpPage;
+
+   $controlPanel = $( '' )
.attr( 'id', 'ext-wikispeech-control-panel' )
.addClass( 'ext-wikispeech-control-panel' )
.appendTo( '#content' );
@@ -40,6 +42,19 @@
'ext-wikispeech-skip-ahead-sentence',
self.skipAheadUtterance
);
+   helpPage = mw.config.get( 'wgWikispeechHelpPage' );
+   if ( helpPage ) {
+   // Only add button for help page if it is 
specified in
+   // the config.
+   $( '' )
+   .addClass( 'ext-wikispeech-divider' )
+   .appendTo( $controlPanel );
+   self.addButton(
+   'ext-wikispeech-help-button',
+   'ext-wikispeech-help',
+   self.goToHelpPage
+   );
+   }
};
 
/**
@@ -599,6 +614,18 @@
};
 
/**
+* Go to the help page.
+*
+* The name of the help page is specified by the config
+* variable `WikispeechHelpPage`.
+*/
+
+   this.goToHelpPage = function () {
+   window.location.pathname =
+   '/wiki/' + mw.config.get( 
'wgWikispeechHelpPage' );
+   };
+
+   /**
 * Register listeners for keyboard shortcuts.
 */
 
diff --git a/tests/qunit/ext.wikispeech.test.js 
b/tests/qunit/ext.wikispeech.test.js
index e5fea89..64c653b 100644
--- a/tests/qunit/ext.wikispeech.test.js
+++ b/tests/qunit/ext.wikispeech.test.js
@@ -192,6 +192,34 @@
);
} );
 
+   QUnit.test( 'addControlPanel(): add help button if page is set', 
function ( assert ) {
+   assert.expect( 1 );
+   mw.config.set(
+   'wgWikispeechHelpPage',
+   'Help'
+   );
+   

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Don't create empty elements

2017-03-30 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/345522 )

Change subject: Don't create empty  elements
..

Don't create empty  elements

These were created when a `CleanedText` only contained
whitespaces. The whitespaces were removed, but a `CleanedText` (with
the empty string) was created.

Bug: T159669
Change-Id: I2bb150b2e69357cd53e587344f41183da0b27bc1
---
M includes/Segmenter.php
M tests/phpunit/SegmenterTest.php
2 files changed, 34 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/22/345522/1

diff --git a/includes/Segmenter.php b/includes/Segmenter.php
index ea98d09..9dcb75f 100644
--- a/includes/Segmenter.php
+++ b/includes/Segmenter.php
@@ -135,25 +135,28 @@
$startOffset,
$endOffset - $startOffset + 1
);
-   $sentenceText = new CleanedText(
-   $sentence,
-   $text->path
-   );
-   array_push( $currentSegment['content'], $sentenceText );
-   if ( $currentSegment['startOffset'] === null ) {
-   // Record the start offset if this is the first text 
added
-   // to the segment.
-   $currentSegment['startOffset'] = $startOffset;
-   }
-   $currentSegment['endOffset'] = $endOffset;
-   if ( $ended ) {
-   array_push( $segments, $currentSegment );
-   // Create a fresh segment to add following text to.
-   $currentSegment = [
-   'content' => [],
-   'startOffset' => null,
-   'endOffset' => null
-   ];
+   if ( $sentence !== '' ) {
+   // Don't add `CleanedText`s with the empty string.
+   $sentenceText = new CleanedText(
+   $sentence,
+   $text->path
+   );
+   array_push( $currentSegment['content'], $sentenceText );
+   if ( $currentSegment['startOffset'] === null ) {
+   // Record the start offset if this is the first 
text
+   // added to the segment.
+   $currentSegment['startOffset'] = $startOffset;
+   }
+   $currentSegment['endOffset'] = $endOffset;
+   if ( $ended ) {
+   array_push( $segments, $currentSegment );
+   // Create a fresh segment to add following text 
to.
+   $currentSegment = [
+   'content' => [],
+   'startOffset' => null,
+   'endOffset' => null
+   ];
+   }
}
return $endOffset;
}
diff --git a/tests/phpunit/SegmenterTest.php b/tests/phpunit/SegmenterTest.php
index a7fd816..155fa18 100644
--- a/tests/phpunit/SegmenterTest.php
+++ b/tests/phpunit/SegmenterTest.php
@@ -192,6 +192,18 @@
);
}
 
+   public function testRemoveTextWithOnlyWhitespacesOutsideSegments() {
+   $cleanedContent = [
+   new CleanedText( ' ' ),
+   new CleanedText( 'Sentence 1.' )
+   ];
+   $segments = Segmenter::segmentSentences( $cleanedContent );
+   $this->assertEquals(
+   'Sentence 1.',
+   $segments[0]['content'][0]->string
+   );
+   }
+
public function testRemoveLeadingAndTrailingWhitespaces() {
$cleanedContent = [ new CleanedText( ' Sentence. ' ) ];
$segments = Segmenter::segmentSentences( $cleanedContent );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2bb150b2e69357cd53e587344f41183da0b27bc1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Calculate correct offsets for unicode characters

2017-03-24 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/344616 )

Change subject: Calculate correct offsets for unicode characters
..

Calculate correct offsets for unicode characters

Unicode characters are counted as multiple bytes, which manifested as
the highlighting of a sentence being longer than it should. This also
affects the start of following sentences.

In fixing this, the segmentation was reworked which also resulted in a
more consistent use of utterance boundaries ("offset" is used instead
of "position" and excludes the last character, which is more common
when getting substrings etc.), not including trailing or leading
whitespaces for utterances and properly handling utterances that are
completely wrapped in tags.

Bug: T159545
Bug: T159811
Bug: T159809
Bug: T159671

Change-Id: I8e32637a51857e383ed1fae5a83fa04b0a978deb
---
M Hooks.php
M extension.json
M includes/Cleaner.php
M includes/Segmenter.php
M modules/ext.wikispeech.js
M tests/phpunit/SegmenterTest.php
M tests/qunit/ext.wikispeech.test.js
7 files changed, 300 insertions(+), 103 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/16/344616/1

diff --git a/Hooks.php b/Hooks.php
index ea491cc..2fa1092 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -54,12 +54,12 @@
'Wikispeech',
'HTML from onParserAfterTidy(): ' . $text
);
-   $cleanedText = Cleaner::cleanHtml( $text );
+   $cleanedContents = Cleaner::cleanHtml( $text );
wfDebugLog(
'Wikispeech',
-   'Cleaned text: ' . var_export( $cleanedText, 
true )
+   'Cleaned text: ' . var_export( 
$cleanedContents, true )
);
-   $utterances = Segmenter::segmentSentences( $cleanedText 
);
+   $utterances = Segmenter::segmentSentences( 
$cleanedContents );
wfDebugLog(
'Wikispeech',
'Utterances: ' . var_export( $utterances, true )
diff --git a/extension.json b/extension.json
index 850c2b9..8b1b9d1 100644
--- a/extension.json
+++ b/extension.json
@@ -83,23 +83,23 @@
"WikispeechKeyboardShortcuts": {
"playStop": {
"key": 32,
-   "modifiers": [ "ctrl" ]
+   "modifiers": [ "alt", "shift" ]
},
"skipAheadSentence": {
"key": 39,
-   "modifiers": [ "ctrl" ]
+   "modifiers": [ "alt", "shift" ]
},
"skipBackSentence": {
"key": 37,
-   "modifiers": [ "ctrl" ]
+   "modifiers": [ "alt", "shift" ]
},
"skipAheadWord": {
"key": 40,
-   "modifiers": [ "ctrl" ]
+   "modifiers": [ "alt", "shift" ]
},
"skipBackWord": {
"key": 38,
-   "modifiers": [ "ctrl" ]
+   "modifiers": [ "alt", "shift" ]
}
},
"WikispeechSkipBackRewindsThreshold": 3.0
diff --git a/includes/Cleaner.php b/includes/Cleaner.php
index a65e0d6..ab58f48 100644
--- a/includes/Cleaner.php
+++ b/includes/Cleaner.php
@@ -25,12 +25,12 @@
// Only add elements below the dummy element. These are the
// elements from the original HTML.
$top = $xpath->evaluate( '/meta/dummy' )->item( 0 );
-   $cleanedContent = [];
+   $cleanedContents = [];
self::addContent(
-   $cleanedContent,
+   $cleanedContents,
$top
);
-   return $cleanedContent;
+   return $cleanedContents;
}
 
/**
diff --git a/includes/Segmenter.php b/includes/Segmenter.php
index 249bbf5..170e8e1 100644
--- a/includes/Segmenter.php
+++ b/includes/Segmenter.php
@@ -13,30 +13,30 @@
 *
 * A segment is an array with the keys "content", "startOffset"
 * and "endOffset". "content" is an array of `CleanedText`s.
-
-* "startOffset" is the position of the first character of the
+* "startOffset" is the offset of the first character of the
 * segment, within the text node it appears. "endOffset" is the
-* 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Prevent keyboard shortcuts from triggering buttons.

2017-03-16 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/343026 )

Change subject: Prevent keyboard shortcuts from triggering buttons.
..

Prevent keyboard shortcuts from triggering buttons.

keydown events with the same key combinations as keyboard shortcuts
don't fire. This is what triggers button click when a button is in
focus and space is pressed. This was implemented generally, i.e. not
only for space, since it's probably the preferred behaviour if there
are similar cases for other keys.

The default shortcuts was changed to use shit and alt instead of
control. This was done because there are some standard keyboard
combinations that were blocked, e.g. skipping word forward/backward
with ctrl+arrow when typing.

Bug: T146459
Change-Id: I8562ee4b78e50e29a35a4147b75b55bb3d6bc464
---
M extension.json
M modules/ext.wikispeech.js
2 files changed, 20 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/26/343026/1

diff --git a/extension.json b/extension.json
index 0470c86..0dbc30e 100644
--- a/extension.json
+++ b/extension.json
@@ -85,23 +85,23 @@
"WikispeechKeyboardShortcuts": {
"playStop": {
"key": 32,
-   "modifiers": [ "ctrl" ]
+   "modifiers": [ "alt", "shift" ]
},
"skipAheadSentence": {
"key": 39,
-   "modifiers": [ "ctrl" ]
+   "modifiers": [ "alt", "shift" ]
},
"skipBackSentence": {
"key": 37,
-   "modifiers": [ "ctrl" ]
+   "modifiers": [ "alt", "shift" ]
},
"skipAheadWord": {
"key": 40,
-   "modifiers": [ "ctrl" ]
+   "modifiers": [ "alt", "shift" ]
},
"skipBackWord": {
"key": 38,
-   "modifiers": [ "ctrl" ]
+   "modifiers": [ "alt", "shift" ]
}
},
"WikispeechSkipBackRewindsThreshold": 3.0
diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index 4290182..97435dc 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -592,7 +592,9 @@
 */
 
this.addKeyboardShortcuts = function () {
-   var shortcuts = mw.config.get( 
'wgWikispeechKeyboardShortcuts' );
+   var shortcuts, name, shortcut;
+
+   shortcuts = mw.config.get( 
'wgWikispeechKeyboardShortcuts' );
$( document ).keydown( function ( event ) {
if ( self.eventMatchShortcut( event, 
shortcuts.playStop ) ) {
self.playOrStop();
@@ -621,6 +623,18 @@
return false;
}
} );
+   // Prevent keyup events from triggering if there is
+   // keydown event for the same key combination. This 
caused
+   // buttons in focus to trigger if a shortcut had space 
as
+   // key.
+   $( document ).keyup( function ( event ) {
+   for ( name in shortcuts ) {
+   shortcut = shortcuts[ name ];
+   if ( self.eventMatchShortcut( event, 
shortcut ) ) {
+   event.preventDefault();
+   }
+   }
+   } );
};
 
/**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8562ee4b78e50e29a35a4147b75b55bb3d6bc464
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Use XPath to get text nodes for utterances.

2017-03-09 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/342024 )

Change subject: Use XPath to get text nodes for utterances.
..

Use XPath to get text nodes for utterances.

Replaced the index array paths with XPath expressions.

CleanedTag was also removed, since it's not needed anymore.

Bug: T158954
Change-Id: Ifec50d6d22a9e3e6adf51d96d315237852aa11ac
---
M extension.json
M includes/CleanedContent.php
M includes/Cleaner.php
M includes/HtmlGenerator.php
M includes/Segmenter.php
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M tests/phpunit/CleanerTest.php
M tests/phpunit/HtmlGeneratorTest.php
M tests/phpunit/SegmenterTest.php
M tests/qunit/ext.wikispeech.test.js
11 files changed, 173 insertions(+), 701 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/24/342024/1

diff --git a/extension.json b/extension.json
index 0470c86..850c2b9 100644
--- a/extension.json
+++ b/extension.json
@@ -18,8 +18,6 @@
"AutoloadClasses": {
"SpecialWikispeech": "specials/SpecialWikispeech.php",
"WikispeechHooks": "Hooks.php",
-   "CleanedContent": "includes/CleanedContent.php",
-   "CleanedTag": "includes/CleanedContent.php",
"CleanedText": "includes/CleanedContent.php",
"Cleaner": "includes/Cleaner.php",
"HtmlGenerator": "includes/HtmlGenerator.php",
diff --git a/includes/CleanedContent.php b/includes/CleanedContent.php
index 3065afd..f925615 100644
--- a/includes/CleanedContent.php
+++ b/includes/CleanedContent.php
@@ -6,33 +6,7 @@
  * @license GPL-2.0+
  */
 
-abstract class CleanedContent {
-   /**
-* The string representation of the content, as it is written in
-* the HTML. This includes the tag name, any attributes, and the
-* brackets, if content is a tag.
-*
-* @var string $string
-*/
-
-   public $string;
-
-   /**
-* Create a CleanedContent, given a string representation.
-*
-* @since 0.0.1
-* @param string $string The string representation of this content.
-*/
-
-   function __construct( $string ) {
-   $this->string = $string;
-   }
-}
-
-class CleanedTag extends CleanedContent {
-}
-
-class CleanedText extends CleanedContent {
+class CleanedText {
/**
 * The path in the HTML to the text node that this was created
 * from. The path consists of indices of the elements leading to
@@ -53,8 +27,8 @@
 * @param array $path The path to the text node this was created from.
 */
 
-   function __construct( $string, $path=[] ) {
-   parent::__construct( $string );
+   function __construct( $string, $path='' ) {
+   $this->string = $string;
$this->path = $path;
}
 
@@ -70,8 +44,7 @@
 
function toElement( $dom ) {
$element = $dom->createElement( 'text', $this->string );
-   $pathString = implode( $this->path, ',' );
-   $element->setAttribute( 'path', $pathString );
+   $element->setAttribute( 'path', $this->path );
return $element;
}
 }
diff --git a/includes/Cleaner.php b/includes/Cleaner.php
index 1109d48..135234a 100644
--- a/includes/Cleaner.php
+++ b/includes/Cleaner.php
@@ -16,25 +16,18 @@
 * @since 0.0.1
 * @param string $markedUpText Input text that may contain HTML
 *  tags.
-* @return array An array of nodes where tags are stored as
-*  `CleanedTag`s and text nodes as `Text`.
+* @return array An array of `CleanedText`s representing text nodes.
 */
 
public static function cleanHtml( $markedUpText ) {
$dom = self::createDomDocument( $markedUpText );
-   $tags = self::getTags( $markedUpText );
-   // Start adding the nodes that are children of the dummy
-   // element. To not add the actual dummy tags, index starts on
-   // -1.
-   $tagIndex = -1;
+   $xpath = new DOMXPath( $dom );
+   // Only add elements below the dummy element. These are the 
elements from the original HTML.
+   $top = $xpath->evaluate( '/meta/dummy' )->item( 0 );
$cleanedContent = [];
self::addContent(
$cleanedContent,
-   $dom->documentElement->firstChild,
-   $markedUpText,
-   $tags,
-   $tagIndex,
-   []
+   $top
);
return $cleanedContent;
}
@@ -66,297 +59,39 @@
}
 
/**
-* Extract a list of tags from a string.
+* Recursively add content as 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Change buttons to display glyphs

2017-03-07 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/341498 )

Change subject: Change buttons to display glyphs
..

Change buttons to display glyphs

The placeholder strings, that were previously used, were replaced by
Font Awesome icons. The buttons were also reordered to look more like
what's common in media players.

Bug: T151884
Change-Id: Ia1dfa4ad86541452c2d81bd5a7781d07137b4dfd
---
M Gruntfile.js
M extension.json
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
A modules/font-awesome-4.7.0/HELP-US-OUT.txt
A modules/font-awesome-4.7.0/css/font-awesome.css
A modules/font-awesome-4.7.0/css/font-awesome.min.css
A modules/font-awesome-4.7.0/fonts/FontAwesome.otf
A modules/font-awesome-4.7.0/fonts/fontawesome-webfont.eot
A modules/font-awesome-4.7.0/fonts/fontawesome-webfont.svg
A modules/font-awesome-4.7.0/fonts/fontawesome-webfont.ttf
A modules/font-awesome-4.7.0/fonts/fontawesome-webfont.woff
A modules/font-awesome-4.7.0/fonts/fontawesome-webfont.woff2
A modules/font-awesome-4.7.0/less/animated.less
A modules/font-awesome-4.7.0/less/bordered-pulled.less
A modules/font-awesome-4.7.0/less/core.less
A modules/font-awesome-4.7.0/less/fixed-width.less
A modules/font-awesome-4.7.0/less/font-awesome.less
A modules/font-awesome-4.7.0/less/icons.less
A modules/font-awesome-4.7.0/less/larger.less
A modules/font-awesome-4.7.0/less/list.less
A modules/font-awesome-4.7.0/less/mixins.less
A modules/font-awesome-4.7.0/less/path.less
A modules/font-awesome-4.7.0/less/rotated-flipped.less
A modules/font-awesome-4.7.0/less/screen-reader.less
A modules/font-awesome-4.7.0/less/stacked.less
A modules/font-awesome-4.7.0/less/variables.less
A modules/font-awesome-4.7.0/scss/_animated.scss
A modules/font-awesome-4.7.0/scss/_bordered-pulled.scss
A modules/font-awesome-4.7.0/scss/_core.scss
A modules/font-awesome-4.7.0/scss/_fixed-width.scss
A modules/font-awesome-4.7.0/scss/_icons.scss
A modules/font-awesome-4.7.0/scss/_larger.scss
A modules/font-awesome-4.7.0/scss/_list.scss
A modules/font-awesome-4.7.0/scss/_mixins.scss
A modules/font-awesome-4.7.0/scss/_path.scss
A modules/font-awesome-4.7.0/scss/_rotated-flipped.scss
A modules/font-awesome-4.7.0/scss/_screen-reader.scss
A modules/font-awesome-4.7.0/scss/_stacked.scss
A modules/font-awesome-4.7.0/scss/_variables.scss
A modules/font-awesome-4.7.0/scss/font-awesome.scss
41 files changed, 8,734 insertions(+), 33 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/98/341498/1


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia1dfa4ad86541452c2d81bd5a7781d07137b4dfd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Floating control panel for player

2017-03-06 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/341298 )

Change subject: Floating control panel for player
..

Floating control panel for player

Moved the buttons for controlling the player to a separate , that
is placed at the bottom of the page. The control panel is fixed to
this position, even when scrolling. When debugging, the control panel
is placed above (Y-axis) the debug panel.

CSS linting was changed from csslint to stylelint.

Bug: T151887
Change-Id: I17ebf3ab3a32dba2b28715bc3053b6b2746bd4f3
---
A .stylelintrc
M Gruntfile.js
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M package.json
M tests/qunit/ext.wikispeech.test.js
6 files changed, 116 insertions(+), 43 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/98/341298/1

diff --git a/.stylelintrc b/.stylelintrc
new file mode 100644
index 000..2c90730
--- /dev/null
+++ b/.stylelintrc
@@ -0,0 +1,3 @@
+{
+   "extends": "stylelint-config-wikimedia"
+}
diff --git a/Gruntfile.js b/Gruntfile.js
index 42cbbd3..981072a 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -5,7 +5,7 @@
grunt.loadNpmTasks( 'grunt-jsonlint' );
grunt.loadNpmTasks( 'grunt-banana-checker' );
grunt.loadNpmTasks( 'grunt-jscs' );
-   grunt.loadNpmTasks( 'grunt-contrib-csslint' );
+   grunt.loadNpmTasks( 'grunt-stylelint' );
 
grunt.initConfig( {
jshint: {
@@ -29,7 +29,16 @@
'!node_modules/**'
]
},
-   csslint: {
+   stylelint: {
+   options: {
+   configFile: '.stylelintrc',
+   formatter: 'string',
+   ignoreDisables: false,
+   failOnError: true,
+   outputFile: '',
+   reportNeedlessDisables: false,
+   syntax: ''
+   },
all: 'modules/**/*.css'
}
} );
@@ -41,7 +50,7 @@
'jscs',
'jsonlint',
'banana',
-   'csslint'
+   'stylelint'
]
);
grunt.registerTask( 'default', 'test' );
diff --git a/modules/ext.wikispeech.css b/modules/ext.wikispeech.css
index 4b5bfb3..5fe48a5 100644
--- a/modules/ext.wikispeech.css
+++ b/modules/ext.wikispeech.css
@@ -3,30 +3,39 @@
 }
 
 .ext-wikispeech-play:after {
-   content: "Play";
+   content: 'Play';
 }
 
 .ext-wikispeech-stop:after {
-   content: "Stop";
+   content: 'Stop';
 }
 
 .ext-wikispeech-skip-ahead-sentence:after {
-   content: "Skip ahead sentence";
+   content: 'Skip ahead sentence';
 }
 
 .ext-wikispeech-skip-back-sentence:after {
-   content: "Skip back sentence";
+   content: 'Skip back sentence';
 }
 
 .ext-wikispeech-skip-ahead-word:after {
-   content: "Skip ahead word";
+   content: 'Skip ahead word';
 }
 
 .ext-wikispeech-skip-back-word:after {
-   content: "Skip back word";
+   content: 'Skip back word';
 }
 
 .ext-wikispeech-highlight-sentence {
-   background-color: rgb(0, 200, 0);
-   background-color: rgba(0, 200, 0, 0.5);
-}
\ No newline at end of file
+   background-color: rgb( 0, 200, 0 );
+   background-color: rgba( 0, 200, 0, 0.5 );
+}
+
+.ext-wikispeech-control-panel {
+   position: fixed;
+   bottom: 0;
+   width: 100%;
+   text-align: center;
+   border: solid 1px rgb( 150, 150, 150 );
+   background-color: rgb( 200, 200, 200 );
+}
diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index 2db7949..a130844 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -9,7 +9,12 @@
 * Add buttons for controlling playback to the top of the page.
 */
 
-   this.addButtons = function () {
+   this.addControlPanel = function () {
+   $( '' )
+   .attr( 'id', 'ext-wikispeech-control-panel' )
+   .addClass( 'ext-wikispeech-control-panel' )
+   .appendTo( '#content' );
+   self.moveControlPanelWhenDebugging();
self.addButton(
'ext-wikispeech-play-stop-button',
'ext-wikispeech-play',
@@ -38,6 +43,52 @@
};
 
/**
+   * Make sure the control panel isn't covered by the debug panel.
+   *
+   * The debug panel is also added to the bottom of the page and
+   * covers the control panel. This function moves the control
+

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Highlight recited sentence

2017-02-09 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/336816 )

Change subject: Highlight recited sentence
..

Highlight recited sentence

Added highlighting to the sentence that is currently being recited,
using span elements. The highlighting visuals can be changed in
modules/ext.wikispeech.css. All text nodes that were used to generate
the utterance is wrapped in spans, except for the first and
last. These only get the ranges used as part of the utterance wrapped.

A `path` attribute was introduced to make the connection from an
utterance to the text nodes that were used to generate it. In doing
this, it was discovered that the position attributes, that were
previously added to both utterances and tokens, aren't used in this
solution. They were therefore removed.

Tests were changed a bit to have less overlap in what's being tested
and to make them easier to work with.

Bug: T148622
Change-Id: I12c8873265b7236c0677b25ce089bbb887ffdd9c
---
A includes/CleanedContent.php
D includes/CleanedTag.php
M includes/Cleaner.php
M includes/HtmlGenerator.php
M includes/Segmenter.php
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M tests/phpunit/CleanerTest.php
M tests/phpunit/HtmlGeneratorTest.php
M tests/phpunit/SegmenterTest.php
M tests/phpunit/Util.php
M tests/qunit/ext.wikispeech.test.js
12 files changed, 962 insertions(+), 629 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/16/336816/1

diff --git a/includes/CleanedContent.php b/includes/CleanedContent.php
new file mode 100644
index 000..4d123b3
--- /dev/null
+++ b/includes/CleanedContent.php
@@ -0,0 +1,52 @@
+string = $string;
+   }
+}
+
+class CleanedTag extends CleanedContent {
+}
+
+class Text extends CleanedContent {
+   public $path;
+
+   function __construct( $string, $path=[] ) {
+   parent::__construct( $string );
+   $this->path = $path;
+   }
+
+   /**
+* Create a Text element from the content.
+*
+* Path is converted to a string and added as an attribute.
+*
+* @since 0.0.1
+* @param DOMDocument $dom The DOM Document used to create the element.
+* @return DOMElement The length of the tag string.
+*/
+
+   function toElement( $dom ) {
+   $element = $dom->createElement( 'text', $this->string );
+   $pathString = implode( $this->path, ',' );
+   $element->setAttribute( 'path', $pathString );
+   return $element;
+   }
+}
diff --git a/includes/CleanedTag.php b/includes/CleanedTag.php
deleted file mode 100644
index 697032c..000
--- a/includes/CleanedTag.php
+++ /dev/null
@@ -1,73 +0,0 @@
-tagString = $tagString;
-   }
-
-   /**
-* Get the length of the tag string.
-*
-* @since 0.0.1
-* @return int The length of the tag string.
-*/
-
-   function getLength() {
-   return strlen( $this->tagString );
-   }
-}
-
-class CleanedStartTag extends CleanedTag {
-
-   /**
-* The length of the element content, i.e. the string delimited by
-* this start tag and the corresponding end tag.
-*
-* @var int $contentLength
-*/
-
-   public $contentLength;
-
-   function __construct( $tagString ) {
-   parent::__construct( $tagString );
-   $this->contentLength = 0;
-   }
-
-   /**
-* Get the length of the tag string.
-*
-* @since 0.0.1
-* @return int The length of the tag string, including element content.
-*/
-
-   function getLength() {
-   $length = strlen( $this->tagString );
-   if ( $this->contentLength ) {
-   $length += $this->contentLength;
-   }
-   return $length;
-   }
-}
-
-class CleanedEndTag extends CleanedTag {
-}
-
-class CleanedEmptyElementTag extends CleanedTag {
-}
diff --git a/includes/Cleaner.php b/includes/Cleaner.php
index e7b4a1f..dc547f6 100644
--- a/includes/Cleaner.php
+++ b/includes/Cleaner.php
@@ -6,7 +6,7 @@
  * @license GPL-2.0+
  */
 
-require_once 'CleanedTag.php';
+require_once 'CleanedContent.php';
 
 class Cleaner {
 
@@ -35,7 +35,8 @@
$dom->documentElement->firstChild,
$markedUpText,
$tags,
-   $tagIndex
+   $tagIndex,
+   []
);
return $cleanedContent;
}
@@ -73,14 +74,12 @@
 * regex since we need the exact string representation of tags to
 * get their correct lengths.
 *
-* When a start tag is encountered, it's stored as an array
-* containing the tag string and the start position of the
-* tag. This array is 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Skip back word

2016-10-11 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/315218

Change subject: Skip back word
..

Skip back word

Enabled skipping back one word at a time while playing. Button and keyborad
shortcut (ctrl + up arrow by deafult) was added.

Also changed from spies to stubs in tests to isolate them further.

Bug: T133687
Change-Id: I0165d2c55680191160ec1f717f5b5452172aecd9
---
M extension.json
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M tests/qunit/ext.wikispeech.test.js
4 files changed, 244 insertions(+), 56 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/18/315218/1

diff --git a/extension.json b/extension.json
index 6f0c748..334d4f6 100644
--- a/extension.json
+++ b/extension.json
@@ -87,6 +87,10 @@
"skipAheadWord": {
"key": 40,
"modifiers": [ "ctrl" ]
+   },
+   "skipBackWord": {
+   "key": 38,
+   "modifiers": [ "ctrl" ]
}
},
"WikispeechSkipBackRewindsThreshold": 3.0
diff --git a/modules/ext.wikispeech.css b/modules/ext.wikispeech.css
index d362b04..18f6934 100644
--- a/modules/ext.wikispeech.css
+++ b/modules/ext.wikispeech.css
@@ -21,3 +21,7 @@
 .ext-wikispeech-skip-ahead-word:after {
content: "Skip ahead word";
 }
+
+.ext-wikispeech-skip-back-word:after {
+   content: "Skip back word";
+}
diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index bedfd7a..81ba3fa 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -30,6 +30,11 @@
'ext-wikispeech-skip-ahead-word',
self.skipAheadToken
);
+   self.addButton(
+   'ext-wikispeech-skip-back-word-button',
+   'ext-wikispeech-skip-back-word',
+   self.skipBackToken
+   );
};
 
this.addButton = function ( id, cssClass, onClickFunction ) {
@@ -232,6 +237,74 @@
};
 
/**
+* Skip to the previous token.
+*/
+
+   this.skipBackToken = function () {
+   var $previousToken, $utterance, $audio;
+
+   if ( self.isPlaying() ) {
+   $previousToken =
+   self.getPreviousToken( 
self.getCurrentToken() );
+   $utterance = $previousToken.parent().parent();
+   if ( $utterance.get( 0 ) !== 
$currentUtterance.get( 0 ) ) {
+   self.playUtterance( $utterance );
+   }
+   $audio = $currentUtterance.children( 'audio' );
+   $audio.prop( 'currentTime', 
$previousToken.attr( 'time' ) );
+   }
+   };
+
+   /**
+* Get the token before a given token.
+*
+* Tokens that are "silent" i.e. have a duration of zero or 
have no
+* transcription, are ignored.
+*
+* @param $token Original token.
+* @return The token before $token.
+*/
+
+   this.getPreviousToken = function ( $token ) {
+   var $utterance, $followingToken, $tokens;
+
+   $utterance = $token.parent().parent();
+   do {
+   $followingToken = $token;
+   $token = $token.prev();
+   if ( !$token.length ) {
+   $utterance = $utterance.prev();
+   if ( !$utterance.length ) {
+   return $();
+   }
+   $tokens = $utterance.find( 'token' );
+   $token = $( $utterance.find( 'token' )
+   .get( 
$tokens.length - 1 ) );
+   }
+   // Ignore tokens that either have a duration of 
zero or that
+   // have no text.
+   } while (
+   $token.attr( 'time' ) === $followingToken.attr( 
'time' ) ||
+   $token.text() === ''
+   );
+   return $token;
+   };
+
+   /**
+

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Skip back sentence

2016-10-07 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/314664

Change subject: Skip back sentence
..

Skip back sentence

Enabled skipping back to the previous sentence while playing. If the current
sentence has played for less than a certain number of seconds, it's played
from the beginning. This threshold can be set in the configuration and is
3 seconds by default. Button and keyborad shortcut (ctrl + down arrow by
deafult) was added.

Bug: T133687
Change-Id: Ib63a013f525ce41f4e03bccf115ebe2a15fe4992
---
M Hooks.php
M extension.json
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M tests/qunit/ext.wikispeech.test.js
5 files changed, 222 insertions(+), 61 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/64/314664/1

diff --git a/Hooks.php b/Hooks.php
index a7c3211..0d15c02 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -120,6 +120,9 @@
global $wgWikispeechKeyboardShortcuts;
$vars['wgWikispeechKeyboardShortcuts'] =
$wgWikispeechKeyboardShortcuts;
+   global $wgWikispeechSkipBackRewindsThreshold;
+   $vars['wgWikispeechSkipBackRewindsThreshold'] =
+   $wgWikispeechSkipBackRewindsThreshold;
return true;
}
 }
diff --git a/extension.json b/extension.json
index efba7c8..6f0c748 100644
--- a/extension.json
+++ b/extension.json
@@ -80,10 +80,15 @@
"key": 39,
"modifiers": [ "ctrl" ]
},
+   "skipBackSentence": {
+   "key": 37,
+   "modifiers": [ "ctrl" ]
+   },
"skipAheadWord": {
"key": 40,
"modifiers": [ "ctrl" ]
}
-   }
+   },
+   "WikispeechSkipBackRewindsThreshold": 3.0
}
 }
diff --git a/modules/ext.wikispeech.css b/modules/ext.wikispeech.css
index 0ea613c..d362b04 100644
--- a/modules/ext.wikispeech.css
+++ b/modules/ext.wikispeech.css
@@ -14,6 +14,10 @@
content: "Skip ahead sentence";
 }
 
+.ext-wikispeech-skip-back-sentence:after {
+   content: "Skip back sentence";
+}
+
 .ext-wikispeech-skip-ahead-word:after {
content: "Skip ahead word";
 }
diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index 1a3b0b4..7bce8a6 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -5,28 +5,39 @@
self = this;
$currentUtterance = $();
 
-   this.addButtons = function () {
-   self.addPlayStopButton();
-   self.addSkipAheadSentenceButton();
-   self.addSkipAheadWordButton();
-   };
-
/**
-* Add a button for starting and stopping recitation to the 
page.
-*
-* When no utterance is playing, clicking starts the first 
utterance.
-* When an utterance is being played, clicking stops the 
playback.
-* The button changes appearance to reflect its current 
function.
+* Add buttons for controlling playback to the top of the 
article.
 */
 
-   this.addPlayStopButton = function () {
-   var $playStopButton = $( '' )
-   .attr( 'id', 'ext-wikispeech-play-stop-button' )
-   .addClass( 'ext-wikispeech-play' );
-   $( '#firstHeading' ).append( $playStopButton );
-   // For some reason, testing doesn't work with
-   // .click( self.playOrStop ).
-   $playStopButton.click( function () { self.playOrStop(); 
} );
+   this.addButtons = function () {
+   self.addButton(
+   'ext-wikispeech-play-stop-button',
+   'ext-wikispeech-play',
+   self.playOrStop
+   );
+   self.addButton(
+   'ext-wikispeech-skip-ahead-sentence-button',
+   'ext-wikispeech-skip-ahead-sentence',
+   self.skipAheadUtterance
+   );
+   self.addButton(
+   'ext-wikispeech-skip-back-sentence-button',
+   'ext-wikispeech-skip-back-sentence',
+   self.skipBackUtterance
+   );
+   self.addButton(
+   'ext-wikispeech-skip-ahead-word-button',
+   

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Map tokens from TTS responses to HTML

2016-10-05 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/314237

Change subject: Map tokens from TTS responses to HTML
..

Map tokens from TTS responses to HTML

Added mapping between the tokens received from the TTS server to the "words"
in the html. Tokens are stored in the utterance elements and are assigned a
position attribute, which is the index of the start of the corresponding
html substring. Removed HTML tags are stored in the tokens element.

Bug: T140105
Change-Id: Ie784328fa3d7bcf7941b6b89146687272fe3b0ca
---
M Hooks.php
A includes/CleanedTag.php
M includes/Cleaner.php
M includes/HtmlGenerator.php
M includes/Segmenter.php
M modules/ext.wikispeech.js
M tests/phpunit/CleanerTest.php
M tests/phpunit/HtmlGeneratorTest.php
M tests/phpunit/SegmenterTest.php
A tests/phpunit/Util.php
M tests/qunit/ext.wikispeech.test.js
11 files changed, 1,303 insertions(+), 271 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/37/314237/1

diff --git a/Hooks.php b/Hooks.php
index 33e6c1d..a7c3211 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -18,7 +18,7 @@
 *
 * @param array $testModules The array of registered test modules
 * @param ResourceLoader $resourceLoader The reference to the resource
-*  loader
+*  loader
 * @return true
 */
 
@@ -46,7 +46,7 @@
 * namespace.
 *
 * @param $parser Parser object. Can be used to manually parse a portion
-*  of wiki text from the $text.
+*  of wiki text from the $text.
 * @param $text Represents the text for page.
 */
 
@@ -59,14 +59,17 @@
'HTML from onParserAfterTidy(): ' . $text
);
$cleanedText = Cleaner::cleanHtml( $text );
-   wfDebugLog( 'Wikispeech', 'Cleaned text: ' . 
$cleanedText );
+   wfDebugLog(
+   'Wikispeech',
+   'Cleaned text: ' . var_export( $cleanedText, 
true )
+   );
$utterances = Segmenter::segmentSentences( $cleanedText 
);
wfDebugLog(
'Wikispeech',
'Utterances: ' . var_export( $utterances, true )
);
$utterancesHtml =
-   HtmlGenerator::generateUtterancesHtml( 
$utterances );
+   HtmlGenerator::createUtterancesHtml( 
$utterances );
wfDebugLog(
'Wikispeech',
'Adding utterances HTML: ' . $utterancesHtml
@@ -101,7 +104,7 @@
 *
 * @param OutputPage $out The OutputPage object.
 * @param Skin $skin Skin object that will be used to generate the page,
-*  added in 1.13.
+*  added in 1.13.
 */
 
public static function onBeforePageDisplay(
diff --git a/includes/CleanedTag.php b/includes/CleanedTag.php
new file mode 100644
index 000..a5f112c
--- /dev/null
+++ b/includes/CleanedTag.php
@@ -0,0 +1,76 @@
+tagString = $tagString;
+   }
+
+   /**
+* Get the length of the tag string.
+*
+* @since 0.0.1
+* @return int The length of the tag string.
+*/
+
+   function getLength() {
+   return strlen( $this->tagString );
+   }
+}
+
+class CleanedStartTag extends CleanedTag {
+
+   /**
+* @var int $contentLength The length of the element content, i.e. the
+* string delimited by this start tag and the corresponding end tag.
+*/
+
+   public $contentLength;
+
+   /**
+* @var bool $removed Whether the tag was completely removed.
+*/
+
+   public $removed;
+
+   function __construct( $tagString ) {
+   parent::__construct( $tagString );
+   $this->contentLength = 0;
+   $this->removed = false;
+   }
+
+   /**
+* Get the length of the tag string.
+*
+* @since 0.0.1
+* @return int The length of the tag string, including element content.
+*/
+
+   function getLength() {
+   $length = strlen( $this->tagString );
+   if ( $this->removed ) {
+   $length += $this->contentLength;
+   }
+   return $length;
+   }
+}
+
+class CleanedEndTag extends CleanedTag {
+}
+
+class CleanedEmptyTag extends CleanedTag {
+}
diff --git a/includes/Cleaner.php b/includes/Cleaner.php
index 9dcc7e6..5fd5917 100644
--- a/includes/Cleaner.php
+++ b/includes/Cleaner.php
@@ -6,19 +6,49 @@
  * @license GPL-2.0+
  */
 
+require_once 'CleanedTag.php';
+
 class Cleaner {
 
/**
-* Clean HTML 

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Skip ahead setence

2016-08-23 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/306159

Change subject: Skip ahead setence
..

Skip ahead setence

Added functionality for skipping ahead one sentence, i.e. start playing the
sentence after the one currently being played. Also refactored some of the
code for playing utterances.

Bug: T140090
Change-Id: I40b81181bcff707008cd4366309b3e68f954fe62
---
M modules/ext.wikispeech.css
M modules/ext.wikispeech.js
M tests/qunit/ext.wikispeech.test.js
3 files changed, 172 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/59/306159/1

diff --git a/modules/ext.wikispeech.css b/modules/ext.wikispeech.css
index 896e735..a7366ad 100644
--- a/modules/ext.wikispeech.css
+++ b/modules/ext.wikispeech.css
@@ -9,3 +9,7 @@
 .ext-wikispeech-stop:after {
content: "Stop";
 }
+
+.ext-wikispeech-skip-ahead-sentence:after {
+   content: "Skip ahead sentence";
+}
diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index c38d824..7c7350a 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -1,12 +1,12 @@
 ( function ( mw, $ ) {
function Wikispeech() {
-   var self, $currentAudio;
+   var self, $currentUtterance;
 
self = this;
-   $currentAudio = $();
+   $currentUtterance = $();
 
/**
-* Adds button for starting and stopping recitation to the page.
+* Add a button for starting and stopping recitation to the 
page.
 *
 * When no utterance is playing, clicking starts the first 
utterance.
 * When an utterance is being played, clicking stops the 
playback.
@@ -21,20 +21,100 @@
.addClass( 'ext-wikispeech-play' );
$( '#firstHeading' ).append( $playStopButton );
$playStopButton.click( function () {
-   if ( $currentAudio.length === 0 ) {
-   $currentAudio = $( '#utterance-0 audio' 
);
-   $currentAudio.trigger( 'play' );
-   $playStopButton.removeClass( 
'ext-wikispeech-play' );
-   $playStopButton.addClass( 
'ext-wikispeech-stop' );
+   if ( $currentUtterance.length === 0 ) {
+   self.play();
} else {
-   $currentAudio.trigger( 'pause' );
-   // Rewind audio for next time it plays.
-   $currentAudio.prop( 'currentTime', 0 );
-   $currentAudio = $();
-   $playStopButton.removeClass( 
'ext-wikispeech-stop' );
-   $playStopButton.addClass( 
'ext-wikispeech-play' );
+   self.stop();
}
} );
+   };
+
+   /**
+* Play the first utterance.
+*/
+
+   this.play = function () {
+   var $playStopButton;
+
+   self.playUtterance( $( '#utterance-0' ) );
+   $playStopButton = $( '#ext-wikispeech-play-stop-button' 
);
+   $playStopButton.removeClass( 'ext-wikispeech-play' );
+   $playStopButton.addClass( 'ext-wikispeech-stop' );
+   };
+
+   /**
+* Play the audio for an utterance.
+*
+* This also stops any currently playing utterance.
+*
+* @param $utterance The utterance to play the audio for.
+*/
+
+   this.playUtterance = function ( $utterance ) {
+   self.stopUtterance( $currentUtterance );
+   $currentUtterance = $utterance;
+   $utterance.children( 'audio' ).trigger( 'play' );
+   };
+
+   /**
+* Stop and rewind the audio for an utterance.
+*
+* @param $utterance The utterance to stop the audio for.
+*/
+
+   this.stopUtterance = function ( $utterance ) {
+   $utterance.children( 'audio' ).trigger( 'pause' );
+   // Rewind audio for next time it plays.
+   $utterance.children( 'audio' ).prop( 'currentTime', 0 );
+   };
+
+   /**
+* Stop playing the utterance currently playing.
+*/
+
+   this.stop = function () {
+  

[MediaWiki-commits] [Gerrit] mediawiki...Wikispeech[master]: Enable extension specific variables

2016-08-19 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/305640

Change subject: Enable extension specific variables
..

Enable extension specific variables

Variables can be accessed in PHP and JavaScript, one case of each was
added (tag removal criteria and TTS server URL, respectively). Default
variables are set in extension.json and can be overwritten in
LocalSettings.php.

Bug: T140221
Change-Id: If040e7c8cac5897712582d0759865f5ad4717479
---
M Hooks.php
M extension.json
M includes/Cleaner.php
M modules/ext.wikispeech.js
M tests/phpunit/CleanerTest.php
5 files changed, 117 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/40/305640/1

diff --git a/Hooks.php b/Hooks.php
index 1c7bc3a..360f803 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -63,4 +63,10 @@
) {
$out->addModules( [ 'ext.wikispeech' ] );
}
+
+   public static function onResourceLoaderGetConfigVars( &$vars ) {
+   global $wgWikispeechServerUrl;
+   $vars['wgWikispeechServerUrl'] = $wgWikispeechServerUrl;
+   return true;
+   }
 }
diff --git a/extension.json b/extension.json
index 2d3a525..cbb3394 100644
--- a/extension.json
+++ b/extension.json
@@ -54,6 +54,21 @@
],
"BeforePageDisplay": [
"WikispeechHooks::onBeforePageDisplay"
+   ],
+   "ResourceLoaderGetConfigVars": [
+   "WikispeechHooks::onResourceLoaderGetConfigVars"
]
+   },
+   "config": {
+   "WikispeechServerUrl": "https://morf.se/wikispeech/;,
+   "WikispeechRemoveTags": {
+   "editsection": true,
+   "toc": true,
+   "table": true,
+   "sup": { "class": "reference" },
+   "div": { "class": "thumb" },
+   "ul": true,
+   "ol": true
+   }
}
 }
diff --git a/includes/Cleaner.php b/includes/Cleaner.php
index 8f8361a..af7348f 100644
--- a/includes/Cleaner.php
+++ b/includes/Cleaner.php
@@ -7,18 +7,6 @@
  */
 
 class Cleaner {
-   // HTML tags that should be removes altogether. If value is null, there
-   // are no further criteria. If the value contains 'class', the tag
-   // also needs to have that class to be removed.
-   private static $REMOVE_TAGS = [
-   'editsection' => null,
-   'toc' => null,
-   'table' => null,
-   'sup' => [ 'class' => 'reference' ],
-   'div' => [ 'class' => 'thumb' ],
-   'ul' => null,
-   'ol' => null
-   ];
 
/**
 * Clean HTML tags by removing some altogether and keeping content
@@ -67,33 +55,63 @@
}
 
/**
-* Check if a node matches criteria for removal.
+* Check if a tag matches criteria for removal.
+*
+* The criteria are defined by $wgWikispeechRemoveTags, which is a map
+* where the keys are tag names. If the value is true, the tag will be
+* removed. If the value is an array, it defines further criteria,
+* currently only class name, which needs to match for the tag to be
+* removed.
+*
+* The value may be false, which means the tag won't be removed. This 
is to
+* allow overriding default values in LocalSettings.php, but is 
otherwise
+* not required.
 *
 * @since 0.0.1
-* @param DOMNode $node The node to check.
-* @return bool true if the node match removal criteria, otherwise 
false.
+* @param DOMNode $node The node for the tag to check.
+* @return bool true if the tag match removal criteria, otherwise false.
 */
 
private static function matchesRemove( $node ) {
-   if ( !array_key_exists( $node->nodeName, self::$REMOVE_TAGS ) ) 
{
+   global $wgWikispeechRemoveTags;
+   if ( !array_key_exists( $node->nodeName, 
$wgWikispeechRemoveTags ) ) {
// The node name isn't found in the removal list.
return false;
}
-   $removeCriteria = self::$REMOVE_TAGS[ $node->nodeName ];
-   if ( $removeCriteria == null ) {
-   // Node name matches and there are no extra criteria.
+   $removeCriteria = $wgWikispeechRemoveTags[ $node->nodeName ];
+   if ( $removeCriteria === true ) {
+   // Node name is found and there are no extra criteria.
return true;
}
+   if ( self::nodeHasClass( $node, $removeCriteria[ 'class' ] ) ) {
+   // Node name and class name match.
+

[MediaWiki-commits] [Gerrit] Start and stop recitation with keyboard - change (mediawiki...Wikispeech)

2016-07-21 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/300247

Change subject: Start and stop recitation with keyboard
..

Start and stop recitation with keyboard

Added a shortcut (initially ctrl + space) to start and stop the recitation.

Bug: T133676
Change-Id: I2a0615989056a08a84d965d14e6f03a82af7dbda
---
M modules/ext.wikispeech.js
1 file changed, 10 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/47/300247/1

diff --git a/modules/ext.wikispeech.js b/modules/ext.wikispeech.js
index f468880..0b819af 100644
--- a/modules/ext.wikispeech.js
+++ b/modules/ext.wikispeech.js
@@ -2,10 +2,10 @@
 
/**
 * Adds button for starting and stopping recitation to the page.
-* When no utterance is playing, clicking starts the first utterance.
-* When an utterance is being played, clicking stops the playback.
-* The button changes between play and stop symbols to reflect its
-* current function.
+* When no utterance is playing, the button starts the first utterance.
+* When an utterance is being played, the button stops the playback. The
+* button changes between play and stop symbols to reflect its current
+* function.
 */
 
function addPlayStopButton() {
@@ -34,6 +34,12 @@
} );
}
} );
+   // Add keyboard shortcut.
+   $( document ).keydown( function ( event ) {
+   if ( event.ctrlKey && event.key === ' ' ) {
+   $playStopButton.click();
+   }
+   } );
}
 
/**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a0615989056a08a84d965d14e6f03a82af7dbda
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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


[MediaWiki-commits] [Gerrit] Change license to GPL-2.0+ - change (mediawiki...Wikispeech)

2016-07-20 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/300029

Change subject: Change license to GPL-2.0+
..

Change license to GPL-2.0+

Changed the license to GPL-2.0+, from GPL-3.0+, to be more consistent with
MediaWiki.

Bug: T136805
Change-Id: I7a036b2de9ab0cfd1f7e5bf5c9bca272c962dbd3
---
M COPYING.txt
M Hooks.php
M extension.json
M includes/Cleaner.php
M includes/Segmenter.php
M tests/phpunit/CleanerTest.php
M tests/phpunit/SegmenterTest.php
7 files changed, 259 insertions(+), 594 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/29/300029/1

diff --git a/COPYING.txt b/COPYING.txt
index 4936591..e522f40 100644
--- a/COPYING.txt
+++ b/COPYING.txt
@@ -8,624 +8,283 @@
 
 
 GNU GENERAL PUBLIC LICENSE
-   Version 3, 29 June 2007
+   Version 2, June 1991
 
- Copyright (C) 2007 Free Software Foundation, Inc. 
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.
 
 Preamble
 
-  The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
-  The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works.  By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users.  We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors.  You can apply it to
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
 your programs, too.
 
   When we speak of free software, we are referring to freedom, not
 price.  Our General Public Licenses are designed to make sure that you
 have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
 
-  To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights.  Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
 
   For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received.  You must make sure that they, too, receive
-or can get the source code.  And you must show them these terms so they
-know their rights.
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
 
-  Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
 
-  For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software.  For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
+  Also, for each author's protection and ours, we 

[MediaWiki-commits] [Gerrit] Segment text - change (mediawiki...Wikispeech)

2016-07-11 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/298256

Change subject: Segment text
..

Segment text

Added functionality to segment text into reasonable size for sending to the
TTS. The Segmenter class has two functions, one for segmenting on paragraph
level and one for sentence level. The latter is still quite basic, and may
need extending to cover specific cases.

Bug: T135980
Change-Id: Ie1f839e1ccd6f4928522de8e22a50ae474dbda04
---
A includes/Segmenter.php
A tests/phpunit/SegmenterTest.php
2 files changed, 136 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/56/298256/1

diff --git a/includes/Segmenter.php b/includes/Segmenter.php
new file mode 100644
index 000..d986a6a
--- /dev/null
+++ b/includes/Segmenter.php
@@ -0,0 +1,59 @@
+ 0 ) {
+   array_push( $segments, $segment );
+   }
+   }
+   return $segments;
+   }
+}
diff --git a/tests/phpunit/SegmenterTest.php b/tests/phpunit/SegmenterTest.php
new file mode 100644
index 000..81a88ac
--- /dev/null
+++ b/tests/phpunit/SegmenterTest.php
@@ -0,0 +1,77 @@
+assertEquals( $expectedSegments, $segments );
+   }
+
+   public function testSegmentByThreeDots() {
+   // @codingStandardsIgnoreStart
+   $input = "I mean, in ten recording sessions, man, we didn't get 
one song...It was the band.";
+   $expectedSegments = [
+   "I mean, in ten recording sessions, man, we didn't get 
one song...",
+   "It was the band." ];
+   // @codingStandardsIgnoreEnd
+   $segments = Segmenter::segmentSentences( $input );
+   $this->assertEquals( $expectedSegments, $segments );
+   }
+
+   public function testDontSegmentByAbbreviations() {
+   // @codingStandardsIgnoreStart
+   $input = 'Finally, at 4 a.m., Dylan called the musicians in and 
outlined the structure of the song. Dylan counted off and the musicians fell 
in, as he attempted his epic composition "Sad Eyed Lady of the Lowlands".';
+   $expectedSegments = [
+   'Finally, at 4 a.m., Dylan called the musicians in and 
outlined the structure of the song.',
+   'Dylan counted off and the musicians fell in, as he 
attempted his epic composition "Sad Eyed Lady of the Lowlands".' ];
+   // @codingStandardsIgnoreEnd
+   $segments = Segmenter::segmentSentences( $input );
+   $this->assertEquals( $expectedSegments, $segments );
+   }
+
+   public function testDontSegmentByDotDirectlyFollowedByComma() {
+   // @codingStandardsIgnoreStart
+   $input = 'Two people had strongly recommended the Hawks to 
Dylan: Mary Martin, the executive secretary of Albert Grossman, and blues 
singer John Hammond, Jr., son of record producer John Hammond, who had signed 
Dylan to Columbia Records in 1961; the Hawks had backed the younger Hammond on 
his 1965 album So Many Roads.';
+   $expectedSegments = [
+   'Two people had strongly recommended the Hawks to 
Dylan: Mary Martin, the executive secretary of Albert Grossman, and blues 
singer John Hammond, Jr., son of record producer John Hammond, who had signed 
Dylan to Columbia Records in 1961; the Hawks had backed the younger Hammond on 
his 1965 album So Many Roads.' ];
+   // @codingStandardsIgnoreEnd
+   $segments = Segmenter::segmentSentences( $input );
+   $this->assertEquals( $expectedSegments, $segments );
+   }
+
+   public function testDontRemoveStringsWithoutDots() {
+   $input = "Recording sessions\n\nBackground";
+   $expectedSegments = [ 'Recording sessions', 'Background' ];
+   $segments = Segmenter::segmentSentences( $input );
+   $this->assertEquals( $expectedSegments, $segments );
+   }
+
+   public function testSegmentParagraphs() {
+   $input = "Recording sessions
+
+Background
+After the release of Highway 61 Revisited in August 1965, Dylan set ...";
+   // @codingStandardsIgnoreStart
+   $expectedSegments = [
+   'Recording sessions',
+   'Background',
+   'After the release of Highway 61 Revisited in August 
1965, Dylan set ...' ];
+   // @codingStandardsIgnoreEnd
+   $segments = Segmenter::segmentParagraphs( $input );
+   $this->assertEquals( $expectedSegments, $segments );
+   }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: 

[MediaWiki-commits] [Gerrit] Clean HTML markup - change (mediawiki...Wikispeech)

2016-07-08 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/297979

Change subject: Clean HTML markup
..

Clean HTML markup

Added functionality for cleaning HTML from a MediaWiki article. Some tags,
like  and , have their text content kept and others, like 
and  for images, are removed altogether.

Bug: T139337
Change-Id: I48709a7e60ce8686364c151bd38b909e7219f94a
---
A includes/Cleaner.php
A tests/phpunit/CleanerTest.php
2 files changed, 236 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/79/297979/1

diff --git a/includes/Cleaner.php b/includes/Cleaner.php
new file mode 100644
index 000..dc6128f
--- /dev/null
+++ b/includes/Cleaner.php
@@ -0,0 +1,98 @@
+ null,
+   'toc' => null,
+   'table' => null,
+   'sup' => [ 'class' => 'reference' ],
+   'div' => [ 'class' => 'thumb' ],
+   'ul' => null,
+   'ol' => null
+   ];
+
+   /**
+* Clean HTML tags by removing some altogether and keeping content
+* for some.
+*
+* @since 0.0.1
+* @param string $markedUpText Input text that may contain HTML tags.
+* @return string The text with HTML tags removed/replaced with
+* contents.
+*/
+
+   public static function cleanHtmlTags( $markedUpText ) {
+   $dom = new DOMDocument();
+   // Add encoding information and wrap the input text in a dummy 
tag
+   // to prevent from p tags being added for text nodes.
+   $wrappedText = '' . $markedUpText . 
'';
+   $dom->loadHTML(
+   $wrappedText,
+   LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED );
+   $cleanedText = self::getTextContent( $dom->documentElement );
+   return $cleanedText;
+   }
+
+   /**
+* Recursively get the text from a node and its children.
+*
+* @since 0.0.1
+* @param DOMNode $node The top node to get text from.
+* @return string The cleaned text from the nodes.
+*/
+
+   private static function getTextContent( $node ) {
+   $content = '';
+   if ( !self::matchesRemove( $node ) ) {
+   foreach ( $node->childNodes as $child ) {
+   if ( $child->nodeType == XML_TEXT_NODE ) {
+   $content .= $child->textContent;
+   } else {
+   $content .= self::getTextContent( 
$child );
+   }
+   }
+   }
+   return $content;
+   }
+
+   /**
+* Check if a node matches criteria for removal.
+*
+* @since 0.0.1
+* @param DOMNode $node The node to check.
+* @return bool true if the node match removal criteria, otherwise 
false.
+*/
+
+   private static function matchesRemove( $node ) {
+   if ( !array_key_exists( $node->nodeName, self::$REMOVE_TAGS ) ) 
{
+   // The node name isn't found in the removal list.
+   return false;
+   }
+   $removeCriteria = self::$REMOVE_TAGS[ $node->nodeName ];
+   if ( $removeCriteria == null ) {
+   // Node name matches and there are no extra critera.
+   return true;
+   }
+   $classNode = $node->attributes->getNamedItem( 'class' );
+   if ( array_key_exists( 'class', $removeCriteria ) &&
+   $classNode != null
+   ) {
+   $classString = $classNode->nodeValue;
+   $nodeClasses = explode( ' ', $classString );
+   if ( in_array( $removeCriteria[ 'class' ], $nodeClasses 
) ) {
+   // Node name and class name match.
+   return true;
+   }
+   }
+   return false;
+   }
+}
diff --git a/tests/phpunit/CleanerTest.php b/tests/phpunit/CleanerTest.php
new file mode 100644
index 000..50a77a5
--- /dev/null
+++ b/tests/phpunit/CleanerTest.php
@@ -0,0 +1,138 @@
+Recording sessionsRecording sessions';
+   $expectedText = 'Recording sessions';
+   $this->assertTextCleaned(
+   'Cleaner::cleanHtmlTags',
+   $expectedText,
+   $markedUpText );
+   }
+
+   /**
+* Run several tests to ensure that the cleaning functions neither do
+* more nor less than they should. This includes: the tested string;
+* the tested string preceded and followed by strings, that should not
+* be altered; the 

[MediaWiki-commits] [Gerrit] Fix PHP testing - change (mediawiki...Wikispeech)

2016-07-04 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/297269

Change subject: Fix PHP testing
..

Fix PHP testing

Added phpcs to composer.json. Updated codesniffer version.

Change-Id: Id97189dda7ac45823966ca6667049b39fc074c33
---
M Hooks.php
M composer.json
A phpcs.xml
3 files changed, 18 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/69/297269/1

diff --git a/Hooks.php b/Hooks.php
index 423418b..bf409d7 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -15,7 +15,10 @@
 * @param ResourceLoader $resourceLoader The reference to the resource 
loader
 * @return true
 */
-   public static function onResourceLoaderTestModules( array 
&$testModules, ResourceLoader &$resourceLoader ) {
+   public static function onResourceLoaderTestModules(
+   array &$testModules,
+   ResourceLoader &$resourceLoader
+   ) {
$testModules['qunit']['ext.wikispeech.tests'] = [
'scripts' => [
'tests/Wikispeech.test.js'
@@ -28,6 +31,4 @@
];
return true;
}
-
-
 }
diff --git a/composer.json b/composer.json
index b246675..567e428 100644
--- a/composer.json
+++ b/composer.json
@@ -1,12 +1,15 @@
 {
"require-dev": {
"jakub-onderka/php-parallel-lint": "0.9",
-   "mediawiki/mediawiki-codesniffer": "0.4.0"
+   "mediawiki/mediawiki-codesniffer": "0.7.2"
},
"scripts": {
"test": [
"parallel-lint . --exclude vendor",
"phpcs -p -s"
-   ]
+   ],
+"fix": [
+"phpcbf"
+]
}
-}
\ No newline at end of file
+}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 000..d81a292
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,8 @@
+
+
+   
+   .
+   
+   
+   vendor
+

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id97189dda7ac45823966ca6667049b39fc074c33
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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


[MediaWiki-commits] [Gerrit] Clean markup - change (mediawiki...Wikispeech)

2016-06-22 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/295495

Change subject: Clean markup
..

Clean markup

Added functionality for cleaning various wikitext and HTML markup. This
should cover the most common cases with some robustness. Only headings and
text body are kept. Templates and tables are removed altogether, with
some exceptions. Links have the same string as when rendered.

Bug: T135976
Change-Id: If241ff2ce0c84044feb16458aa1a1069992ead8a
---
A Wikispeech_body.php
A tests/phpunit/Wikispeech_bodyTest.php
2 files changed, 495 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/95/295495/1

diff --git a/Wikispeech_body.php b/Wikispeech_body.php
new file mode 100644
index 000..bf587e8
--- /dev/null
+++ b/Wikispeech_body.php
@@ -0,0 +1,255 @@
+ 'Recording sessions'
+* @endcode
+*
+* @since 0.0.1
+* @param string $markedUpText A string that may contain headings.
+* @return string The string without the markup.
+*/
+
+   public static function cleanHeadings( $markedUpText ) {
+   $cleanedText = preg_replace( '/=+([^=]+)=+/s', '$1', 
$markedUpText );
+   return $cleanedText;
+   }
+
+   /**
+* Removes emphases (italic and bold) markup from a string.
+*
+* Example:
+* @code
+* "''Blonde on Blonde''" -> 'Blonde on Blonde'
+* @endcode
+*
+* @since 0.0.1
+* @param string $markedUpText A string that may contain empahses.
+* @return string The string without markup.
+*/
+
+   public static function cleanEmphases( $markedUpText ) {
+   $cleanedText = preg_replace(
+   "/((''')?('')?)(.+?)\\1/",
+   '$4',
+   $markedUpText );
+   return $cleanedText;
+   }
+
+   /**
+* Removes links markup from a string.
+*
+* Example:
+* @code
+* '[[singer-songwriter]]' -> 'singer-songwriter'
+* @endcode
+*
+* @since 0.0.1
+* @param string $markedUpText A string that may contain links.
+* @return string The string without markup.
+*/
+
+   public static function cleanLinks( $markedUpText ) {
+   $cleanedText = preg_replace(
+   '!\[(\[(([^\|]+)|(.+\|(.+)))\]|(https?:)?//[^ ]+ 
(.+)|(https?:)?//.+)\]!U',
+   '$3$5$7',
+   $markedUpText );
+   return $cleanedText;
+   }
+
+   /**
+* Removes wiki templates from a string.
+*
+* Example:
+* @code
+* '{{harvnb|Gray|2006|p62}}'
+* @endcode
+*
+* @since 0.0.1
+* @param string $markedUpText A string that may contain wiki templates.
+* @return string The string without markup.
+*/
+
+   public static function cleanWikiTemplates( $markedUpText ) {
+   $cleanedText = $markedUpText;
+   $templateTree = self::getTreeStructure( $markedUpText, '{{', 
'}}' );
+   // If we don't iterate backwards, later node ranges won't match.
+   foreach( array_reverse( $templateTree ) as $range ) {
+   if( $range[ 'depth' ] == 0 ) {
+   $length = $range[ 'end' ] - $range[ 'start' ];
+   $templateString = substr(
+   $cleanedText,
+   $range[ 'start' ],
+   $length );
+   if( $templateString == "{{'}}" ) {
+   $replacementString = "'";
+   } else {
+   $replacementString = '';
+   }
+   $cleanedText = substr_replace(
+   $cleanedText,
+   $replacementString,
+   $range[ 'start' ],
+   $length );
+   }
+   }
+   return $cleanedText;
+   }
+
+   /**
+* Creates a tree sctrucutre from a string.
+*
+* @since 0.0.1
+* @param string $text A string that contains some kind tree annotation
+* of the type a(b(c))(d).
+* @param string $nodeStartExpression The expression that starts a node,
+* e.g. '('.
+* @param string $nodeEndExpression The expression that ends a node,
+* e.g. ')'.
+* @return array An array of nodes, represented as maps containing 
depth,
+* and start and end position in $text. Nodes are added in the 

[MediaWiki-commits] [Gerrit] Add composer and npm products files to gitignore - change (mediawiki...Wikispeech)

2016-06-13 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has submitted this change and it was merged.

Change subject: Add composer and npm products files to gitignore
..


Add composer and npm products files to gitignore

Change-Id: I368e1710ab954f484cc082e9e3eea2ac18869b29
---
M .gitignore
1 file changed, 5 insertions(+), 0 deletions(-)

Approvals:
  Sebastian Berlin (WMSE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/.gitignore b/.gitignore
index b25c15b..09bed2d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,6 @@
 *~
+
+composer.lock
+vendor
+
+node_modules

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I368e1710ab954f484cc082e9e3eea2ac18869b29
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil 
Gerrit-Reviewer: Sebastian Berlin (WMSE) 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] Change license to GPL 3.0 - change (mediawiki...Wikispeech)

2016-06-01 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/292092

Change subject: Change license to GPL 3.0
..

Change license to GPL 3.0

Changed the license to GPL 3.0, since this was specified in the project
application. Also added .gitignore.

Bug: T136541
Change-Id: I857bab87c6c8dd76745ae767e33632d6c162cea1
---
A .gitignore
A COPYING.txt
A CREDITS.txt
M Hooks.php
M extension.json
5 files changed, 716 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/92/292092/1

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000..b25c15b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*~
diff --git a/COPYING.txt b/COPYING.txt
new file mode 100644
index 000..4936591
--- /dev/null
+++ b/COPYING.txt
@@ -0,0 +1,683 @@
+The license text below "" applies to all files within this distribution,
+other than those that are in a directory which contains files named "LICENSE",
+"LICENSE.txt", "COPYING" or "COPYING.txt", or a subdirectory thereof. For those
+files, the license text contained in said file overrides any license
+information contained in directories of smaller depth. Alternative licenses are
+typically used for software that is provided by external parties, and merely
+packaged with this software for convenience.
+
+
+GNU GENERAL PUBLIC LICENSE
+   Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. 
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot 

[MediaWiki-commits] [Gerrit] Fix special page not found - change (mediawiki...Wikispeech)

2016-05-26 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/290923

Change subject: Fix special page not found
..

Fix special page not found

Corrected the path to the special page in extension.json.

Change-Id: I933d2228b101bb6a5fb258ab727cbf8c9c00b39c
---
M extension.json
1 file changed, 1 insertion(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/23/290923/1

diff --git a/extension.json b/extension.json
index f0ceb81..d30e197 100644
--- a/extension.json
+++ b/extension.json
@@ -16,7 +16,7 @@
 ]
 },
 "AutoloadClasses": {
-"SpecialWikispeech": "specials/SpecialPage.php",
+"SpecialWikispeech": "specials/SpecialWikispeech.php",
 "WikispeechHooks": "Hooks.php"
 },
 "ext.wikispeech": {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I933d2228b101bb6a5fb258ab727cbf8c9c00b39c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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


[MediaWiki-commits] [Gerrit] Activate localization - change (mediawiki...Wikispeech)

2016-05-26 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/290881

Change subject: Activate localization
..

Activate localization

Activated the localization as seen in
https://www.mediawiki.org/wiki/Manual:Developing_extensions#Load_the_localisation_file

Change-Id: Ic2a1ec6d5584b4d32a978108e68a378393c68b68
---
M extension.json
1 file changed, 6 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/81/290881/1

diff --git a/extension.json b/extension.json
index 68200e5..f0ceb81 100644
--- a/extension.json
+++ b/extension.json
@@ -43,5 +43,10 @@
 "ResourceLoaderTestModules": [
 "WikispeechHooks::onResourceLoaderTestModules"
 ]
+},
+"MessagesDirs": {
+"MyExtension": [
+"i18n"
+]
 }
-}
\ No newline at end of file
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic2a1ec6d5584b4d32a978108e68a378393c68b68
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikispeech
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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


[MediaWiki-commits] [Gerrit] Initialize repo using MWStew - change (mediawiki...Wikispeech)

2016-05-25 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/290666

Change subject: Initialize repo using MWStew
..

Initialize repo using MWStew

Change-Id: I66ab28182ec9a7a891ff4f97debd9d354e83c557
---
A .jscsrc
A .jshintignore
A .jshintrc
A Gruntfile.js
A Hooks.php
A Wikispeech.alias.php
A composer.json
A extension.json
A i18n/en.json
A i18n/qqq.json
A modules/ext.Wikispeech.css
A modules/ext.Wikispeech.js
A package.json
A specials/SpecialWikispeech.php
A tests/Wikispeech.test.js
A tests/Wikispeech.test.php
16 files changed, 255 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikispeech 
refs/changes/66/290666/1

diff --git a/.jscsrc b/.jscsrc
new file mode 100644
index 000..a031ea4
--- /dev/null
+++ b/.jscsrc
@@ -0,0 +1,3 @@
+{
+   "preset": "wikimedia"
+}
\ No newline at end of file
diff --git a/.jshintignore b/.jshintignore
new file mode 100644
index 000..b512c09
--- /dev/null
+++ b/.jshintignore
@@ -0,0 +1 @@
+node_modules
\ No newline at end of file
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 000..4ecb7d5
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,20 @@
+{
+   // Enforcing
+   "bitwise": true,
+   "eqeqeq": true,
+   "es3": true,
+   "latedef": true,
+   "noarg": true,
+   "nonew": true,
+   "undef": true,
+   "unused": true,
+   "strict": false,
+
+   // Environment
+   "browser": true,
+
+   "globals": {
+   "mw": false,
+   "$": false
+   }
+}
\ No newline at end of file
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 000..dd8535b
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,35 @@
+/*jshint node:true */
+module.exports = function ( grunt ) {
+   grunt.loadNpmTasks( 'grunt-contrib-jshint' );
+   grunt.loadNpmTasks( 'grunt-jsonlint' );
+   grunt.loadNpmTasks( 'grunt-banana-checker' );
+   grunt.loadNpmTasks( 'grunt-jscs' );
+
+   grunt.initConfig( {
+   jshint: {
+   options: {
+   jshintrc: true
+   },
+   all: [
+   '*.js',
+   'modules/**/*.js'
+   ]
+   },
+   jscs: {
+   src: '<%= jshint.all %>'
+   },
+   banana: {
+   all: 'i18n/'
+   },
+   jsonlint: {
+   all: [
+   '*.json',
+   '**/*.json',
+   '!node_modules/**'
+   ]
+   }
+   } );
+
+   grunt.registerTask( 'test', [ 'jshint', 'jscs', 'jsonlint', 'banana' ] 
);
+   grunt.registerTask( 'default', 'test' );
+};
\ No newline at end of file
diff --git a/Hooks.php b/Hooks.php
new file mode 100644
index 000..b80adc4
--- /dev/null
+++ b/Hooks.php
@@ -0,0 +1,33 @@
+ [
+   'tests/ext.Wikispeech.test.js'
+   ],
+   'dependencies' => [
+   'ext.wikispeech'
+   ],
+   'localBasePath' => __DIR__ . '/..',
+   'remoteExtPath' => 'Wikispeech',
+   ];
+   return true;
+   }
+
+
+}
diff --git a/Wikispeech.alias.php b/Wikispeech.alias.php
new file mode 100644
index 000..71dd9e2
--- /dev/null
+++ b/Wikispeech.alias.php
@@ -0,0 +1,12 @@
+ array( 'wikispeech' ),
+);
diff --git a/composer.json b/composer.json
new file mode 100644
index 000..b246675
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,12 @@
+{
+   "require-dev": {
+   "jakub-onderka/php-parallel-lint": "0.9",
+   "mediawiki/mediawiki-codesniffer": "0.4.0"
+   },
+   "scripts": {
+   "test": [
+   "parallel-lint . --exclude vendor",
+   "phpcs -p -s"
+   ]
+   }
+}
\ No newline at end of file
diff --git a/extension.json b/extension.json
new file mode 100644
index 000..68200e5
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,47 @@
+{
+"name": "Wikispeech",
+"version": "0.0.1",
+"author": [
+"Sebastian Berlin"
+],
+"url": "https://www.mediawiki.org/wiki/Extension:Wikispeech;,
+"namemsg": "wikispeech",
+"descriptionmsg": "wikispeech-desc",
+"license-name": "MIT",
+"type": "other",
+"manifest_version": 1,
+"MessageDirs": {
+"Wikispeech": [
+"i18n"
+]
+},
+"AutoloadClasses": {
+"SpecialWikispeech": "specials/SpecialPage.php",
+"WikispeechHooks": "Hooks.php"
+},
+"ext.wikispeech": {
+"scripts": [
+"modules/ext.wikispeech.js"
+],
+

[MediaWiki-commits] [Gerrit] api: Decode URL-encoded link text - change (labs...heritage)

2016-04-20 Thread Sebastian Berlin (WMSE) (Code Review)
Sebastian Berlin (WMSE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/284450

Change subject: api: Decode URL-encoded link text
..

api: Decode URL-encoded link text

Added decoding of URL-encoded link text in FormatHtml::prettifyUrls().

Bug: T132029
Change-Id: I239638eb8ba025add62495cf54846c0864af2a32
---
M api/includes/FormatHtml.php
1 file changed, 4 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/labs/tools/heritage 
refs/changes/50/284450/1

diff --git a/api/includes/FormatHtml.php b/api/includes/FormatHtml.php
index 8fd06cc..84d168e 100644
--- a/api/includes/FormatHtml.php
+++ b/api/includes/FormatHtml.php
@@ -112,7 +112,10 @@
 */
static function prettifyUrls($text) {
if ( preg_match( 
'/(https?:)?\/\/((\w+)\.wikipedia\.org\/w\/index\.php\?title=(.*)=(.*))/',
 $text, $m ) ) {
-   return '' . 
htmlspecialchars( $m[3] . ': ' . str_replace( '_', ' ', $m[4] ) ) . '';
+   $encodedLinkText = str_replace( '_', ' ', $m[4] );
+   $linkText = urldecode( $encodedLinkText );
+   return '' .
+   htmlspecialchars( $linkText ) . '';
} else {
// Normal text
return htmlspecialchars( $text );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I239638eb8ba025add62495cf54846c0864af2a32
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/heritage
Gerrit-Branch: master
Gerrit-Owner: Sebastian Berlin (WMSE) 

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