Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/83064
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(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MassMessage
refs/changes/64/83064/1
diff --git a/MassMessage.i18n.php b/MassMessage.i18n.php
index e27cdc1..ffe8260 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 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..f9f0e44
--- /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(', ')
).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: newchange
Gerrit-Change-Id: I72524db89112684225721b5d9729b6fd5a8221cd
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