Tim Starling has submitted this change and it was merged.

Change subject: Initial commit
......................................................................


Initial commit

Initial commit for upstream. More or less functional side-by-side
preview tool with user preference and toolbar link.

Depends-On: I3eee8a1ef3007353ba8b129d968d9f4e4d40ef5d
Change-Id: I24d0776a933fa3fc4c6088dcf5b13bdb71a85cd6
---
A .gitignore
A .gitreview
A extension.json
A i18n/en.json
A i18n/qqq.json
A includes/EditAction.php
A includes/Hooks.php
A includes/MigrationEditPage.php
A resources/ext.parsermigration.edit.css
9 files changed, 226 insertions(+), 0 deletions(-)

Approvals:
  Tim Starling: Verified; Looks good to me, approved



diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..98b092a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.svn
+*~
+*.kate-swp
+.*.swp
diff --git a/.gitreview b/.gitreview
new file mode 100644
index 0000000..5b7515d
--- /dev/null
+++ b/.gitreview
@@ -0,0 +1,6 @@
+[gerrit]
+host=gerrit.wikimedia.org
+port=29418
+project=mediawiki/extensions/ParserMigration.git
+defaultbranch=master
+defaultrebase=0
diff --git a/extension.json b/extension.json
new file mode 100644
index 0000000..0f9c888
--- /dev/null
+++ b/extension.json
@@ -0,0 +1,38 @@
+{
+       "name": "ParserMigration",
+       "author": "Tim Starling",
+       "version": "1.0.0",
+       "url": "https://www.mediawiki.org/wiki/Extension:ParserMigration";,
+       "descriptionmsg": "parsermigration-desc",
+       "license-name": "CC0-1.0",
+       "manifest_version": 1,
+       "AutoloadClasses": {
+               "MediaWiki\\ParserMigration\\EditAction": 
"includes/EditAction.php",
+               "MediaWiki\\ParserMigration\\MigrationEditPage": 
"includes/MigrationEditPage.php",
+               "MediaWiki\\ParserMigration\\Hooks": "includes/Hooks.php"
+       },
+       "Actions": {
+               "parsermigration-edit": "MediaWiki\\ParserMigration\\EditAction"
+       },
+       "MessagesDirs": {
+               "ParserMigration": "i18n"
+       },
+       "config": {
+               "ParserMigrationTidiers": []
+       },
+       "ResourceFileModulePaths": {
+               "localBasePath": "resources"
+       },
+       "ResourceModules": {
+               "ext.parsermigration.edit": {
+                       "styles": "ext.parsermigration.edit.css"
+               }
+       },
+       "DefaultUserOptions": {
+               "parsermigration": "0"
+       },
+       "Hooks": {
+               "GetPreferences": 
"MediaWiki\\ParserMigration\\Hooks::onGetPreferences",
+               "BaseTemplateToolbox": 
"MediaWiki\\ParserMigration\\Hooks::onBaseTemplateToolbox"
+       }
+}
diff --git a/i18n/en.json b/i18n/en.json
new file mode 100644
index 0000000..6e0a2a9
--- /dev/null
+++ b/i18n/en.json
@@ -0,0 +1,15 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Tim Starling"
+               ]
+       },
+       "parsermigration-desc": "Parser migration tool",
+       "parsermigration-edit-subtitle": "with parser migration tool",
+       "parsermigration-current": "Current",
+       "parsermigration-new": "New",
+       "parsermigration-pref-label": "Enable parser migration tool",
+       "parsermigration-pref-help": "This adds a sidebar link giving access to 
[https://www.mediawiki.org/wiki/Extension:ParserMigration a tool] for migrating 
article text to new versions of the MediaWiki parser.",
+       "parsermigration-toolbox-label": "Edit with migration tool"
+
+}
diff --git a/i18n/qqq.json b/i18n/qqq.json
new file mode 100644
index 0000000..dfcf198
--- /dev/null
+++ b/i18n/qqq.json
@@ -0,0 +1,14 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Tim Starling"
+               ]
+       },
+       "parsermigration-desc": "The Special:Version extension description",
+       "parsermigration-edit-subtitle": "A subtitle shown below the h1 when 
editing a page with the tool",
+       "parsermigration-current": "The column heading for the article HTML as 
shown by the current parser",
+       "parsermigration-new": "The column heading for the article HTML as 
shown by the \"new\" parser",
+       "parsermigration-pref-label": "The user preference label for a checkbox 
which enables the feature",
+       "parsermigration-pref-help": "Help text for the user preference 
checkbox",
+       "parsermigration-toolbox-label": "The text of the toolbox link, which 
allows the user to edit the page with a special user interface."
+}
diff --git a/includes/EditAction.php b/includes/EditAction.php
new file mode 100644
index 0000000..dd06452
--- /dev/null
+++ b/includes/EditAction.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace MediaWiki\ParserMigration;
+
+class EditAction extends \FormlessAction {
+       public function getName() {
+               return 'parsermigration-edit';
+       }
+
+       protected function getDescription() {
+               return wfMessage( 'parsermigration-edit-subtitle' );
+       }
+
+       public function onView() {
+               $article = new \Article( $this->getTitle() );
+               $page = new MigrationEditPage( $this->getContext(), 
$this->getTitle() );
+               $page->edit();
+               return null;
+       }
+}
diff --git a/includes/Hooks.php b/includes/Hooks.php
new file mode 100644
index 0000000..0608ff4
--- /dev/null
+++ b/includes/Hooks.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace MediaWiki\ParserMigration;
+
+class Hooks {
+       static public function onGetPreferences( $user, &$defaultPreferences ) {
+               $defaultPreferences['parsermigration'] = [
+                       'type' => 'toggle',
+                       'label-message' => 'parsermigration-pref-label',
+                       'help-message' => 'parsermigration-pref-help',
+                       'section' => 'editing/advancedediting'
+               ];
+               return true;
+       }
+
+       static public function onBaseTemplateToolbox( &$template, &$toolbox ) {
+               $skin = $template->getSkin();
+               $out = $skin->getOutput();
+               $title = $skin->getTitle();
+               if ( $out->isArticleRelated() ) {
+                       $toolbox['parsermigration'] = [
+                               'href' => $title->getLocalUrl( [ 'action' => 
'parsermigration-edit' ] ),
+                               'text' => wfMessage( 
'parsermigration-toolbox-label' )->text(),
+                       ];
+               }
+       }
+}
diff --git a/includes/MigrationEditPage.php b/includes/MigrationEditPage.php
new file mode 100644
index 0000000..4f8aa61
--- /dev/null
+++ b/includes/MigrationEditPage.php
@@ -0,0 +1,82 @@
+<?php
+
+namespace MediaWiki\ParserMigration;
+
+class MigrationEditPage extends \EditPage {
+       protected $pmContext;
+
+       public function __construct( \IContextSource $context, \Title $title ) {
+               $article = new \Article( $title );
+               parent::__construct( $article );
+               $this->setContextTitle( $title );
+               $this->pmContext = $context;
+       }
+
+       protected function getActionURL( \Title $title ) {
+               return $title->getLocalUrl( [ 'action' => 
'parsermigration-edit' ] );
+       }
+
+       public function setHeaders() {
+               parent::setHeaders();
+               $out = $this->pmContext->getOutput();
+               $out->addModules( 'ext.parsermigration.edit' );
+       }
+
+       protected function previewOnOpen() {
+               return true;
+       }
+
+       protected function doPreviewParse( \Content $content ) {
+               $user = $this->pmContext->getUser();
+               $parserOptions = $this->getPreviewParserOptions();
+               $pstContent = $content->preSaveTransform( $this->mTitle, $user, 
$parserOptions );
+               $scopedCallback = $parserOptions->setupFakeRevision(
+                       $this->mTitle, $pstContent, $user );
+               $parserOutput = $pstContent->getParserOutput( $this->mTitle, 
null, $parserOptions );
+               \ScopedCallback::consume( $scopedCallback );
+
+               $parserOutput->setEditSectionTokens( false ); // no section 
edit links
+
+               $tidiers = \RequestContext::getMain()->getConfig()->get( 
'ParserMigrationTidiers' );
+               if ( !is_array( $tidiers ) || !isset( $tidiers[0] ) || !isset( 
$tidiers[1] ) ) {
+                       throw new \Exception( '$wgParserMigrationTidiers must 
have at least two elements' );
+               }
+               $leftOutput = $this->tidyParserOutput( $parserOutput, 
$tidiers[0] );
+               $rightOutput = $this->tidyParserOutput( $parserOutput, 
$tidiers[1] );
+               $previewHTML = "<table 
class=\"mw-parsermigration-sxs\"><tbody><tr>\n" .
+                       "<th>" . wfMessage( 'parsermigration-current' 
)->parse() . "</th>\n" .
+                       "<th>" . wfMessage( 'parsermigration-new' )->parse() . 
"</th>\n" .
+                       "</tr><tr>\n" .
+                       "<td class=\"mw-parsermigration-left\">\n\n" .
+                       $leftOutput->getText() .
+                       "\n\n</td><td class=\"mw-parsermigration-right\">\n\n" .
+                       $rightOutput->getText() .
+                       "\n\n</td></tr></tbody></table>\n";
+
+               return [
+                       'parserOutput' => $rightOutput,
+                       'html' => $previewHTML ];
+       }
+
+       protected function tidyParserOutput( $parserOutput, $config ) {
+               switch ( $config['driver'] ) {
+                       case 'RaggettInternalHHVM':
+                               $tidier = new 
\MediaWiki\Tidy\RaggettInternalHHVM( $config );
+                               break;
+                       case 'RaggettInternalPHP':
+                               $tidier = new 
\MediaWiki\Tidy\RaggettInternalPHP( $config );
+                               break;
+                       case 'RaggettExternal':
+                               $tidier = new \MediaWiki\Tidy\RaggettExternal( 
$config );
+                               break;
+                       case 'Html5Depurate':
+                               $tidier = new \MediaWiki\Tidy\Html5Depurate( 
$config );
+                               break;
+                       default:
+                               throw new MWException( "Invalid tidy driver: 
\"{$config['driver']}\"" );
+               }
+               $newOutput = clone $parserOutput;
+               $newOutput->setText( $tidier->tidy( $newOutput->getRawText() ) 
);
+               return $newOutput;
+       }
+}
diff --git a/resources/ext.parsermigration.edit.css 
b/resources/ext.parsermigration.edit.css
new file mode 100644
index 0000000..8683c9f
--- /dev/null
+++ b/resources/ext.parsermigration.edit.css
@@ -0,0 +1,20 @@
+.mw-parsermigration-sxs {
+       width: 100%;
+       border-collapse: collapse;
+}
+
+.mw-parsermigration-left {
+       width: 50%;
+       overflow: scroll;
+       border-right: thin solid #ccc;
+}
+.mw-parsermigration-right {
+       padding-left: 0.4em;
+}
+.mw-parsermigration-sxs > tbody > tr > th {
+       border-bottom: thin solid #ccc;
+}
+.mw-parsermigration-sxs > tbody > tr > th:first-child {
+       border-right: thin solid #ccc;
+}
+

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I24d0776a933fa3fc4c6088dcf5b13bdb71a85cd6
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/ParserMigration
Gerrit-Branch: master
Gerrit-Owner: Tim Starling <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>

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

Reply via email to