Merge "Miscellaneous profiling fixes"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 9 Jan 2013 08:24:16 +0000 (08:24 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 9 Jan 2013 08:24:16 +0000 (08:24 +0000)
1  2 
includes/EditPage.php
includes/Linker.php

diff --combined includes/EditPage.php
@@@ -1218,54 -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)
         *
  
                $status = Status::newGood();
  
-               wfProfileIn( __METHOD__  );
+               wfProfileIn( __METHOD__ );
                wfProfileIn( __METHOD__ . '-checks' );
  
                if ( !wfRunHooks( 'EditPage::attemptSave', array( $this ) ) ) {
                        $status->fatal( 'hookaborted' );
                        $status->value = self::AS_HOOK_ERROR;
                        wfProfileOut( __METHOD__ . '-checks' );
-                       wfProfileOut( __METHOD__  );
+                       wfProfileOut( __METHOD__ );
                        return $status;
                }
  
                } 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;
                }
                                $status->setResult( false, $code );
  
                                wfProfileOut( __METHOD__ . '-checks' );
-                               wfProfileOut( __METHOD__  );
+                               wfProfileOut( __METHOD__ );
  
                                return $status;
                }
                                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;
                        }
                                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;
                        }
diff --combined includes/Linker.php
@@@ -1858,19 -1858,13 +1858,19 @@@ class Linker 
        /**
         * Returns HTML for the "templates used on this page" list.
         *
 +       * Make an HTML list of templates, and then add a "More..." link at
 +       * the bottom. If $more is null, do not add a "More..." link. If $more
 +       * is a Title, make a link to that title and use it. If $more is a string,
 +       * directly paste it in as the link.
 +       *
         * @param $templates Array of templates from Article::getUsedTemplate
         * or similar
 -       * @param $preview Boolean: whether this is for a preview
 -       * @param $section Boolean: whether this is for a section edit
 +       * @param bool $preview Whether this is for a preview
 +       * @param bool $section Whether this is for a section edit
 +       * @param Title|string|null $more A link for "More..." of the templates
         * @return String: HTML output
         */
 -      public static function formatTemplates( $templates, $preview = false, $section = false ) {
 +      public static function formatTemplates( $templates, $preview = false, $section = false, $more = null ) {
                wfProfileIn( __METHOD__ );
  
                $outText = '';
                                        . wfMessage( 'word-separator' )->escaped()
                                        . $protected . '</li>';
                        }
 +
 +                      if ( $more instanceof Title ) {
 +                              $outText .= '<li>' . self::link( $more, wfMessage( 'moredotdotdot' ) ) . '</li>';
 +                      } elseif ( $more ) {
 +                              $outText .= "<li>$more</li>";
 +                      }
 +
                        $outText .= '</ul>';
                }
-               wfProfileOut( __METHOD__  );
+               wfProfileOut( __METHOD__ );
                return $outText;
        }
  
                        }
                        $outText .= '</ul>';
                }
-               wfProfileOut( __METHOD__  );
+               wfProfileOut( __METHOD__ );
                return $outText;
        }