Merge "New hook for readonly editpages"
authorMwalker <mwalker@wikimedia.org>
Tue, 15 Apr 2014 18:15:59 +0000 (18:15 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 15 Apr 2014 18:15:59 +0000 (18:15 +0000)
1  2 
docs/hooks.txt
includes/EditPage.php

diff --combined docs/hooks.txt
@@@ -839,26 -839,6 +839,26 @@@ ChangePassword form via the Preference
  $unpatrolled: Whether or not we are showing unpatrolled changes.
  $watched: Whether or not the change is watched by the user.
  
 +'ChangesListInitRows': Batch process change list rows prior to rendering.
 +$changesList: ChangesList instance
 +$rows: The data that will be rendered. May be a ResultWrapper instance or
 +  an array.
 +
 +'ChangesListSpecialPageFilters': Called after building form options on pages inheriting from ChangesListSpecialPage (in core: RecentChanges, RecentChangesLinked and Watchlist).
 +$special: ChangesListSpecialPage instance
 +&$filters: associative array of filter definitions. The keys are the HTML
 +  name/URL parameters. Each key maps to an associative array with a 'msg'
 +  (message key) and a 'default' value.
 +
 +'ChangesListSpecialPageQuery': Called when building SQL query on pages inheriting from ChangesListSpecialPage (in core: RecentChanges, RecentChangesLinked and Watchlist).
 +$name: name of the special page, e.g. 'Watchlist'
 +&$tables: array of tables to be queried
 +&$fields: array of columns to select
 +&$conds: array of WHERE conditionals for query
 +&$query_options: array of options for the database request
 +&$join_conds: join conditions for the tables
 +$opts: FormOptions for this request
 +
  'Collation::factory': Called if $wgCategoryCollation is an unknown collation.
  $collationName: Name of the collation in question
  &$collationObject: Null. Replace with a subclass of the Collation class that
@@@ -1025,6 -1005,12 +1025,12 @@@ yourself. Alternatively, modifying $err
  contents of $error to be echoed at the top of the edit form as wikitext.
  Return true without altering $error to allow the edit to proceed.
  
+ 'EditPage::showReadOnlyForm:initial: similar to EditPage::showEditForm:initial
+ but for the readonly 'view source' variant of the edit form.
+ $editor: EditPage instance (object)
+ &$out: an OutputPage instance to write to
+ return value is ignored (should alway return true)
  'EditPage::showStandardInputs:options': allows injection of form fields into
  the editOptions area
  $editor: EditPage instance (object)
@@@ -1461,7 -1447,6 +1467,7 @@@ $user: user (object) whose email is bei
  Callee may modify $url and $query, URL will be constructed as $url . $query
  &$url: URL to index.php
  &$query: Query string
 +$rc: RecentChange object that triggered url generation
  
  'IsFileCacheable': Override the result of Article::isFileCacheable() (if true)
  $article: article (object) being checked
@@@ -2384,7 -2369,7 +2390,7 @@@ use this to change some selection crite
    result from the normal query
  
  'SpecialRecentChangesFilters': Called after building form options at
 -RecentChanges.
 +RecentChanges. Deprecated, use ChangesListSpecialPageFilters instead.
  $special: the special page object
  &$filters: associative array of filter definitions. The keys are the HTML
    name/URL parameters. Each key maps to an associative array with a 'msg'
@@@ -2396,8 -2381,7 +2402,8 @@@ SpecialRecentChanges
  $opts: FormOptions for this request
  
  'SpecialRecentChangesQuery': Called when building SQL query for
 -SpecialRecentChanges and SpecialRecentChangesLinked.
 +SpecialRecentChanges and SpecialRecentChangesLinked. Deprecated, use
 +ChangesListSpecialPageQuery instead.
  &$conds: array of WHERE conditionals for query
  &$tables: array of tables to be queried
  &$join_conds: join conditions for the tables
@@@ -2487,14 -2471,12 +2493,14 @@@ $wgVersion: Current $wgVersion for you 
  &$versionUrl: Raw url to link to (eg: release notes)
  
  'SpecialWatchlistFilters': Called after building form options at Watchlist.
 +Deprecated, use ChangesListSpecialPageFilters instead.
  $special: the special page object
  &$filters: associative array of filter definitions. The keys are the HTML
    name/URL parameters. Each key maps to an associative array with a 'msg'
    (message key) and a 'default' value.
  
  'SpecialWatchlistQuery': Called when building sql query for SpecialWatchlist.
 +Deprecated, use ChangesListSpecialPageQuery instead.
  &$conds: array of WHERE conditionals for query
  &$tables: array of tables to be queried
  &$join_conds: join conditions for the tables
diff --combined includes/EditPage.php
@@@ -36,6 -36,7 +36,6 @@@
   * headaches, which may be fatal.
   */
  class EditPage {
 -
        /**
         * Status: Article successfully updated
         */
                        throw new PermissionsError( $action, $permErrors );
                }
  
+               wfRunHooks( 'EditPage::showReadOnlyForm:initial', array( $this, &$wgOut ) );
                $wgOut->setRobotPolicy( 'noindex,nofollow' );
                $wgOut->setPageTitle( wfMessage( 'viewsource-title', $this->getContextTitle()->getPrefixedText() ) );
                $wgOut->addBacklinkSubtitle( $this->getContextTitle() );
                                $preload = $wgRequest->getVal( 'preload',
                                        // Custom preload text for new sections
                                        $this->section === 'new' ? 'MediaWiki:addsection-preload' : '' );
 +                              $params = $wgRequest->getArray( 'preloadparams', array() );
  
 -                              $content = $this->getPreloadedContent( $preload );
 +                              $content = $this->getPreloadedContent( $preload, $params );
                        }
                // For existing pages, get text based on "undo" or section parameters.
                } else {
                        if ( $this->section != '' ) {
                                // Get section edit text (returns $def_text for invalid sections)
 -                              $orig = $this->getOriginalContent();
 +                              $orig = $this->getOriginalContent( $wgUser );
                                $content = $orig ? $orig->getSection( $this->section ) : null;
  
                                if ( !$content ) {
                                }
  
                                if ( $content === false ) {
 -                                      $content = $this->getOriginalContent();
 +                                      $content = $this->getOriginalContent( $wgUser );
                                }
                        }
                }
         * 'missing-revision' message.
         *
         * @since 1.19
 +       * @param User $user The user to get the revision for
         * @return Content|null
         */
 -      private function getOriginalContent() {
 +      private function getOriginalContent( User $user ) {
                if ( $this->section == 'new' ) {
                        return $this->getCurrentContent();
                }
  
                        return $handler->makeEmptyContent();
                }
 -              $content = $revision->getContent();
 +              $content = $revision->getContent( Revision::FOR_THIS_USER, $user );
                return $content;
        }
  
         * an earlier setPreloadText() or by loading the given page.
         *
         * @param string $preload representing the title to preload from.
 +       * @param Array $params Parameters to use (interface-message style) in the preloaded text
         *
         * @return Content
         *
         * @since 1.21
         */
 -      protected function getPreloadedContent( $preload ) {
 +      protected function getPreloadedContent( $preload, $params = array() ) {
                global $wgUser;
  
                if ( !empty( $this->mPreloadContent ) ) {
                        $content = $converted;
                }
  
 -              return $content->preloadTransform( $title, $parserOptions );
 +              return $content->preloadTransform( $title, $parserOptions, $params );
        }
  
        /**
         * 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
 +       * @param Status $status For reporting the outcome to the caller
 +       * @param User $user The user performing the edit
         *
         * @return bool
         */
                                        return $status;
                                }
                        } elseif ( !$this->allowBlankSummary
 -                              && !$content->equals( $this->getOriginalContent() )
 +                              && !$content->equals( $this->getOriginalContent( $wgUser ) )
                                && !$content->isRedirect()
                                && md5( $this->summary ) == $this->autoSumm
                        ) {
                }
                # Try to add a custom edit intro, or use the standard one if this is not possible.
                if ( !$this->showCustomIntro() && !$this->mTitle->exists() ) {
 -                      $helpLink = Skin::makeInternalOrExternalUrl(
 +                      $helpLink = wfExpandUrl( Skin::makeInternalOrExternalUrl(
                                wfMessage( 'helppage' )->inContentLanguage()->text()
 -                      );
 +                      ) );
                        if ( $wgUser->isLoggedIn() ) {
                                $wgOut->wrapWikiMsg(
                                        // Suppress the external link icon, consider the help url an internal one
        }
  
        /**
 -       * @param $isSubjectPreview Boolean: true if this is the section subject/title
 -       *                          up top, or false if this is the comment summary
 -       *                          down below the textarea
 +       * @param bool $isSubjectPreview true if this is the section subject/title
 +       *   up top, or false if this is the comment summary
 +       *   down below the textarea
         * @param string $summary The text of the summary to display
 -       * @return String
 +       * @return string
         */
        protected function showSummaryInput( $isSubjectPreview, $summary = "" ) {
                global $wgOut, $wgContLang;
        }
  
        /**
 -       * @param $isSubjectPreview Boolean: true if this is the section subject/title
 -       *                          up top, or false if this is the comment summary
 -       *                          down below the textarea
 +       * @param bool $isSubjectPreview true if this is the section subject/title
 +       *   up top, or false if this is the comment summary
 +       *   down below the textarea
         * @param string $summary the text of the summary to display
 -       * @return String
 +       * @return string
         */
        protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
                // avoid spaces in preview, gets always trimmed on save
@@@ -3420,6 -3420,15 +3422,6 @@@ HTM
                                'tip'    => wfMessage( 'media_tip' )->text(),
                                'key'    => 'M'
                        ) : false,
 -                      class_exists( 'MathRenderer' ) ? array(
 -                              'image'  => $wgLang->getImageFile( 'button-math' ),
 -                              'id'     => 'mw-editbutton-math',
 -                              'open'   => "<math>",
 -                              'close'  => "</math>",
 -                              'sample' => wfMessage( 'math_sample' )->text(),
 -                              'tip'    => wfMessage( 'math_tip' )->text(),
 -                              'key'    => 'C'
 -                      ) : false,
                        array(
                                'image'  => $wgLang->getImageFile( 'button-nowiki' ),
                                'id'     => 'mw-editbutton-nowiki',
                $wgOut->addReturnTo( $this->getContextTitle(), array( 'action' => 'edit' ) );
        }
  
 -      /**
 -       * Format an anchor fragment as it would appear for a given section name
 -       * @param $text String
 -       * @return String
 -       * @private
 -       */
 -      function sectionAnchor( $text ) {
 -              global $wgParser;
 -              return $wgParser->guessSectionNameFromWikiText( $text );
 -      }
 -
        /**
         * Check if the browser is on a blacklist of user-agents known to
         * mangle UTF-8 data on form submission. Returns true if Unicode
         * should make it through, false if it's known to be a problem.
         * @return bool
 -       * @private
         */
 -      function checkUnicodeCompliantBrowser() {
 +      private function checkUnicodeCompliantBrowser() {
                global $wgBrowserBlackList, $wgRequest;
  
                $currentbrowser = $wgRequest->getHeader( 'User-Agent' );
         * Filter an input field through a Unicode de-armoring process if it
         * came from an old browser with known broken Unicode editing issues.
         *
 -       * @param $request WebRequest
 -       * @param $field String
 -       * @return String
 -       * @private
 -       */
 -      function safeUnicodeInput( $request, $field ) {
 -              $text = rtrim( $request->getText( $field ) );
 -              return $request->getBool( 'safemode' )
 -                      ? $this->unmakesafe( $text )
 -                      : $text;
 -      }
 -
 -      /**
 -       * @param $request WebRequest
 -       * @param $text string
 +       * @param WebRequest $request
 +       * @param string $field
         * @return string
         */
 -      function safeUnicodeText( $request, $text ) {
 -              $text = rtrim( $text );
 +      protected function safeUnicodeInput( $request, $field ) {
 +              $text = rtrim( $request->getText( $field ) );
                return $request->getBool( 'safemode' )
 -                      ? $this->unmakesafe( $text )
 +                      ? $this->unmakeSafe( $text )
                        : $text;
        }
  
         * Filter an output field through a Unicode armoring process if it is
         * going to an old browser with known broken Unicode editing issues.
         *
 -       * @param $text String
 -       * @return String
 -       * @private
 +       * @param string $text
 +       * @return string
         */
 -      function safeUnicodeOutput( $text ) {
 +      protected function safeUnicodeOutput( $text ) {
                global $wgContLang;
                $codedText = $wgContLang->recodeForEdit( $text );
                return $this->checkUnicodeCompliantBrowser()
                        ? $codedText
 -                      : $this->makesafe( $codedText );
 +                      : $this->makeSafe( $codedText );
        }
  
        /**
         * Preexisting such character references will have a 0 added to them
         * to ensure that round-trips do not alter the original data.
         *
 -       * @param $invalue String
 -       * @return String
 -       * @private
 +       * @param string $invalue
 +       * @return string
         */
 -      function makesafe( $invalue ) {
 +      private function makeSafe( $invalue ) {
                // Armor existing references for reversibility.
                $invalue = strtr( $invalue, array( "&#x" => "&#x0" ) );
  
         * back to UTF-8. Used to protect data from corruption by broken web browsers
         * as listed in $wgBrowserBlackList.
         *
 -       * @param $invalue String
 -       * @return String
 -       * @private
 +       * @param string $invalue
 +       * @return string
         */
 -      function unmakesafe( $invalue ) {
 +      private function unmakeSafe( $invalue ) {
                $result = "";
 -              for ( $i = 0; $i < strlen( $invalue ); $i++ ) {
 +              $valueLength = strlen( $invalue );
 +              for ( $i = 0; $i < $valueLength; $i++ ) {
                        if ( ( substr( $invalue, $i, 3 ) == "&#x" ) && ( $invalue[$i + 3] != '0' ) ) {
                                $i += 3;
                                $hexstring = "";