http -> https rewrite: Only replace one http by https
[lhc/web/wiklou.git] / includes / EditPage.php
index 035c5cc..c2803b6 100644 (file)
@@ -36,7 +36,6 @@
  * headaches, which may be fatal.
  */
 class EditPage {
-
        /**
         * Status: Article successfully updated
         */
@@ -226,7 +225,7 @@ class EditPage {
 
        /**
         * Has a summary been preset using GET parameter &summary= ?
-        * @var Bool
+        * @var bool
         */
        var $hasPresetSummary = false;
 
@@ -267,7 +266,7 @@ class EditPage {
        public $allowNonTextContent = false;
 
        /**
-        * @param $article Article
+        * @param Article $article
         */
        public function __construct( Article $article ) {
                $this->mArticle = $article;
@@ -297,7 +296,7 @@ class EditPage {
        /**
         * Set the context Title object
         *
-        * @param $title Title object or null
+        * @param Title|null $title Title object or null
         */
        public function setContextTitle( $title ) {
                $this->mContextTitle = $title;
@@ -308,7 +307,7 @@ class EditPage {
         * If not set, $wgTitle will be returned. This behavior might change in
         * the future to return $this->mTitle instead.
         *
-        * @return Title object
+        * @return Title
         */
        public function getContextTitle() {
                if ( is_null( $this->mContextTitle ) ) {
@@ -488,8 +487,8 @@ class EditPage {
         *   "View source for ..." page displaying the source code after the error message.
         *
         * @since 1.19
-        * @param array $permErrors of permissions errors, as returned by
-        *                    Title::getUserPermissionsErrors().
+        * @param array $permErrors Array of permissions errors, as returned by
+        *    Title::getUserPermissionsErrors().
         * @throws PermissionsError
         */
        protected function displayPermissionsError( array $permErrors ) {
@@ -546,7 +545,7 @@ class EditPage {
         * Show a read-only error
         * Parameters are the same as OutputPage:readOnlyPage()
         * Redirect to the article page if redlink=1
-        * @deprecated in 1.19; use displayPermissionsError() instead
+        * @deprecated since 1.19; use displayPermissionsError() instead
         */
        function readOnlyPage( $source = null, $protected = false, $reasons = array(), $action = null ) {
                wfDeprecated( __METHOD__, '1.19' );
@@ -626,7 +625,7 @@ class EditPage {
 
        /**
         * This function collects the form data and uses it to populate various member variables.
-        * @param $request WebRequest
+        * @param WebRequest $request
         * @throws ErrorPageError
         */
        function importFormData( &$request ) {
@@ -820,7 +819,7 @@ class EditPage {
         * this method should be overridden and return the page text that will be used
         * for saving, preview parsing and so on...
         *
-        * @param $request WebRequest
+        * @param WebRequest $request
         */
        protected function importContentFormData( &$request ) {
                return; // Don't do anything, EditPage already extracted wpTextbox1
@@ -829,7 +828,7 @@ class EditPage {
        /**
         * Initialise form fields in the object
         * Called on the first invocation, e.g. when a user clicks an edit link
-        * @return bool -- if the requested section is valid
+        * @return bool If the requested section is valid
         */
        function initialiseForm() {
                global $wgUser;
@@ -865,8 +864,8 @@ class EditPage {
        /**
         * Fetch initial editing page content.
         *
-        * @param $def_text string|bool
-        * @return mixed string on success, $def_text for invalid sections
+        * @param string|bool $def_text
+        * @return string|bool string on success, $def_text for invalid sections
         * @private
         * @deprecated since 1.21, get WikiPage::getContent() instead.
         */
@@ -888,7 +887,7 @@ class EditPage {
        /**
         * @param Content|null $def_content The default value to return
         *
-        * @return mixed Content on success, $def_content for invalid sections
+        * @return Content|null Content on success, $def_content for invalid sections
         *
         * @since 1.21
         */
@@ -913,14 +912,15 @@ class EditPage {
                                $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 ) {
@@ -1002,7 +1002,7 @@ class EditPage {
                                }
 
                                if ( $content === false ) {
-                                       $content = $this->getOriginalContent();
+                                       $content = $this->getOriginalContent( $wgUser );
                                }
                        }
                }
@@ -1023,9 +1023,10 @@ class EditPage {
         * '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();
                }
@@ -1038,7 +1039,7 @@ class EditPage {
 
                        return $handler->makeEmptyContent();
                }
-               $content = $revision->getContent();
+               $content = $revision->getContent( Revision::FOR_THIS_USER, $user );
                return $content;
        }
 
@@ -1073,7 +1074,7 @@ class EditPage {
        /**
         * Use this method before edit() to preload some text into the edit box
         *
-        * @param $text string
+        * @param string $text
         * @deprecated since 1.21, use setPreloadedContent() instead.
         */
        public function setPreloadedText( $text ) {
@@ -1087,7 +1088,7 @@ class EditPage {
        /**
         * Use this method before edit() to preload some content into the edit box
         *
-        * @param $content Content
+        * @param Content $content
         *
         * @since 1.21
         */
@@ -1101,7 +1102,7 @@ class EditPage {
         *
         * @param string $preload representing the title to preload from.
         *
-        * @return String
+        * @return string
         *
         * @deprecated since 1.21, use getPreloadedContent() instead
         */
@@ -1118,13 +1119,14 @@ class EditPage {
         * Get the contents to be preloaded into the box, either set by
         * an earlier setPreloadText() or by loading the given page.
         *
-        * @param string $preload representing the title to preload from.
+        * @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 ) ) {
@@ -1178,13 +1180,13 @@ class EditPage {
                        $content = $converted;
                }
 
-               return $content->preloadTransform( $title, $parserOptions );
+               return $content->preloadTransform( $title, $parserOptions, $params );
        }
 
        /**
         * Make sure the form isn't faking a user's credentials.
         *
-        * @param $request WebRequest
+        * @param WebRequest $request
         * @return bool
         * @private
         */
@@ -1343,9 +1345,9 @@ 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
+        * @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
         */
@@ -1391,14 +1393,14 @@ class EditPage {
        /**
         * Attempt submission (no UI)
         *
-        * @param array $result array to add statuses to, currently with the possible keys:
+        * @param array $result Array to add statuses to, currently with the possible keys:
         *  spam - string - Spam string from content if any spam is detected by matchSpamRegex
         *  sectionanchor - string - Section anchor for a section save
         *  nullEdit - boolean - Set if doEditContent is OK.  True if null edit, false otherwise.
         *  redirect - boolean -  Set if doEditContent is OK.  True if resulting revision is a redirect
         * @param bool $bot True if edit is being made under the bot right.
         *
-        * @return Status object, possibly with a message, but always with one of the AS_* constants in $status->value,
+        * @return Status Status object, possibly with a message, but always with one of the AS_* constants in $status->value,
         *
         * FIXME: This interface is TERRIBLE, but hard to get rid of due to various error display idiosyncrasies. There are
         * also lots of cases where error metadata is set in the object and retrieved later instead of being returned, e.g.
@@ -1737,7 +1739,7 @@ class EditPage {
                                        return $status;
                                }
                        } elseif ( !$this->allowBlankSummary
-                               && !$content->equals( $this->getOriginalContent() )
+                               && !$content->equals( $this->getOriginalContent( $wgUser ) )
                                && !$content->isRedirect()
                                && md5( $this->summary ) == $this->autoSumm
                        ) {
@@ -1864,7 +1866,7 @@ class EditPage {
        /**
         * Attempts to merge text content with base and current revisions
         *
-        * @param $editText string
+        * @param string $editText
         *
         * @return bool
         * @deprecated since 1.21, use mergeChangesIntoContent() instead
@@ -1890,7 +1892,7 @@ class EditPage {
         *
         * @since 1.21
         *
-        * @param $editContent
+        * @param Content $editContent
         *
         * @return bool
         */
@@ -1946,9 +1948,9 @@ class EditPage {
        /**
         * Check given input text against $wgSpamRegex, and return the text of the first match.
         *
-        * @param $text string
+        * @param string $text
         *
-        * @return string|bool matching string or false
+        * @return string|bool Matching string or false
         */
        public static function matchSpamRegex( $text ) {
                global $wgSpamRegex;
@@ -1960,9 +1962,9 @@ class EditPage {
        /**
         * Check given input text against $wgSummarySpamRegex, and return the text of the first match.
         *
-        * @param $text string
+        * @param string $text
         *
-        * @return string|bool matching string or false
+        * @return string|bool Matching string or false
         */
        public static function matchSummarySpamRegex( $text ) {
                global $wgSummarySpamRegex;
@@ -1971,8 +1973,8 @@ class EditPage {
        }
 
        /**
-        * @param $text string
-        * @param $regexes array
+        * @param string $text
+        * @param array $regexes
         * @return bool|string
         */
        protected static function matchSpamRegexInternal( $text, $regexes ) {
@@ -2084,9 +2086,9 @@ class EditPage {
                }
                # 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
@@ -2151,7 +2153,7 @@ class EditPage {
         * content.
         *
         * @param Content|null|bool|string $content
-        * @return String the editable text form of the content.
+        * @return string The editable text form of the content.
         *
         * @throws MWException if $content is not an instance of TextContent and $this->allowNonTextContent is not true.
         */
@@ -2204,7 +2206,7 @@ class EditPage {
 
        /**
         * Send the edit form and related headers to $wgOut
-        * @param $formCallback Callback|null that takes an OutputPage parameter; will be called
+        * @param callable|null $formCallback That takes an OutputPage parameter; will be called
         *     during form output near the top, for captchas and the like.
         */
        function showEditForm( $formCallback = null ) {
@@ -2399,7 +2401,7 @@ class EditPage {
         * Extract the section title from current section text, if any.
         *
         * @param string $text
-        * @return Mixed|string or false
+        * @return string|bool string or false
         */
        public static function extractSectionTitle( $text ) {
                preg_match( "/^(=+)(.+)\\1\\s*(\n|$)/i", $text, $matches );
@@ -2574,8 +2576,8 @@ class EditPage {
         *
         * @param string $summary The value of the summary input
         * @param string $labelText The html to place inside the label
-        * @param array $inputAttrs of attrs to use on the input
-        * @param array $spanLabelAttrs of attrs to use on the span inside the label
+        * @param array $inputAttrs Array of attrs to use on the input
+        * @param array $spanLabelAttrs Array of attrs to use on the span inside the label
         *
         * @return array An array in the format array( $label, $input )
         */
@@ -2606,11 +2608,11 @@ class EditPage {
        }
 
        /**
-        * @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;
@@ -2632,11 +2634,11 @@ class EditPage {
        }
 
        /**
-        * @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 string $summary the text of the summary to display
-        * @return String
+        * @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
         */
        protected function getSummaryPreview( $isSubjectPreview, $summary = "" ) {
                // avoid spaces in preview, gets always trimmed on save
@@ -2708,8 +2710,8 @@ HTML
         * The $textoverride method can be used by subclasses overriding showContentForm
         * to pass back to this method.
         *
-        * @param array $customAttribs of html attributes to use in the textarea
-        * @param string $textoverride optional text to override $this->textarea1 with
+        * @param array $customAttribs Array of html attributes to use in the textarea
+        * @param string $textoverride Optional text to override $this->textarea1 with
         */
        protected function showTextbox1( $customAttribs = null, $textoverride = null ) {
                if ( $this->wasDeletedSinceLastEdit() && $this->formtype == 'save' ) {
@@ -2815,7 +2817,7 @@ HTML
         * Append preview output to $wgOut.
         * Includes category rendering if this is a category page.
         *
-        * @param string $text the HTML to be output for the preview.
+        * @param string $text The HTML to be output for the preview.
         */
        protected function showPreview( $text ) {
                global $wgOut;
@@ -2944,8 +2946,7 @@ HTML
         * Get the copyright warning, by default returns wikitext
         *
         * @param Title $title
-        * @param string $format output format, valid values are any function of
-        *                       a Message object
+        * @param string $format Output format, valid values are any function of a Message object
         * @return string
         */
        public static function getCopyrightWarning( $title, $format = 'plain' ) {
@@ -3104,7 +3105,7 @@ HTML
         * variable in the constructor is not enough. This can be used when the
         * EditPage lives inside of a Special page rather than a custom page action.
         *
-        * @param $title Title object for which is being edited (where we go to for &action= links)
+        * @param Title $title Title object for which is being edited (where we go to for &action= links)
         * @return string
         */
        protected function getActionURL( Title $title ) {
@@ -3116,6 +3117,7 @@ HTML
         * Note that we rely on the logging table, which hasn't been always there,
         * but that doesn't matter, because this only applies to brand new
         * deletes.
+        * @return bool
         */
        protected function wasDeletedSinceLastEdit() {
                if ( $this->deletedSinceEdit !== null ) {
@@ -3311,7 +3313,7 @@ HTML
        }
 
        /**
-        * @return Array
+        * @return array
         */
        function getTemplates() {
                if ( $this->preview || $this->section != '' ) {
@@ -3420,15 +3422,6 @@ HTML
                                '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',
@@ -3501,7 +3494,7 @@ HTML
         * minor and watch
         *
         * @param int $tabindex Current tabindex
-        * @param array $checked of checkbox => bool, where bool indicates the checked
+        * @param array $checked Array of checkbox => bool, where bool indicates the checked
         *                 status of the checkbox
         *
         * @return array
@@ -3630,7 +3623,7 @@ HTML
        /**
         * Call the stock "user is blocked" page
         *
-        * @deprecated in 1.19; throw an exception directly instead
+        * @deprecated since 1.19; throw an exception directly instead
         */
        function blockedPage() {
                wfDeprecated( __METHOD__, '1.19' );
@@ -3642,7 +3635,7 @@ HTML
        /**
         * Produce the stock "please login to edit pages" page
         *
-        * @deprecated in 1.19; throw an exception directly instead
+        * @deprecated since 1.19; throw an exception directly instead
         */
        function userNotLoggedInPage() {
                wfDeprecated( __METHOD__, '1.19' );
@@ -3653,7 +3646,7 @@ HTML
         * Show an error page saying to the user that he has insufficient permissions
         * to create a new page
         *
-        * @deprecated in 1.19; throw an exception directly instead
+        * @deprecated since 1.19; throw an exception directly instead
         */
        function noCreatePermission() {
                wfDeprecated( __METHOD__, '1.19' );
@@ -3680,7 +3673,7 @@ HTML
        /**
         * Show "your edit contains spam" page with your diff and text
         *
-        * @param $match string|Array|bool Text (or array of texts) which triggered one or more filters
+        * @param string|array|bool $match Text (or array of texts) which triggered one or more filters
         */
        public function spamPageWithContent( $match = false ) {
                global $wgOut, $wgLang;
@@ -3707,25 +3700,13 @@ HTML
                $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' );
@@ -3746,27 +3727,14 @@ HTML
         * 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;
        }
 
@@ -3774,16 +3742,15 @@ HTML
         * 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 );
        }
 
        /**
@@ -3795,11 +3762,10 @@ HTML
         * 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" ) );
 
@@ -3837,13 +3803,13 @@ HTML
         * 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 = "";