[MediaWiki-commits] [Gerrit] mediawiki...Linter[master]: Support new wikitext editor for edit helper

2017-04-25 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/342279 )

Change subject: Support new wikitext editor for edit helper
..


Support new wikitext editor for edit helper

Register a hook for when VE is finished initializing to select the error
section, just like the textbox-based editor.

Use the BeforePageDisplay hook so it runs on VE page loads too.

Bug: T160102
Change-Id: I59a7e0a3e8be32e4689cbf41c4904970902c4dff
---
M .jshintrc
M extension.json
M includes/Hooks.php
M modules/ext.linter.edit.js
4 files changed, 40 insertions(+), 11 deletions(-)

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



diff --git a/.jshintrc b/.jshintrc
index 66e3d48..fa96cd8 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -19,6 +19,7 @@
 
"globals": {
"mediaWiki": false,
+   "ve": false,
"OO": false
}
 }
diff --git a/extension.json b/extension.json
index 8931304..533253f 100644
--- a/extension.json
+++ b/extension.json
@@ -26,7 +26,7 @@
},
"Hooks": {
"LoadExtensionSchemaUpdates": 
"MediaWiki\\Linter\\Hooks::onLoadExtensionSchemaUpdates",
-   "EditFormInitialText": 
"MediaWiki\\Linter\\Hooks::onEditFormInitialText",
+   "BeforePageDisplay": 
"MediaWiki\\Linter\\Hooks::onBeforePageDisplay",
"APIQuerySiteInfoGeneralInfo": 
"MediaWiki\\Linter\\Hooks::onAPIQuerySiteInfoGeneralInfo",
"InfoAction": "MediaWiki\\Linter\\Hooks::onInfoAction",
"WikiPageDeletionUpdates": 
"MediaWiki\\Linter\\Hooks::onWikiPageDeletionUpdates"
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 5626e1e..6498eeb 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -23,9 +23,9 @@
 use ApiQuerySiteInfo;
 use Content;
 use DatabaseUpdater;
-use EditPage;
 use IContextSource;
 use MWCallableUpdate;
+use OutputPage;
 use WikiPage;
 
 class Hooks {
@@ -38,21 +38,23 @@
}
 
/**
-* Hook: EditFormInitialText
+* Hook: BeforePageDisplay
 *
 * If there is a lintid parameter, look up that error in the database
 * and setup and output our client-side helpers
 *
-* @param EditPage $editPage
+* @param OutputPage &$out
 */
-   public static function onEditFormInitialText( EditPage $editPage ) {
-   $context = $editPage->getContext();
-   $request = $context->getRequest();
+   public static function onBeforePageDisplay( OutputPage &$out ) {
+   $request = $out->getRequest();
$lintId = $request->getInt( 'lintid' );
if ( !$lintId ) {
return;
}
-   $title = $editPage->getTitle();
+   $title = $out->getTitle();
+   if ( !$title ) {
+   return;
+   }
 
$lintError = ( new Database( $title->getArticleID() ) 
)->getFromId( $lintId );
if ( !$lintError ) {
@@ -60,7 +62,6 @@
return;
}
 
-   $out = $context->getOutput();
$out->addJsConfigVars( [
'wgLinterErrorCategory' => $lintError->category,
'wgLinterErrorLocation' => $lintError->location,
diff --git a/modules/ext.linter.edit.js b/modules/ext.linter.edit.js
index 5162219..fa13f98 100644
--- a/modules/ext.linter.edit.js
+++ b/modules/ext.linter.edit.js
@@ -1,8 +1,35 @@
 ( function ( mw, $ ) {
$( function () {
-   var location = mw.config.get( 'wgLinterErrorLocation' );
+   var location = mw.config.get( 'wgLinterErrorLocation' ),
+   $textbox = $( '#wpTextbox1' );
+
+   /**
+* Convert the normal offset for one that is usable
+* by VE's DOM that changes newlines into 
+*
+* @param {ve.ui.Surface} surface
+* @param {int} offset
+* @return {int}
+*/
+   function fixOffset( surface, offset ) {
+   return ( surface.getDom().slice( 0, offset ).match( 
/\n/g ) || [] ).length + 1 + offset;
+   }
+
if ( location ) {
-   $( '#wpTextbox1' ).focus().textSelection( 
'setSelection', { start: location[ 0 ], end: location[ 1 ] } );
+   if ( $textbox.length ) {
+   $textbox.focus().textSelection( 'setSelection', 
{ start: location[ 0 ], end: location[ 1 ] } );
+   }
+   // Register NWE code should it be loaded
+   // TODO: We should somehow force source mode if VE is 
opened
+   mw.hook( 've.activationComplete' ).add( function () {
+  

[MediaWiki-commits] [Gerrit] mediawiki...Linter[master]: Support new wikitext editor for edit helper

2017-03-10 Thread Legoktm (Code Review)
Legoktm has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/342279 )

Change subject: Support new wikitext editor for edit helper
..

Support new wikitext editor for edit helper

Register a hook for when VE is finished initializing to select the error
section, just like the textbox-based editor.

Use the BeforePageDisplay hook so it runs on VE page loads too.

Bug: T160102
Change-Id: I59a7e0a3e8be32e4689cbf41c4904970902c4dff
---
M .jshintrc
M extension.json
M includes/Hooks.php
M modules/ext.linter.edit.js
4 files changed, 40 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Linter 
refs/changes/79/342279/1

diff --git a/.jshintrc b/.jshintrc
index 66e3d48..fa96cd8 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -19,6 +19,7 @@
 
"globals": {
"mediaWiki": false,
+   "ve": false,
"OO": false
}
 }
diff --git a/extension.json b/extension.json
index 7d2c51b..18ee941 100644
--- a/extension.json
+++ b/extension.json
@@ -26,7 +26,7 @@
},
"Hooks": {
"LoadExtensionSchemaUpdates": 
"MediaWiki\\Linter\\Hooks::onLoadExtensionSchemaUpdates",
-   "EditFormInitialText": 
"MediaWiki\\Linter\\Hooks::onEditFormInitialText",
+   "BeforePageDisplay": 
"MediaWiki\\Linter\\Hooks::onBeforePageDisplay",
"APIQuerySiteInfoGeneralInfo": 
"MediaWiki\\Linter\\Hooks::onAPIQuerySiteInfoGeneralInfo",
"InfoAction": "MediaWiki\\Linter\\Hooks::onInfoAction",
"WikiPageDeletionUpdates": 
"MediaWiki\\Linter\\Hooks::onWikiPageDeletionUpdates"
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 5626e1e..6498eeb 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -23,9 +23,9 @@
 use ApiQuerySiteInfo;
 use Content;
 use DatabaseUpdater;
-use EditPage;
 use IContextSource;
 use MWCallableUpdate;
+use OutputPage;
 use WikiPage;
 
 class Hooks {
@@ -38,21 +38,23 @@
}
 
/**
-* Hook: EditFormInitialText
+* Hook: BeforePageDisplay
 *
 * If there is a lintid parameter, look up that error in the database
 * and setup and output our client-side helpers
 *
-* @param EditPage $editPage
+* @param OutputPage &$out
 */
-   public static function onEditFormInitialText( EditPage $editPage ) {
-   $context = $editPage->getContext();
-   $request = $context->getRequest();
+   public static function onBeforePageDisplay( OutputPage &$out ) {
+   $request = $out->getRequest();
$lintId = $request->getInt( 'lintid' );
if ( !$lintId ) {
return;
}
-   $title = $editPage->getTitle();
+   $title = $out->getTitle();
+   if ( !$title ) {
+   return;
+   }
 
$lintError = ( new Database( $title->getArticleID() ) 
)->getFromId( $lintId );
if ( !$lintError ) {
@@ -60,7 +62,6 @@
return;
}
 
-   $out = $context->getOutput();
$out->addJsConfigVars( [
'wgLinterErrorCategory' => $lintError->category,
'wgLinterErrorLocation' => $lintError->location,
diff --git a/modules/ext.linter.edit.js b/modules/ext.linter.edit.js
index 5162219..5d7c769 100644
--- a/modules/ext.linter.edit.js
+++ b/modules/ext.linter.edit.js
@@ -1,8 +1,35 @@
 ( function ( mw, $ ) {
$( function () {
-   var location = mw.config.get( 'wgLinterErrorLocation' );
+   var location = mw.config.get( 'wgLinterErrorLocation' ),
+   $textbox = $( '#wpTextbox1' );
+
+   /**
+* Convert the normal offset for one that is usable
+* by VE's DOM that changes newlines into 
+*
+* @param {ve.ui.Surface} surface
+* @param {int} offset
+* @return {int}
+*/
+   function fixOffset( surface, offset ) {
+   return ( surface.getDom().slice( 0, offset ).match( 
/\n/g ) || [] ).length + 1 + offset;
+   }
+
if ( location ) {
-   $( '#wpTextbox1' ).focus().textSelection( 
'setSelection', { start: location[ 0 ], end: location[ 1 ] } );
+   if ( $textbox.length ) {
+   $textbox.focus().textSelection( 'setSelection', 
{ start: location[ 0 ], end: location[ 1 ] } );
+   } else {
+   // Register NWE code
+   // TODO: We should somehow force source mode if 
VE is opened
+   mw.hook( 've.activationComplete' ).add( 
function () {
+