Legoktm has uploaded a new change for review.

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

Change subject: Revert "Remove inline event handler js from charinsert"
......................................................................

Revert "Remove inline event handler js from charinsert"

This reverts commit b2f7c4c507e54dbcb1e629699ec5941ac7019660.

Bug: T129524
Change-Id: I07d89b9cdce4c27b8a7c8b374387971643de3877
(cherry picked from commit 28e0ff213d2617edc7dfdccd291393977af66f92)
---
M CharInsert.body.php
M extension.json
D modules/ext.charinsert.js
3 files changed, 24 insertions(+), 72 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CharInsert 
refs/changes/32/276932/1

diff --git a/CharInsert.body.php b/CharInsert.body.php
index 993d1c8..1702cf0 100644
--- a/CharInsert.body.php
+++ b/CharInsert.body.php
@@ -6,31 +6,10 @@
                return true;
        }
 
-       /**
-        * Things like edittools message are added to output directly,
-        * instead of using something like OutputPage::addWikiText.
-        * As a result, modules sometimes aren't transferred over.
-        */
-       public static function onBeforePageDisplay( $out ) {
-               $addModules = false;
-               $title = $out->getTitle();
-               if ( $title->isSpecial( 'Upload' ) ) {
-                       $addModules = true;
-               } else {
-                       $action = Action::getActionName( $out );
-                       if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
-                               $addModules = true;
-                       }
-               }
-               if ( $addModules ) {
-                       $out->addModules( 'ext.charinsert' );
-               }
-       }
-
        public static function charInsertHook( $data, $params, Parser $parser ) 
{
                $data = $parser->mStripState->unstripBoth( $data );
                // For mw.toolbar.insertTags()
-               $parser->getOutput()->addModules( 'ext.charinsert' );
+               $parser->getOutput()->addModules( 'mediawiki.toolbar' );
                return implode( "<br />\n",
                        array_map( 'CharInsert::charInsertLine',
                                explode( "\n", trim( $data ) ) ) );
@@ -67,18 +46,31 @@
        }
 
        public static function charInsertChar( $start, $end = '' ) {
-               $estart = self::charInsertDisplay( $start );
-               $eend = self::charInsertDisplay( $end );
-               $inline = $estart . $eend;
-
+               $estart = self::charInsertJsString( $start );
+               $eend = self::charInsertJsString( $end   );
+               if ( $eend == '' ) {
+                       $inline = self::charInsertDisplay( $start );
+               } else {
+                       $inline = self::charInsertDisplay( $start . $end );
+               }
                return Xml::element( 'a',
                        array(
-                               'data-mw-charinsert-start' => $estart,
-                               'data-mw-charinsert-end' => $eend,
-                               'class' => 'mw-charinsert-item 
mw-charinsert-item-todo',
-                               'href' => "#"
-                       ), $inline
-               );
+                               'onclick' => 
"mw.toolbar.insertTags('$estart','$eend','');return false",
+                               'href'    => "javascript:void()" ),
+                       $inline );
+       }
+
+       public static function charInsertJsString( $text ) {
+               return strtr(
+                       self::charInsertDisplay( $text ),
+                       array(
+                               "\\"   => "\\\\",
+                               "\""   => "\\\"",
+                               "'"    => "\\'",
+                               "\r\n" => "\\n",
+                               "\r"   => "\\n",
+                               "\n"   => "\\n",
+                       ) );
        }
 
        public static function charInsertDisplay( $text ) {
diff --git a/extension.json b/extension.json
index 8522177..f8c2129 100644
--- a/extension.json
+++ b/extension.json
@@ -8,32 +8,12 @@
        "Hooks": {
                "ParserFirstCallInit": [
                        "CharInsert::onParserFirstCallInit"
-               ],
-               "BeforePageDisplay": [
-                       "CharInsert::onBeforePageDisplay"
                ]
        },
        "MessagesDirs": {
                "CharInsert": [
                        "i18n"
                ]
-       },
-       "ResourceModules": {
-               "ext.charinsert": {
-                       "scripts": [
-                               "ext.charinsert.js"
-                       ],
-                       "dependencies": [
-                               "mediawiki.toolbar"
-                       ],
-                       "targets": [
-                               "desktop"
-                       ]
-               }
-       },
-       "ResourceFileModulePaths": {
-               "localBasePath": "modules",
-               "remoteExtPath": "CharInsert/modules"
        },
        "AutoloadClasses": {
                "CharInsert": "CharInsert.body.php"
diff --git a/modules/ext.charinsert.js b/modules/ext.charinsert.js
deleted file mode 100644
index de0b4c8..0000000
--- a/modules/ext.charinsert.js
+++ /dev/null
@@ -1,20 +0,0 @@
-( function ( $, mw ) {
-       var addClickHandlers = function ( $content ) {
-               $content.find( 'a.mw-charinsert-item-todo' ).each( function () {
-                       var $elm = $( this ),
-                               start = $elm.data( 'mw-charinsert-start' ),
-                               end = $elm.data( 'mw-charinsert-end' );
-                       $elm.click( function ( e ) {
-                               e.preventDefault();
-                               mw.toolbar.insertTags( start, end, '' );
-                       } ).removeClass( 'mw-charinsert-item-todo' );
-               } );
-       };
-       // Normally <charinsert> appears outside of content area.
-       // However, we also want to catch things like live preview,
-       // so we use both the onready hook and wikipage.content.
-       $( function () {
-               addClickHandlers( $( document ) );
-       } );
-       mw.hook( 'wikipage.content' ).add( addClickHandlers );
-} )( jQuery, mediaWiki );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I07d89b9cdce4c27b8a7c8b374387971643de3877
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CharInsert
Gerrit-Branch: wmf/1.27.0-wmf.16
Gerrit-Owner: Legoktm <[email protected]>

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

Reply via email to