Euvl has uploaded a new change for review. https://gerrit.wikimedia.org/r/83228
Change subject: Ability to turn off the recognition of glossary terms in certain places(Lingo). Phase 2: visual interface for turning off in (involves JS) ...................................................................... Ability to turn off the recognition of glossary terms in certain places(Lingo). Phase 2: visual interface for turning off in (involves JS) Change-Id: I85bcc25f6c31874041014ce1893aa5e2068640be --- M LingoElement.php M libs/Lingo.js M skins/Lingo.css A skins/removeicon.png 4 files changed, 64 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Lingo refs/changes/28/83228/1 diff --git a/LingoElement.php b/LingoElement.php index a153470..67c041d 100644 --- a/LingoElement.php +++ b/LingoElement.php @@ -138,10 +138,14 @@ $spanDefinitionInner->appendChild( $element ); } + $spanDefinitionInner->appendChild( $this->getDeleteButton( $doc, $this->mTerm ) ); + // insert term and definition $span->appendChild( $spanTerm ); $span->appendChild( $spanDefinitionOuter ); + $spanDefinitionOuter->appendChild( $spanDefinitionInner ); + $this->mFullDefinition = $span; } @@ -193,4 +197,13 @@ return self::$mLinkTemplate->cloneNode( true ); } + private function getDeleteButton( DOMDocument &$doc, $term ) { + + $link = $doc->createElement( 'span', "" ); + $link->setAttribute( 'class', 'deleteButton' ); + $link->setAttribute( 'id', $term ); + + return $link; + } + } diff --git a/libs/Lingo.js b/libs/Lingo.js index 6dae13e..d7a5f47 100644 --- a/libs/Lingo.js +++ b/libs/Lingo.js @@ -215,7 +215,50 @@ } $( this ).parent().fadeOut( 200 ); - } ); + } ) + .find( '.deleteButton' ) + .click( function ( event ) { + event.stopImmediatePropagation(); + + $.getJSON( mw.util.wikiScript( 'api' ), { + format: 'json', + action: 'query', + titles: mw.config.get( 'wgPageName' ), + prop: 'revisions', + rvprop: 'content' + } ).done( function ( data ) { + + var editToken = mw.user.tokens.get( 'editToken' ); + var term = event.target.id; + var text = data.query.pages[1].revisions[0]["*"]; + var new_text = text.replace(term, "<noglossary>" + term + "</noglossary>"); + + $.ajax( { + url: mw.util.wikiScript( 'api' ), + data: { + format: 'json', + action: 'edit', + title: mw.config.get( 'wgPageName' ), + summary: data.query.pages[1].title, + text: new_text + ' + ' + Date.now(), + token: editToken + }, + dataType: 'json', + type: 'POST', + success: function( data ) { + + if ( data && data.edit && data.edit.result == 'Success' ) { + window.location.reload(); + } else { + alert( 'Error: API returned error code ' + data.error.code ); + } + }, + error: function( xhr ) { + alert( 'Error: Request failed.' ); + } + } ); + } ); + } ); } ); }( jQuery, mediaWiki ) ); diff --git a/skins/Lingo.css b/skins/Lingo.css index e8631e1..bb6c8a8 100644 --- a/skins/Lingo.css +++ b/skins/Lingo.css @@ -62,3 +62,10 @@ .tooltip:hover .tooltip_tipwrapper { display: block; } + +.deleteButton { + cursor: pointer; + background: url("removeicon.png") no-repeat center; + width: 16px; + height: 16px; +} diff --git a/skins/removeicon.png b/skins/removeicon.png new file mode 100644 index 0000000..dff9b9d --- /dev/null +++ b/skins/removeicon.png Binary files differ -- To view, visit https://gerrit.wikimedia.org/r/83228 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I85bcc25f6c31874041014ce1893aa5e2068640be Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Lingo Gerrit-Branch: master Gerrit-Owner: Euvl <eu.vlase...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits