Anomie has uploaded a new change for review.

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

Change subject: Rewrite error handling to avoid OutputPage::addInlineScript
......................................................................

Rewrite error handling to avoid OutputPage::addInlineScript

This is apparently unofficially deprecated, and we can do things a bit
more straightforwardly by using ParserOutput::addJsConfigVars() to
communicate the error messages to the JS.

This also takes the opportunity to move "ext.scribunto", which is mostly
about errors, to "ext.scribunto.errors".

Change-Id: I1577dab2dab1bd79cb127879de141fdbb8963aeb
---
M Scribunto.php
M common/Hooks.php
M engines/LuaSandbox/Engine.php
M engines/LuaStandalone/LuaStandaloneEngine.php
R modules/ext.scribunto.errors.css
A modules/ext.scribunto.errors.js
D modules/ext.scribunto.js
A modules/ext.scribunto.logs.css
8 files changed, 64 insertions(+), 83 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto 
refs/changes/03/186503/1

diff --git a/Scribunto.php b/Scribunto.php
index 0861049..703b994 100644
--- a/Scribunto.php
+++ b/Scribunto.php
@@ -72,7 +72,6 @@
 $wgHooks['UnitTestsList'][] = 'ScribuntoHooks::unitTestsList';
 $wgParserTestFiles[] = $dir . 'tests/engines/LuaCommon/luaParserTests.txt';
 
-$wgParserOutputHooks['ScribuntoError'] = 'ScribuntoHooks::parserOutputHook';
 $wgContentHandlers['Scribunto'] = 'ScribuntoContentHandler';
 
 $sbtpl = array(
@@ -80,18 +79,22 @@
        'remoteExtPath' => 'Scribunto/modules',
 );
 
