http -> https rewrite: Only replace one http by https
[lhc/web/wiklou.git] / includes / EditPage.php
index f57fc60..c2803b6 100644 (file)
@@ -225,7 +225,7 @@ class EditPage {
 
        /**
         * Has a summary been preset using GET parameter &summary= ?
-        * @var Bool
+        * @var bool
         */
        var $hasPresetSummary = false;
 
@@ -266,7 +266,7 @@ class EditPage {
        public $allowNonTextContent = false;
 
        /**
-        * @param $article Article
+        * @param Article $article
         */
        public function __construct( Article $article ) {
                $this->mArticle = $article;
@@ -296,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;
@@ -307,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 ) ) {
@@ -487,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 ) {
@@ -511,6 +511,8 @@ class EditPage {
                        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() );
@@ -543,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' );
@@ -623,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 ) {
@@ -817,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
@@ -826,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;
@@ -862,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.
         */
@@ -885,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
         */
@@ -910,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 ) {
@@ -999,7 +1002,7 @@ class EditPage {
                                }
 
                                if ( $content === false ) {
-                                       $content = $this->getOriginalContent();
+                                       $content = $this->getOriginalContent( $wgUser );
                                }
                        }
                }
@@ -1020,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();
                }
@@ -1035,7 +1039,7 @@ class EditPage {
 
                        return $handler->makeEmptyContent();
                }
-               $content = $revision->getContent();
+               $content = $revision->getContent( Revision::FOR_THIS_USER, $user );
                return $content;
        }
 
@@ -1070,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 ) {
@@ -1084,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
         */
@@ -1098,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
         */
@@ -1115,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 ) ) {
@@ -1175,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
         */
@@ -1340,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
         */
@@ -1388,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.
@@ -1734,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
                        ) {
@@ -1861,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
@@ -1887,7 +1892,7 @@ class EditPage {
         *
         * @since 1.21
         *
-        * @param $editContent
+        * @param Content $editContent
         *
         * @return bool
         */
@@ -1943,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;
@@ -1957,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;
@@ -1968,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 ) {
@@ -2148,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.
         */
@@ -2201,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 ) {
@@ -2396,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 );
@@ -2571,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 )
         */
@@ -2603,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;
@@ -2629,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
@@ -2705,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' ) {
@@ -2812,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;
@@ -2941,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' ) {
@@ -3101,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 ) {
@@ -3113,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 ) {
@@ -3308,7 +3313,7 @@ HTML
        }
 
        /**
-        * @return Array
+        * @return array
         */
        function getTemplates() {
                if ( $this->preview || $this->section != '' ) {
@@ -3417,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',
@@ -3498,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
@@ -3627,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' );
@@ -3639,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' );
@@ -3650,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' );
@@ -3677,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;