Merge "Miscellaneous profiling fixes"
[lhc/web/wiklou.git] / includes / EditPage.php
index 292d2b7..410fa3a 100644 (file)
@@ -610,7 +610,7 @@ class EditPage {
                                // modified by subclasses
                                wfProfileIn( get_class( $this ) . "::importContentFormData" );
                                $textbox1 = $this->importContentFormData( $request );
-                               if ( isset( $textbox1 ) ) {
+                               if ( $textbox1 !== null ) {
                                        $this->textbox1 = $textbox1;
                                }
 
@@ -1218,6 +1218,54 @@ class EditPage {
                }
        }
 
+       /**
+        * Run hooks that can filter edits just before they get saved.
+        *
+        * @param Content $content the Content to filter.
+        * @param Status  $status for reporting the outcome to the caller
+        * @param User    $user the user performing the edit
+        *
+        * @return bool
+        */
+       protected function runPostMergeFilters( Content $content, Status $status, User $user ) {
+               // Run old style post-section-merge edit filter
+               if ( !ContentHandler::runLegacyHooks( 'EditFilterMerged',
+                       array( $this, $content, &$this->hookError, $this->summary ) ) ) {
+
+                       # Error messages etc. could be handled within the hook...
+                       $status->fatal( 'hookaborted' );
+                       $status->value = self::AS_HOOK_ERROR;
+                       return false;
+               } elseif ( $this->hookError != '' ) {
+                       # ...or the hook could be expecting us to produce an error
+                       $status->fatal( 'hookaborted' );
+                       $status->value = self::AS_HOOK_ERROR_EXPECTED;
+                       return false;
+               }
+
+               // Run new style post-section-merge edit filter
+               if ( !wfRunHooks( 'EditFilterMergedContent',
+                       array( $this->mArticle->getContext(), $content, $status, $this->summary,
+                               $user, $this->minoredit ) ) ) {
+
+                       # Error messages etc. could be handled within the hook...
+                       // XXX: $status->value may already be something informative...
+                       $this->hookError = $status->getWikiText();
+                       $status->fatal( 'hookaborted' );
+                       $status->value = self::AS_HOOK_ERROR;
+                       return false;
+               } elseif ( !$status->isOK() ) {
+                       # ...or the hook could be expecting us to produce an error
+                       // FIXME this sucks, we should just use the Status object throughout
+                       $this->hookError = $status->getWikiText();
+                       $status->fatal( 'hookaborted' );
+                       $status->value = self::AS_HOOK_ERROR_EXPECTED;
+                       return false;
+               }
+
+               return true;
+       }
+
        /**
         * Attempt submission (no UI)
         *
@@ -1235,7 +1283,7 @@ class EditPage {
 
                $status = Status::newGood();
 
-               wfProfileIn( __METHOD__  );
+               wfProfileIn( __METHOD__ );
                wfProfileIn( __METHOD__ . '-checks' );
 
                if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
@@ -1243,16 +1291,17 @@ class EditPage {
                        $status->fatal( 'hookaborted' );
                        $status->value = self::AS_HOOK_ERROR;
                        wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__  );
+                       wfProfileOut( __METHOD__ );
                        return $status;
                }
 
                try {
                        # Construct Content object
                        $textbox_content = $this->toEditContent( $this->textbox1 );
-               } catch (MWContentSerializationException $ex) {
+               } catch ( MWContentSerializationException $ex ) {
                        $status->fatal( 'content-failed-to-parse', $this->contentModel, $this->contentFormat, $ex->getMessage() );
                        $status->value = self::AS_PARSE_ERROR;
+                       wfProfileOut( __METHOD__ . '-checks' );
                        wfProfileOut( __METHOD__ );
                        return $status;
                }
@@ -1265,7 +1314,7 @@ class EditPage {
                                $status->setResult( false, $code );
 
                                wfProfileOut( __METHOD__ . '-checks' );
-                               wfProfileOut( __METHOD__  );
+                               wfProfileOut( __METHOD__ );
 
                                return $status;
                }
@@ -1386,17 +1435,7 @@ class EditPage {
                                return $status;
                        }
 
-                       // Run post-section-merge edit filter
-                       if ( !wfRunHooks( 'EditFilterMerged', array( $this, $this->textbox1, &$this->hookError, $this->summary ) ) ) {
-                               # Error messages etc. could be handled within the hook...
-                               $status->fatal( 'hookaborted' );
-                               $status->value = self::AS_HOOK_ERROR;
-                               wfProfileOut( __METHOD__ );
-                               return $status;
-                       } elseif ( $this->hookError != '' ) {
-                               # ...or the hook could be expecting us to produce an error
-                               $status->fatal( 'hookaborted' );
-                               $status->value = self::AS_HOOK_ERROR_EXPECTED;
+                       if ( !$this->runPostMergeFilters( $textbox_content, $status, $wgUser ) ) {
                                wfProfileOut( __METHOD__ );
                                return $status;
                        }
@@ -1510,20 +1549,7 @@ class EditPage {
                                return $status;
                        }
 
-                       // Run post-section-merge edit filter
-                       $hook_args = array( $this, $content, &$this->hookError, $this->summary );
-
-                       if ( !ContentHandler::runLegacyHooks( 'EditFilterMerged', $hook_args )
-                               || !wfRunHooks( 'EditFilterMergedContent', $hook_args ) ) {
-                               # Error messages etc. could be handled within the hook...
-                               $status->fatal( 'hookaborted' );
-                               $status->value = self::AS_HOOK_ERROR;
-                               wfProfileOut( __METHOD__ );
-                               return $status;
-                       } elseif ( $this->hookError != '' ) {
-                               # ...or the hook could be expecting us to produce an error
-                               $status->fatal( 'hookaborted' );
-                               $status->value = self::AS_HOOK_ERROR_EXPECTED;
+                       if ( !$this->runPostMergeFilters( $content, $status, $wgUser ) ) {
                                wfProfileOut( __METHOD__ );
                                return $status;
                        }
@@ -1672,8 +1698,7 @@ class EditPage {
        }
 
        /**
-        * @private
-        * @todo document
+        * Attempts to merge text content with base and current revisions
         *
         * @param $editText string
         *
@@ -1695,12 +1720,15 @@ class EditPage {
        }
 
        /**
-        * @private
-        * @todo document
+        * Attempts to do 3-way merge of edit content with a base revision
+        * and current content, in case of edit conflict, in whichever way appropriate
+        * for the content type.
+        *
+        * @since 1.21
         *
         * @param $editContent
+        *
         * @return bool
-        * @since since 1.WD
         */
        private function mergeChangesIntoContent( &$editContent ){
                wfProfileIn( __METHOD__ );