-$wgResourceModules['ext.scribunto'] = $sbtpl + array(
-       'scripts' => 'ext.scribunto.js',
-       'styles' => 'ext.scribunto.css',
+$wgResourceModules['ext.scribunto.errors'] = $sbtpl + array(
+       'scripts' => 'ext.scribunto.errors.js',
+       'styles' => 'ext.scribunto.errors.css',
        'dependencies' => array( 'jquery.ui.dialog' ),
        'messages' => array(
                'scribunto-parser-dialog-title'
        ),
 );
+$wgResourceModules['ext.scribunto.logs'] = $sbtpl + array(
+       'styles' => 'ext.scribunto.logs.css',
+       'position' => 'top',
+);
 $wgResourceModules['ext.scribunto.edit'] = $sbtpl + array(
        'scripts' => 'ext.scribunto.edit.js',
        'styles' => 'ext.scribunto.edit.css',
-       'dependencies' => array( 'ext.scribunto', 'mediawiki.api', 
'jquery.spinner' ),
+       'dependencies' => array( 'mediawiki.api', 'jquery.spinner' ),
        'messages' => array(
                'scribunto-console-title',
                'scribunto-console-intro',
diff --git a/common/Hooks.php b/common/Hooks.php
index b34a0ee..7ddb752 100644
--- a/common/Hooks.php
+++ b/common/Hooks.php
@@ -132,14 +132,17 @@
                                );
                        }
                        $out = $parser->getOutput();
-                       if ( !isset( $out->scribunto_errors ) ) {
-                               $out->addOutputHook( 'ScribuntoError' );
-                               $out->scribunto_errors = array();
+                       $jsVars = $out->getJsConfigVars();
+                       if ( isset( $jsVars['ScribuntoErrors'] ) ) {
+                               $errors = $jsVars['ScribuntoErrors'];
+                       } else {
+                               $errors = array();
                                $parser->addTrackingCategory( 
'scribunto-common-error-category' );
+                               $out->addModules( 'ext.scribunto.errors' );
                        }
-
-                       $out->scribunto_errors[] = $html;
-                       $id = 'mw-scribunto-error-' . ( count( 
$out->scribunto_errors ) - 1 );
+                       $errors[] = $html;
+                       $out->addJsConfigVars( 'ScribuntoErrors', $errors );
+                       $id = 'mw-scribunto-error-' . ( count( $errors ) - 1 );
                        $parserError = htmlspecialchars( $e->getMessage() );
                        wfProfileOut( __METHOD__ );
 
@@ -361,24 +364,6 @@
                        $files[] = __DIR__ . '/../tests/' . $test;
                }
                return true;
-       }
-
-       /**
-        * @param OutputPage $outputPage
-        * @param ParserOutput $parserOutput
-        */
-       public static function parserOutputHook( OutputPage $outputPage, 
ParserOutput $parserOutput ) {
-               // Only run the following if we're not on mobile as 
ext.scribunto doesn't work on mobile. Bug 59808
-               if ( $outputPage->getTarget() === 'mobile' ) {
-                       return;
-               }
-
-               $outputPage->addModules( 'ext.scribunto' );
-               $outputPage->addInlineScript(
-                       'mw.loader.using("ext.scribunto", function() {' .
-                               Xml::encodeJsCall( 'mw.scribunto.setErrors', 
array( $parserOutput->scribunto_errors ) )
-                       . '});'
-               );
        }
 
        /**
diff --git a/engines/LuaSandbox/Engine.php b/engines/LuaSandbox/Engine.php
index f4107f5..0a3dce6 100644
--- a/engines/LuaSandbox/Engine.php
+++ b/engines/LuaSandbox/Engine.php
@@ -112,7 +112,7 @@
                        $output->setLimitReportData( $k, $v );
                }
                if ( isset( $data['scribunto-limitreport-logs'] ) ) {
-                       $output->addModules( 'ext.scribunto' );
+                       $output->addModules( 'ext.scribunto.logs' );
                }
        }
 
diff --git a/engines/LuaStandalone/LuaStandaloneEngine.php 
b/engines/LuaStandalone/LuaStandaloneEngine.php
index 048b148..386eae7 100644
--- a/engines/LuaStandalone/LuaStandaloneEngine.php
+++ b/engines/LuaStandalone/LuaStandaloneEngine.php
@@ -68,7 +68,7 @@
                }
                $logs = $this->getLogBuffer();
                if ( $logs !== '' ) {
-                       $output->addModules( 'ext.scribunto' );
+                       $output->addModules( 'ext.scribunto.logs' );
                        $output->setLimitReportData( 
'scribunto-limitreport-logs', $logs );
                }
        }
diff --git a/modules/ext.scribunto.css b/modules/ext.scribunto.errors.css
similarity index 63%
rename from modules/ext.scribunto.css
rename to modules/ext.scribunto.errors.css
index ee3dada..184691a 100644
--- a/modules/ext.scribunto.css
+++ b/modules/ext.scribunto.errors.css
@@ -5,8 +5,3 @@
 .scribunto-error:hover, .scribunto-error:focus {
        text-decoration: underline;
 }
-
-.scribunto-limitreport-logs {
-       margin: 0;
-       white-space: pre-wrap;
-}
diff --git a/modules/ext.scribunto.errors.js b/modules/ext.scribunto.errors.js
new file mode 100644
index 0000000..a8af58a
--- /dev/null
+++ b/modules/ext.scribunto.errors.js
@@ -0,0 +1,41 @@
+( function ( $, mw ) {
+
+       $( function () {
+               var errors = mw.config.get( 'ScribuntoErrors' ),
+                       regex = /^mw-scribunto-error-(\d+)/,
+                       $dialog = $( '<div>' );
+
+               if ( !$.isArray( errors ) ) {
+                       mw.log( 'mw.scribunto.errors: ScribuntoErrors does not 
exist in mw.config or isn\'t an array!' );
+                       errors = [];
+               }
+
+               $dialog.dialog( {
+                       title: mw.msg( 'scribunto-parser-dialog-title' ),
+                       autoOpen: false
+               } );
+
+               $( '.scribunto-error' ).each( function ( index, span ) {
+                       var errorId,
+                               matches = regex.exec( span.id );
+                       if ( matches === null ) {
+                               mw.log( 'mw.scribunto.errors: regex mismatch!' 
);
+                               return;
+                       }
+                       errorId = parseInt( matches[1], 10 );
+                       $( span ).on( 'click', function ( e ) {
+                               if ( typeof errors[ errorId ] !== 'string' ) {
+                                       mw.log( 'mw.scribunto.errors: error ' + 
matches[1] + ' not found.' );
+                                       return;
+                               }
+                               var error = errors[ errorId ];
+                               $dialog
+                                       .dialog( 'close' )
+                                       .html( error )
+                                       .dialog( 'option', 'position', [ 
e.clientX + 5, e.clientY + 5 ] )
+                                       .dialog( 'open' );
+                       } );
+               } );
+       } );
+
+} ) ( jQuery, mediaWiki );
diff --git a/modules/ext.scribunto.js b/modules/ext.scribunto.js
deleted file mode 100644
index 8cb9646..0000000
--- a/modules/ext.scribunto.js
+++ /dev/null
@@ -1,47 +0,0 @@
-( function ( $, mw ) {
-
-       var scribunto = mw.scribunto = {
-               errors: null,
-
-               setErrors: function ( errors ) {
-                       scribunto.errors = errors;
-               },
-
-               init: function () {
-                       var regex = /^mw-scribunto-error-(\d+)/,
-                               $dialog = $( '<div>' );
-
-                       $dialog.dialog( {
-                               title: mw.msg( 'scribunto-parser-dialog-title' 
),
-                               autoOpen: false
-                       } );
-
-                       $( '.scribunto-error' ).each( function ( index, span ) {
-                               var errorId,
-                                       matches = regex.exec( span.id );
-                               if ( matches === null ) {
-                                       mw.log( 'mw.scribunto.init: regex 
mismatch!' );
-                                       return;
-                               }
-                               errorId = parseInt( matches[1], 10 );
-                               $( span ).on( 'click', function ( e ) {
-                                       if ( typeof scribunto.errors[ errorId ] 
!== 'string' ) {
-                                               mw.log( 'mw.scribunto.init: 
error ' + matches[1] + ' not found, ' +
-                                                       'mw.loader.using() 
callback may not have been called yet.' );
-                                               return;
-                                       }
-                                       var error = scribunto.errors[ errorId ];
-                                       $dialog
-                                               .dialog( 'close' )
-                                               .html( error )
-                                               .dialog( 'option', 'position', 
[ e.clientX + 5, e.clientY + 5 ] )
-                                               .dialog( 'open' );
-                               } );
-                       } );
-               }
-       };
-
-       $( mw.scribunto.init );
-
-} ) ( jQuery, mediaWiki );
-
diff --git a/modules/ext.scribunto.logs.css b/modules/ext.scribunto.logs.css
new file mode 100644
index 0000000..a115427
--- /dev/null
+++ b/modules/ext.scribunto.logs.css
@@ -0,0 +1,4 @@
+.scribunto-limitreport-logs {
+       margin: 0;
+       white-space: pre-wrap;
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1577dab2dab1bd79cb127879de141fdbb8963aeb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>

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

Reply via email to