jenkins-bot has submitted this change and it was merged.

Change subject: Use JavaScript to detect unclosed HTML tags
......................................................................


Use JavaScript to detect unclosed HTML tags

Previous-Change-Id: I27f3456de6a6025962afef08aea6440706095947
Change-Id: I72524db89112684225721b5d9729b6fd5a8221cd
---
M MassMessage.i18n.php
M MassMessage.php
A ext.MassMessage.badhtml.js
3 files changed, 71 insertions(+), 1 deletion(-)

Approvals:
  Siebrand: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/MassMessage.i18n.php b/MassMessage.i18n.php
index e27cdc1..533153d 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..0e7faf0 100644
--- a/MassMessage.php
+++ b/MassMessage.php
@@ -73,10 +73,13 @@
        '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'
+               'jquery.ui.autocomplete',
+               'jquery.delayedBind',
        ),
        'localBasePath' => $dir,
        'remoteExtPath' => 'MassMessage',
diff --git a/ext.MassMessage.badhtml.js b/ext.MassMessage.badhtml.js
new file mode 100644
index 0000000..8b8c354
--- /dev/null
+++ b/ext.MassMessage.badhtml.js
@@ -0,0 +1,62 @@
+/**
+ * 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' ).delayedBind( 500, 'keyup', 
function( ) {
+            var code, regex, matches, tags, possibles, tag;
+            code = $.trim( $( '#mw-massmessage-form-message' ).val() );
+            if( code === '' ) {
+                return;
+            }
+
+            regex = /<.*?>/g;
+            matches = code.match(regex);
+            if( !matches.length ) {
+                return;
+            }
+
+            tags = {};
+
+            $.each(matches, function( idx, itm ) {
+                var realTag, tag;
+                //if the tag is, <..../>, it's self closing
+                if ( itm.substr( itm.length - 2, itm.length ) !== '/>' ) {
+
+                    //strip out any attributes
+                    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 {
+                        realTag = tag.substr(1, tag.length);
+                        if (tags.hasOwnProperty(realTag)) {
+                            tags[realTag]--;
+                        } else {
+                            tags[realTag] = -1;
+                        }
+                    }
+                }
+            });
+
+            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 ).text(),
+                    { tag: 'massmessage-html-warning' }  // Show only one 
notification at a time
+                );
+            }
+        });
+    });
+
+}( mediaWiki, jQuery ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I72524db89112684225721b5d9729b6fd5a8221cd
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/MassMessage
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: MZMcBride <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to