Tim Starling has uploaded a new change for review.

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

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/Hooks.php
A includes/MigrationEditPage.php
A includes/SpecialParserMigration.php
A resources/ext.parsermigration.edit.css
9 files changed, 260 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ParserMigration 
refs/changes/82/296182/1

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..18471b1
--- /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\\SpecialParserMigration": 
"includes/SpecialParserMigration.php",
+               "MediaWiki\\ParserMigration\\MigrationEditPage": 
"includes/MigrationEditPage.php",
+               "MediaWiki\\ParserMigration\\Hooks": "includes/Hooks.php"
+       },
+       "SpecialPages": {
+               "ParserMigration": 
"MediaWiki\\ParserMigration\\SpecialParserMigration"
+       },
+       "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..68eeee3
--- /dev/null
+++ b/i18n/en.json
@@ -0,0 +1,16 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Tim Starling"
+               ]
+       },
+       "parsermigration": "Parser migration tool",
+       "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..6962f9c
--- /dev/null
+++ b/i18n/qqq.json
@@ -0,0 +1,15 @@
+{
+       "@metadata": {
+               "authors": [
+                       "Tim Starling"
+               ]
+       },
+       "parsermigration": "The special page title",
+       "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/Hooks.php b/includes/Hooks.php
new file mode 100644
index 0000000..e620a0f
--- /dev/null
+++ b/includes/Hooks.php
@@ -0,0 +1,40 @@
+<?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();
+               $class = false;
+               // Non-recursive self-link
+               if ( $title->getNamespace() === NS_SPECIAL ) {
+                       list( $specialName, $subPage ) =
+                               \SpecialPageFactory::resolveAlias( 
$title->getDBkey() );
+                       if ( $specialName === 'ParserMigration' ) {
+                               $bits = explode( '/', $subPage, 2 );
+                               if ( $bits[0] === 'edit' ) {
+                                       $title = \Title::newFromText( $bits[1] 
);
+                               }
+                       }
+               }
+               if ( $out->isArticleRelated() ) {
+                       $toolbox['parsermigration'] = [
+                               'href' => \SpecialPage::getTitleFor( 
'ParserMigration',
+                                       'edit/' . $title->getPrefixedDBkey() 
)->getLocalUrl(),
+                               'text' => wfMessage( 
'parsermigration-toolbox-label' )->text(),
+                       ];
+               }
+       }
+}
diff --git a/includes/MigrationEditPage.php b/includes/MigrationEditPage.php
new file mode 100644
index 0000000..b307882
--- /dev/null
+++ b/includes/MigrationEditPage.php
@@ -0,0 +1,80 @@
+<?php
+
+namespace MediaWiki\ParserMigration;
+
+class MigrationEditPage extends \EditPage {
+       protected $special;
+
+       function __construct( \SpecialPage $special, \Article $article ) {
+               parent::__construct( $article );
+               $this->setContextTitle( $article->getTitle() );
+               $this->special = $special;
+       }
+
+       protected function getActionURL( \Title $title ) {
+               return $this->special->getPageTitle( 'edit/' . 
$title->getPrefixedDBkey() )
+                       ->getLocalURL();
+       }
+
+       public function setHeaders() {
+               global $wgOut;
+               parent::setHeaders();
+               $wgOut->setSubtitle( wfMessage( 'parsermigration-edit-subtitle' 
) );
+               $wgOut->addModuleStyles( 'ext.parsermigration.edit' );
+       }
+
+       protected function doPreviewParse( \Content $content ) {
+               global $wgUser, $wgOut;
+
+               $parserOptions = $this->getPreviewParserOptions();
+               $pstContent = $content->preSaveTransform( $this->mTitle, 
$wgUser, $parserOptions );
+               $scopedCallback = $parserOptions->setupFakeRevision(
+                       $this->mTitle, $pstContent, $wgUser );
+               $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/includes/SpecialParserMigration.php 
b/includes/SpecialParserMigration.php
new file mode 100644
index 0000000..7de7e11
--- /dev/null
+++ b/includes/SpecialParserMigration.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace MediaWiki\ParserMigration;
+
+class SpecialParserMigration extends \SpecialPage {
+       function __construct() {
+               parent::__construct( 'ParserMigration' );
+       }
+
+       function execute( $subPage ) {
+               $this->setHeaders();
+               $parts = explode( '/', $subPage, 2 );
+               if ( !count( $parts ) ) {
+                       $action = 'intro';
+               } else {
+                       $action = $parts[0];
+               }
+               $path = isset( $parts[1] ) ? $parts[1] : '';
+
+               switch ( $action ) {
+               case 'edit':
+                       $this->edit( $path );
+                       break;
+               default:
+                       $this->getOutput()->addHTML( 'Not implemented' );
+                       break;
+               }
+       }
+
+       function edit( $subPage ) {
+               $out = $this->getOutput();
+               $title = \Title::newFromText( $subPage );
+               if ( !$title ) {
+                       $out->addWikiMsg( 'badtitle' );
+                       return;
+               }
+               $article = new \Article( $title );
+               $page = new MigrationEditPage( $this, $article );
+               $page->edit();
+       }
+}
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: newchange
Gerrit-Change-Id: I24d0776a933fa3fc4c6088dcf5b13bdb71a85cd6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ParserMigration
Gerrit-Branch: master
Gerrit-Owner: Tim Starling <[email protected]>

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

Reply via email to