Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/82799
Change subject: [WIP] Use JavaScript to detect unclosed HTML tags
......................................................................
[WIP] Use JavaScript to detect unclosed HTML tags
Change-Id: I27f3456de6a6025962afef08aea6440706095947
---
M MassMessage.i18n.php
M MassMessage.php
A ext.MassMessage.badhtml.js
3 files changed, 65 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MassMessage
refs/changes/99/82799/1
diff --git a/MassMessage.i18n.php b/MassMessage.i18n.php
index e27cdc1..a7990cf 100644
--- a/MassMessage.i18n.php
+++ b/MassMessage.i18n.php
@@ -31,6 +31,7 @@
'massmessage-queued-count' => 'Queued [[Special:MassMessage|mass
messages]]',
'massmessage-hidden-comment' => '<!-- Message sent by User:$1@$2 using
the list at $3 -->',
'massmessage-optout-category' => 'Opted-out of message delivery',
+ 'massmessage-badhtml' => 'Your message may have {{PLURAL:$2|an unclosed
HTML tag|unclosed HTML tags}}: $1',
'right-massmessage' => 'Send a message to multiple users at once',
'action-massmessage' => 'send a message to multiple users at once',
'log-name-massmessage' => 'Mass message log',
@@ -82,6 +83,10 @@
'right-massmessage' => '{{doc-right|massmessage}}
See also:
* {{msg-mw|Right-massmessage-global}}',
+ 'massmessage-badhtml' => 'Shown in a JavaScript popup if we detect
unclosed HTML tags
+
+* $1 - comma separated list of unclosed HTML tags
+* $2 - number of unclosed HTML tags',
'action-massmessage' => '{{doc-action|massmessage}}',
'log-name-massmessage' => 'Log page title',
'log-description-massmessage' => 'Log page description',
diff --git a/MassMessage.php b/MassMessage.php
index 47f13a1..588307b 100644
--- a/MassMessage.php
+++ b/MassMessage.php
@@ -73,7 +73,9 @@
'scripts' => array(
'ext.MassMessage.special.js',
'ext.MassMessage.autocomplete.js',
+ 'ext.MassMessage.badhtml.js',
),
+ 'messages' => array( 'massmessage-badhtml' ),
'dependencies' => array(
'jquery.byteLimit',
'jquery.ui.autocomplete'
diff --git a/ext.MassMessage.badhtml.js b/ext.MassMessage.badhtml.js
new file mode 100644
index 0000000..28701bd
--- /dev/null
+++ b/ext.MassMessage.badhtml.js
@@ -0,0 +1,58 @@
+/**
+ * Attempt to detect invalid HTML
+ * from
http://www.raymondcamden.com/index.cfm/2012/1/23/Detecting-invalid-HTML-with-JavaScript
+ */
+( function ( mw, $ ) {
+ $( function () {
+ $( '#mw-massmessage-form-message' ).focusout( function( ) {
+ var code = $.trim( $( '#mw-massmessage-form-message' ).val() );
+ if( code == '' ) {
+ return;
+ }
+
+ var regex = /<.*?>/g;
+ var matches = code.match(regex);
+ if( !matches.length ) {
+ return;
+ }
+
+ var tags = {};
+
+ $.each(matches, function( idx, itm ) {
+
+ //if the tag is, <..../>, it's self closing
+ if ( itm.substr( itm.length - 2, itm.length ) != '/>' ) {
+
+ //strip out any attributes
+ var tag = itm.replace(/[<>]/g, '').split(' ')[0];
+ //start or end tag?
+ if ( tag.charAt(0) != '/' ) {
+ if ( tags.hasOwnProperty( tag ) ) {
+ tags[tag]++;
+ } else {
+ tags[tag] = 1;
+ }
+ } else {
+ var realTag = tag.substr(1, tag.length);
+ if (tags.hasOwnProperty(realTag)) {
+ tags[realTag]--;
+ } else {
+ tags[realTag] = -1;
+ }
+ }
+ }
+ });
+
+ var possibles = [];
+ for ( tag in tags ) {
+ if ( tags[tag] != 0 ) {
+ possibles.push( tag );
+ }
+ }
+ if (possibles.length) {
+ mw.notify( mw.message( 'massmessage-badhtml',
possibles.join(','), possibles.length).parse() );
+ }
+ });
+ });
+
+}( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/82799
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I27f3456de6a6025962afef08aea6440706095947
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits