Foxtrott has submitted this change and it was merged.

Change subject: Enable diff operation; 2 minor bugfixes
......................................................................


Enable diff operation; 2 minor bugfixes

* followup Ifa72f031b: re-enables the diff operation
* bugfix in SFUtils::getPageText: do not access null as object
* bugfix in SFFormPrinter::formHTML: increase instance num of multiple instances

Change-Id: I3e41aadd62cc7fcbe0d64bb1c0aefe0fa540db5d
---
M includes/SF_AutoeditAPI.php
M includes/SF_FormPrinter.php
M includes/SF_Utils.php
M specials/SF_FormEdit.php
4 files changed, 56 insertions(+), 20 deletions(-)

Approvals:
  Foxtrott: Verified; Looks good to me, approved
  jenkins-bot: Checked



diff --git a/includes/SF_AutoeditAPI.php b/includes/SF_AutoeditAPI.php
index 9097f23..f48e2b7 100644
--- a/includes/SF_AutoeditAPI.php
+++ b/includes/SF_AutoeditAPI.php
@@ -14,9 +14,10 @@
  */
 class SFAutoeditAPI extends ApiBase {
 
-       const ACTION_SAVE = 0;
-       const ACTION_PREVIEW = 1;
-       const ACTION_FORMEDIT = 2;
+       const ACTION_FORMEDIT = 0;
+       const ACTION_SAVE = 1;
+       const ACTION_PREVIEW = 2;
+       const ACTION_DIFF = 3;
 
        /**
         * Error level used when a non-recoverable error occured.
@@ -162,6 +163,11 @@
                        // set action to 'preview' if requested
                        $this->mAction = self::ACTION_PREVIEW;
                        unset( $this->mOptions[ 'wpPreview' ] );
+               } else if ( array_key_exists( 'wpDiff', $this->mOptions ) ) {
+
+                       // set action to 'preview' if requested
+                       $this->mAction = self::ACTION_DIFF;
+                       unset( $this->mOptions[ 'wpDiff' ] );
                } else if ( array_key_exists( 'action', $this->mOptions ) ) {
 
                        switch ( $this->mOptions[ 'action' ] ) {
@@ -318,6 +324,30 @@
                return $editor;
        }
 
+       /**
+        * Sets the output HTML of wgOut as the module's result
+        */
+       protected function setResultFromOutput() {
+
+               global $wgOut;
+
+               // turn on output buffering
+               ob_start();
+
+               // generate preview document and write it to output buffer
+               $wgOut->output();
+
+               // retrieve the preview document from output buffer
+               $targetHtml = ob_get_contents();
+
+               // clean output buffer, so MW can use it again
+               ob_clean();
+
+               // store the document as result
+               $this->getResult()->addValue( null, 'result', $targetHtml );
+
+       }
+
        protected function doPreview( $editor ) {
 
                global $wgOut;
@@ -335,20 +365,13 @@
 
                $wgOut->addHTML( Html::rawElement( 'div', array( 'id' => 
'wikiPreview' ), $previewOutput ) );
 
-               // turn on output buffering
-               ob_start();
+               $this->setResultFromOutput();
 
-               // generate preview document and write it to output buffer
-               $wgOut->output();
+       }
 
-               // retrieve the preview document from output buffer
-               $targetHtml = ob_get_contents();
-
-               // clean output buffer, so MW can use it again
-               ob_clean();
-
-               // store the document as result
-               $this->getResult()->addValue( null, 'result', $targetHtml );
+       protected function doDiff( $editor ) {
+               $editor->showDiff();
+               $this->setResultFromOutput();
        }
 
        protected function doStore( EditPage $editor ) {
@@ -700,7 +723,7 @@
 
                // signals that the form was submitted
                // always true, else we would not be here
-               $isFormSubmitted = $this->mAction === self::ACTION_SAVE || 
$this->mAction === self::ACTION_PREVIEW;
+               $isFormSubmitted = $this->mAction === self::ACTION_SAVE || 
$this->mAction === self::ACTION_PREVIEW || $this->mAction === self::ACTION_DIFF;
 
                // the article id of the form to be used
                $formArticleId = $formTitle->getArticleID();
@@ -786,7 +809,7 @@
                }
 
                // we already preloaded stuff for saving/previewing, do not do 
it again
-               if ( $this->mAction === self::ACTION_SAVE || $this->mAction === 
self::ACTION_PREVIEW ) {
+               if ( $isFormSubmitted ) {
                        $preloadContent = '';
                        $isPageSource = false;
                }
@@ -809,7 +832,7 @@
                $this->mOptions[ 'formHTML' ] = $formHTML;
                $this->mOptions[ 'formJS' ] = $formJS;
                
-               if ( $this->mAction === self::ACTION_SAVE || $this->mAction === 
self::ACTION_PREVIEW ) {
+               if ( $isFormSubmitted ) {
 
                        // if the target page was not specified, see if 
something was generated
                        // from the target name formula
@@ -831,6 +854,8 @@
                        // perform the requested action
                        if ( $this->mAction === self::ACTION_PREVIEW ) {
                                $this->doPreview( $editor );
+                       } else if ( $this->mAction === self::ACTION_DIFF ) {
+                               $this->doDiff( $editor );
                        } else {
                                $this->doStore( $editor );
                        }
diff --git a/includes/SF_FormPrinter.php b/includes/SF_FormPrinter.php
index 3b4856d..d78b520 100644
--- a/includes/SF_FormPrinter.php
+++ b/includes/SF_FormPrinter.php
@@ -1470,6 +1470,7 @@
                                        // This will cause the section to be
                                        // re-parsed on the next go.
                                        $section_num--;
+                                       $instance_num++;
                                }
                        } else { // if ( $allow_multiple ) {
                                $form_text .= $section;
diff --git a/includes/SF_Utils.php b/includes/SF_Utils.php
index 6fcb076..e4bb6b7 100644
--- a/includes/SF_Utils.php
+++ b/includes/SF_Utils.php
@@ -59,7 +59,13 @@
                if ( method_exists( 'WikiPage', 'getContent' ) ) {
                        // MW 1.21+
                        $wikiPage = new WikiPage( $title );
-                       return $wikiPage->getContent()->getNativeData();
+                       $content = $wikiPage->getContent();
+
+                       if ( $content !== null ) {
+                               return $content->getNativeData();
+                       } else {
+                               return null;
+                       }
                } else {
                        // MW <= 1.20
                        $article = new Article( $title );
diff --git a/specials/SF_FormEdit.php b/specials/SF_FormEdit.php
index b94e80e..2563edc 100644
--- a/specials/SF_FormEdit.php
+++ b/specials/SF_FormEdit.php
@@ -74,7 +74,11 @@
                $module->setOption( 'target', $target_name );
 
                // if the page was submitted, formdata should be complete => do 
not preload
-               $module->setOption( 'preload', !$wgRequest->getCheck( 'wpSave' 
) && !$wgRequest->getCheck( 'wpPreview' ) );
+               $module->setOption( 'preload', 
+                               !$wgRequest->getCheck( 'wpSave' ) &&
+                               !$wgRequest->getCheck( 'wpPreview' ) &&
+                               !$wgRequest->getCheck( 'wpDiff' )
+                               );
 
                $module->execute();
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3e41aadd62cc7fcbe0d64bb1c0aefe0fa540db5d
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Foxtrott <[email protected]>
Gerrit-Reviewer: Foxtrott <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to