[MediaWiki-commits] [Gerrit] mediawiki...VisualEditor[master]: Enable preload in VisualEditor

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

Change subject: Enable preload in VisualEditor
..


Enable preload in VisualEditor

This allows the use of the preload and preloadparams query parameters. They
should behave as they do in the old editor, loading substituted content in
visual and source modes.

Bug: T51622
Change-Id: I522fb5b480d17912f6d6116be6aa043ead855b52
---
M ApiVisualEditor.php
M VisualEditor.hooks.php
M modules/ve-mw/i18n/en.json
M modules/ve-mw/i18n/qqq.json
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
M modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js
6 files changed, 56 insertions(+), 7 deletions(-)

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



diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php
index f479f15..2aa093a 100644
--- a/ApiVisualEditor.php
+++ b/ApiVisualEditor.php
@@ -285,6 +285,34 @@
if ( $content !== '' ) {
$content = 
$this->parseWikitextFragment( $title, $content );
}
+   if ( $content === '' && 
$params['preload'] ) {
+   $preloadTitle = 
Title::newFromText( $params['preload'] );
+   # Check for existence to avoid 
getting MediaWiki:Noarticletext
+   if ( $preloadTitle instanceof 
Title &&
+
$preloadTitle->exists() &&
+
$preloadTitle->userCan( 'read' )
+   ) {
+   $preloadPage = 
WikiPage::factory( $preloadTitle );
+   if ( 
$preloadPage->isRedirect() ) {
+   $preloadTitle = 
$preloadPage->getRedirectTarget();
+   $preloadPage = 
WikiPage::factory( $preloadTitle );
+   }
+
+   $content = 
$preloadPage->getContent( Revision::RAW );
+   $parserOptions = 
ParserOptions::newFromUser( $wgUser );
+
+   $content = 
$content->preloadTransform(
+   $preloadTitle,
+   $parserOptions,
+   
$params['preloadparams']
+   )->serialize();
+
+   if ( $params['paction'] 
!== 'wikitext' ) {
+   // We need to 
turn this transformed wikitext into parsoid html
+   $content = 
$this->parseWikitextFragment( $title, $content );
+   }
+   }
+   }
$baseTimestamp = wfTimestampNow();
$oldid = 0;
$restoring = false;
@@ -524,7 +552,10 @@
'oldid' => $oldid,
 
];
-   if ( $params['paction'] === 'parse' || 
$params['paction'] === 'wikitext' ) {
+   if ( $params['paction'] === 'parse' ||
+$params['paction'] === 'wikitext' ||
+$params['preload']
+   ) {
$result['content'] = $content;
}
break;
@@ -657,6 +688,8 @@
'oldid' => null,
'editintro' => null,
'pst' => false,
+   'preload' => null,
+   'preloadparams' => null,
];
}
 
diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php
index af932c1..c3b1aa6 100644
--- a/VisualEditor.hooks.php
+++ b/VisualEditor.hooks.php
@@ -16,8 +16,6 @@
// TODO: Other params too?
// Known-good parameters: edit, veaction, section, oldid, lintid
private static $unsupportedEditParams = [
-   'preload',
-   'preloadparams',
'preloadtitle',
 

[MediaWiki-commits] [Gerrit] mediawiki...VisualEditor[master]: Enable preload in VisualEditor

2017-09-15 Thread DLynch (Code Review)
DLynch has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/378343 )

Change subject: Enable preload in VisualEditor
..

Enable preload in VisualEditor

This allows the use of the preload and preloadparams query parameters. They
should behave as they do in the old editor, loading substituted content in
visual and source modes.

Bug: T51622
Change-Id: I522fb5b480d17912f6d6116be6aa043ead855b52
---
M ApiVisualEditor.php
M VisualEditor.hooks.php
M modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
M modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js
4 files changed, 43 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/43/378343/1

diff --git a/ApiVisualEditor.php b/ApiVisualEditor.php
index f479f15..6ab6425 100644
--- a/ApiVisualEditor.php
+++ b/ApiVisualEditor.php
@@ -285,6 +285,28 @@
if ( $content !== '' ) {
$content = 
$this->parseWikitextFragment( $title, $content );
}
+   if ( $content === '' && 
$params['preload'] ) {
+   $preloadTitle = 
Title::newFromText( $params['preload'] );
+   # Check for existence to avoid 
getting MediaWiki:Noarticletext
+   if ( $preloadTitle instanceof 
Title && $preloadTitle->exists() && $preloadTitle->userCan( 'read' ) ) {
+
+   $preloadPage = 
WikiPage::factory( $preloadTitle );
+   if ( 
$preloadPage->isRedirect() ) {
+   $preloadTitle = 
$preloadPage->getRedirectTarget();
+   $preloadPage = 
WikiPage::factory( $preloadTitle );
+   }
+
+   $content = 
$preloadPage->getContent( Revision::RAW );
+   $parserOptions = 
ParserOptions::newFromUser( $wgUser );
+
+   $content = 
$content->preloadTransform( $preloadTitle, $parserOptions, 
$params['preloadparams'] )->serialize();
+
+   if ( $params['paction'] 
!== 'wikitext' ) {
+   // We need to 
turn this transformed wikitext into parsoid html
+   $content = 
$this->parseWikitextFragment( $title, $content );
+   }
+   }
+   }
$baseTimestamp = wfTimestampNow();
$oldid = 0;
$restoring = false;
@@ -524,7 +546,7 @@
'oldid' => $oldid,
 
];
-   if ( $params['paction'] === 'parse' || 
$params['paction'] === 'wikitext' ) {
+   if ( $params['paction'] === 'parse' || 
$params['paction'] === 'wikitext' || $params['preload'] ) {
$result['content'] = $content;
}
break;
@@ -657,6 +679,8 @@
'oldid' => null,
'editintro' => null,
'pst' => false,
+   'preload' => null,
+   'preloadparams' => null,
];
}
 
diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php
index af932c1..c3b1aa6 100644
--- a/VisualEditor.hooks.php
+++ b/VisualEditor.hooks.php
@@ -16,8 +16,6 @@
// TODO: Other params too?
// Known-good parameters: edit, veaction, section, oldid, lintid
private static $unsupportedEditParams = [
-   'preload',
-   'preloadparams',
'preloadtitle',
'undo',
'undoafter',
diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js 
b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
index 0f79fb8..41dd4b7 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js
@@ -251,6 +251,8 @@
oldId: oldId,
targetName: 'article', // 
ve.init.mw.DesktopArticleTarget.static.name