Florianschmidtwelzow has uploaded a new change for review.

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

Change subject: WIP/POC: Add mobile preview button to EditPage
......................................................................

WIP/POC: Add mobile preview button to EditPage

On EditPage the user can click the mobile preview button to see an instant
preview of his actual changes to the site by openeing a new tab with the
parsed version of the text and in mobile version.

Change-Id: Ia735aa3d1eb978d70c28911d112dd0b5e90e7a47
---
M MobileFrontend.alias.php
M MobileFrontend.php
M i18n/en.json
M includes/MobileFrontend.hooks.php
M includes/Resources.php
A includes/specials/SpecialEditorPreview.php
A javascripts/desktop/editorPreview.js
7 files changed, 125 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/89/166089/1

diff --git a/MobileFrontend.alias.php b/MobileFrontend.alias.php
index 13e6875..281b283 100644
--- a/MobileFrontend.alias.php
+++ b/MobileFrontend.alias.php
@@ -11,6 +11,7 @@
 
 /** English (English) */
 $specialPageAliases['en'] = array(
+       'EditorPreview' => array( 'EditorPreview' ),
        'History' => array( 'History' ),
        'MobileWebApp' => array( 'MobileWebApp' ),
        'MobileOptions' => array( 'MobileOptions' ),
diff --git a/MobileFrontend.php b/MobileFrontend.php
index e9b1bb0..65781ff 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -79,6 +79,7 @@
        'SpecialNearby' => 'specials/SpecialNearby',
        'SpecialMobileLanguages' => 'specials/SpecialMobileLanguages',
        'SpecialMobileNotifications' => 'specials/SpecialMobileNotifications',
+       'SpecialEditorPreview' => 'specials/SpecialEditorPreview',
        'MobileSpecialPage' => 'specials/MobileSpecialPage',
        'MobileSpecialPageFeed' => 'specials/MobileSpecialPageFeed',
 
@@ -142,9 +143,13 @@
        'MobileFrontendHooks::onEventLoggingRegisterSchemas';
 $wgHooks['OutputPageParserOutput'][] = 
'MobileFrontendHooks::onOutputPageParserOutput';
 $wgHooks['HTMLFileCache::useFileCache'][] = 'onHTMLFileCache_useFileCache';
+$wgHooks['EditPage::showEditForm:initial'][] =
+       'MobileFrontendHooks::onEditPage_showEditForm_initial';
+$wgHooks['EditPageBeforeEditButtons'][] = 
'MobileFrontendHooks::onEditPageBeforeEditButtons';
 
 // use array_merge to ensure we do not override existing values set by core
 $wgSpecialPages = array_merge( $wgSpecialPages, array(
+       'EditorPreview' => 'SpecialEditorPreview',
        'History' => 'SpecialMobileHistory',
        'MobileDiff' => 'SpecialMobileDiff',
        'MobileEditor' => 'SpecialMobileEditor',
diff --git a/i18n/en.json b/i18n/en.json
index 8ad7700..dff4fe5 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -92,6 +92,7 @@
        "mobile-frontend-editor-viewing-source-page": "<strong>Viewing source 
of</strong><span> $1</span>",
        "mobile-frontend-editor-visual-editor": "Edit",
        "mobile-frontend-editor-wait": "Saving edit, please wait.",
+       "mobile-frontend-editorpreview-title": "Mobile preview for your Edit",
        "mobile-frontend-enable-images": "Enable images on mobile site",
        "mobile-frontend-expand-sections-description": "Always expand all 
sections when navigating to a new page.",
        "mobile-frontend-expand-sections-status": "Expand all sections",
diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index 6853ba2..80e2d83 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -910,4 +910,41 @@
        public static function onHTMLFileCache_useFileCache() {
                return !MobileContext::singleton()->shouldDisplayMobileView();
        }
+
+       /**
+        * Adds the required module for editorPreview
+        *
+        * @param EditPage $editPage
+        * @param OutputPage $output
+        */
+       public static function onEditPage_showEditForm_initial(
+               EditPage $editPage, OutputPage $output
+       ) {
+               $output->addModules( array( 'mobile.editpreview' ) );
+       }
+
+       /**
+        * Add a mobile preview button to the edit form
+        *
+        * @param EditPage $editPage: the current EditPage object
+        * @param array $buttons: the edit buttons found below the editing box
+        *  ("Save", "Preview", "Live", and "Diff")
+        * @param integer $tabindex: HTML tabindex of the last edit check/button
+        */
+       public static function onEditPageBeforeEditButtons( &$editPage, 
&$buttons, &$tabindex ) {
+               $attr = array(
+                       'type' => 'button',
+                       'value' => 'Mobile Preview',
+                       'id' => 'wpMobilePreview',
+                       'tabindex' => $tabindex + 1,
+               );
+               $buttons = array_slice( $buttons, 0, 2, true ) +
+                       array(
+                               'mobilePreview' => Html::element(
+                                       'input',
+                                       Html::buttonAttributes( $attr )
+                               )
+                       ) +
+                       array_slice( $buttons, 2, count( $buttons ) );
+       }
 }
diff --git a/includes/Resources.php b/includes/Resources.php
index 8fca9ac..77d9594 100644
--- a/includes/Resources.php
+++ b/includes/Resources.php
@@ -1106,6 +1106,14 @@
                        'javascripts/specials/mobilediff.js',
                ),
        ),
