Pwirth has uploaded a new change for review.

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

Change subject: BsVisualEditor: Fixed error handling for save button
......................................................................

BsVisualEditor: Fixed error handling for save button

* Fixed return value and improved processing
* Fixed plugin error handling for "fail" return
* Added TODO's - This shloud be an API call anyway

Change-Id: Ia6335ae0a3faee3fcaca9a8c6e7633a6daa48023
---
M VisualEditor/VisualEditor.class.php
M VisualEditor/resources/tiny_mce_plugins/bsactions/plugin.js
2 files changed, 43 insertions(+), 24 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions 
refs/changes/11/199611/1

diff --git a/VisualEditor/VisualEditor.class.php 
b/VisualEditor/VisualEditor.class.php
index 792ff58..7fcc8aa 100644
--- a/VisualEditor/VisualEditor.class.php
+++ b/VisualEditor/VisualEditor.class.php
@@ -438,14 +438,24 @@
        }
 
        /**
-        *
+        * PW(25.03.2015) TODO: Use API
         * @global User $wgUser
         * @global Language $wgLang
         * @return string
         */
        public static function doSaveArticle() {
-               if (BsCore::checkAccessAdmission('read') === false)
-                       return true;
+               $aResult = $aOutput = array(
+                       'saveresult' => 'fail',
+                       'message' => '',
+                       'edittime' => '',
+                       'summary' => '',
+                       'starttime' => wfTimestamp(TS_MW, time() + 2),
+               );
+               if (BsCore::checkAccessAdmission('read') === false) {
+                       $aResult['message'] = wfMessage( 'bs-permissionerror' 
)->plain();
+                       return FormatJson::encode( $aResult );
+               }
+
                global $wgLang, $wgRequest;
                $sArticleId = $wgRequest->getInt('articleId', 0);
                $sText = $wgRequest->getVal('text', '');
@@ -458,37 +468,36 @@
                        $sSummary = '/* '.wfMessage( 
'bs-visualeditor-no-summary' )->plain().' */';
                }
 
-               $oArticle = Article::newFromID($sArticleId);
-               if ( $oArticle === null ) {
-                       $oArticle = new Article(Title::newFromText($sPageName));
+               //PW(25.03.2015) TODO: Use Wikipage
+               $oArticle = Article::newFromID( $sArticleId );
+               if( is_null($oArticle) ) {
+                       $oTitle = Title::newFromText( $sPageName );
+                       if( is_null($oTitle) || !$oTitle->exists() ) {
+                               $aResult['message'] = wfMessage( 'badtitle' 
)->plain();
+                               return FormatJson::encode( $aResult );
+                       }
+                       $oArticle = new Article( $oTitle );
                }
 
                if ($iSection) {
                        $sText = $oArticle->replaceSection($iSection, $sText);
                }
 
+               //PW(25.03.2015) TODO: Deprecated since MW 1.21 use
+               //Wikipage::doEditContent instead
                $oSaveResult = $oArticle->doEdit($sText, $sSummary);
 
-               $sTime = $wgLang->timeanddate($sReturnEditTime, true);
-               $sMessage = '';
-               $sResult = '';
-               if (empty($oSaveResult->errors)) {
-                       $sResult = 'ok';
-                       $sMessage = wfMessage( 'bs-visualeditor-save-message', 
$sTime, $sSummary )->plain();
+               if( $oSaveResult->isGood() ) {
+                       $sTime = $wgLang->timeanddate($sReturnEditTime, true);
+                       $aResult['edittime'] = $sReturnEditTime;
+                       $aResult['saveresult'] = 'ok';
+                       $aResult['message'] = wfMessage( 
'bs-visualeditor-save-message', $sTime, $sSummary )->plain();
+                       $aResult['summary'] = $sSummary;
                } else {
-                       $sResult = 'fail';
-                       $sMessage = $oSaveResult->getMessage();
+                       $aResult['message'] = 
$oSaveResult->getMessage()->plain();
                }
 
-               $aOutput = array(
-                       'saveresult' => $sResult, 
//$oSaveResult->getMessage(),//$sSaveResultCode,
-                       'message' => $sMessage, //wfMessage( 
'bs-visualeditor-save-message', $sTime, $sSummary )->plain(),
-                       'edittime' => $sReturnEditTime,
-                       'summary' => $sSummary,
-                       'starttime' => wfTimestamp(TS_MW, time() + 2)
-               );
-
-               return FormatJson::encode($aOutput);
+               return FormatJson::encode( $aResult );
        }
 
        public static function checkLinks($links) {
diff --git a/VisualEditor/resources/tiny_mce_plugins/bsactions/plugin.js 
b/VisualEditor/resources/tiny_mce_plugins/bsactions/plugin.js
index ebdd429..9f6a1c7 100644
--- a/VisualEditor/resources/tiny_mce_plugins/bsactions/plugin.js
+++ b/VisualEditor/resources/tiny_mce_plugins/bsactions/plugin.js
@@ -86,7 +86,7 @@
 
                text = tinyMCE.activeEditor.getContent({save: true});
 
-               if (text === '') {
+               if ( typeof text === 'undefined' || text === '') {
                        return; // @todo Nothing to save. Disable button 
instead.
                }
 
@@ -113,6 +113,7 @@
                ajaxUrl = 
bs.util.getAjaxDispatcherUrl('VisualEditor::doSaveArticle');
 
                $(document).trigger('BSVisualEditorBeforeArticleSave', [this, 
ajaxParams, ajaxUrl]);
+
                Ext.Ajax.request({
                        method: 'post',
                        params: ajaxParams,
@@ -120,6 +121,15 @@
                        success: function(response, opts) {
                                
$(document).trigger('BSVisualEditorAfterArticleSave', [this, true, response, 
opts]);
                                var json = Ext.decode(response.responseText);
+
+                               if( typeof json.saveresult === 'undefined' || 
json.saveresult === 'fail') {
+                                       if( typeof json.message !== 'undefined' 
&& json.message !== '' ) {
+                                               mw.notify( json.message );
+                                               
$('#mw-js-message').html('<div>' + json.message + '</div>').show(); //TODO: Use 
jsMsg() or newer interfaces (message bubbles)
+                                               
$('#mw-js-message').stop().css("background-color", 
"#FFFF9C").animate({backgroundColor: "#FCFCFC"}, 1500);
+                                       }
+                                       return;
+                               }
                                $("input[name=wpEdittime]").val(json.edittime);
                                
$("input[name=wpStarttime]").val(json.starttime);
                                mw.notify( json.message );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia6335ae0a3faee3fcaca9a8c6e7633a6daa48023
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Pwirth <[email protected]>

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

Reply via email to