Merge "New hook for readonly editpages"
[lhc/web/wiklou.git] / includes / EditPage.php
index d4b06fe..d0bd7c7 100644 (file)
@@ -36,7 +36,6 @@
  * headaches, which may be fatal.
  */
 class EditPage {
-
        /**
         * Status: Article successfully updated
         */
@@ -512,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() );
@@ -911,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 ) {
@@ -1000,7 +1002,7 @@ class EditPage {
                                }
 
                                if ( $content === false ) {
-                                       $content = $this->getOriginalContent();
+                                       $content = $this->getOriginalContent( $wgUser );
                                }
                        }
                }
@@ -1021,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();
                }
@@ -1036,7 +1039,7 @@ class EditPage {
 
                        return $handler->makeEmptyContent();
                }
-               $content = $revision->getContent();
+               $content = $revision->getContent( Revision::FOR_THIS_USER, $user );
                return $content;
        }
 
@@ -1117,12 +1120,13 @@ class EditPage {
         * 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 ) ) {
@@ -1176,7 +1180,7 @@ class EditPage {
                        $content = $converted;
                }
 
-               return $content->preloadTransform( $title, $parserOptions );
+               return $content->preloadTransform( $title, $parserOptions, $params );
        }
 
        /**
@@ -1342,8 +1346,8 @@ 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 Status $status For reporting the outcome to the caller
+        * @param User $user The user performing the edit
         *
         * @return bool
         */
@@ -1735,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
                        ) {
@@ -2082,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
@@ -2604,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;
@@ -2630,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 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
@@ -3418,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',
@@ -3705,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' );
@@ -3744,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;
        }
 
@@ -3772,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 );
        }
 
        /**
@@ -3793,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" ) );
 
@@ -3835,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 = "";