+
+       // Used for mobile preview on desktop EditPage
+       'mobile.editpreview' => $wgMFMobileResourceBoilerplate + array(
+               'scripts' => array(
+                       'javascripts/desktop/editorPreview.js'
+               ),
+               'targets' => array( 'desktop' )
+       ),
 );
 
 /**
diff --git a/includes/specials/SpecialEditorPreview.php 
b/includes/specials/SpecialEditorPreview.php
new file mode 100644
index 0000000..19a77a7
--- /dev/null
+++ b/includes/specials/SpecialEditorPreview.php
@@ -0,0 +1,55 @@
+<?php
+
+class SpecialEditorPreview extends MobileSpecialPage {
+       /**
+        * Constructor
+        */
+       public function __construct() {
+               parent::__construct( 'EditorPreview' );
+               $this->listed = false;
+       }
+
+       /**
+        * Generates this special page
+        *
+        * @param string $par The subpage
+        */
+       public function execute( $par = '' ) {
+               wfProfileIn( __METHOD__ );
+               global $wgUser, $wgContLang, $wgParserConf, $wgMFPageActions;
+
+               $out = $this->getOutput();
+               $request = $this->getRequest();
+               // get the preview text from post data
+               $previewText = $request->getVal( 'mobilePreviewText' );
+
+               // if there is no previewText or the form was not posted, go 
away to the main page
+               // FIXME: error message better?
+               if ( !$request->wasPosted() || !$previewText ) {
+                       $out->redirect( Title::newMainPage()->getLocalUrl() );
+               }
+
+               // To attempt Minerva to load page styles, we need to set a 
custom title of the main name-
+               // space (otherwise this page will be identified as a special 
page)
+               $previewTitle = Title::newFromText( 'EditorPreview' );
+               $this->getContext()->setTitle( $previewTitle );
+
+               // disable all mobile page actions
+               $wgMFPageActions = array();
+
+               // create a new parser object to parse the text
+               $parser = new Parser( $wgParserConf );
+               // parse the text of the edit form
+               $parserOutput = $parser->parse(
+                       $previewText,
+                       $previewTitle,
+                       ParserOptions::newFromUserAndLang( $wgUser, $wgContLang 
)
+               );
+
+               // set our custom title and add the ParserOutput to the HTML
+               $out->setPageTitle( $this->msg( 
'mobile-frontend-editorpreview-title' ) );
+               $out->addHtml( $parserOutput->getText() );
+
+               wfProfileOut( __METHOD__ );
+       }
+}
diff --git a/javascripts/desktop/editorPreview.js 
b/javascripts/desktop/editorPreview.js
new file mode 100644
index 0000000..9234635
--- /dev/null
+++ b/javascripts/desktop/editorPreview.js
@@ -0,0 +1,18 @@
+jQuery( function ( $ ) {
+       // FIXME: Add this to the hook adding this module
+       $( '#editform' ).after(
+               '<form action="' +
+               mw.util.getUrl( 'Special:EditorPreview' ) +
+               '?useformat=mobile" target="_blank" method="POST" 
id="editorPreviewForm" style="display:none;">' +
+               '<textarea id="mobilePreviewText" 
name="mobilePreviewText"></textarea>' +
+               '</form>'
+       );
+
+       // handle the click on the "mobile preview" button
+       $( '#wpMobilePreview' ).on( 'click', function() {
+               // transfer the content to our form
+               $( '#mobilePreviewText' ).val( $( '#wpTextbox1' ).val() );
+               // submit the form (show preview)
+               $( '#editorPreviewForm' ).submit();
+       } );
+} );
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia735aa3d1eb978d70c28911d112dd0b5e90e7a47
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.wel...@t-online.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to