Deprecated WikiPage::preSaveTransform() in favour of Parser::preSaveTransform() and...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Tue, 15 Nov 2011 21:46:05 +0000 (21:46 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Tue, 15 Nov 2011 21:46:05 +0000 (21:46 +0000)
includes/EditPage.php
includes/WikiPage.php

index 8bcb2a3..780cb53 100644 (file)
@@ -2091,13 +2091,16 @@ HTML
         * save and then make a comparison.
         */
        function showDiff() {
+               global $wgUser, $wgContLang, $wgParser;
+
                $oldtext = $this->mArticle->fetchContent();
                $newtext = $this->mArticle->replaceSection(
                        $this->section, $this->textbox1, $this->summary, $this->edittime );
 
                wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
 
-               $newtext = $this->mArticle->preSaveTransform( $newtext );
+               $popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
+               $newtext = $wgParser->preSaveTransform( $newtext, $this->mTitle, $wgUser, $popts );
                $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
                $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
                if ( $oldtext !== false  || $newtext != '' ) {
@@ -2296,10 +2299,25 @@ HTML
         * @return string
         */
        function getPreviewText() {
-               global $wgOut, $wgUser, $wgParser;
+               global $wgOut, $wgUser, $wgParser, $wgRawHtml;
 
                wfProfileIn( __METHOD__ );
 
+               if ( $wgRawHtml && !$this->mTokenOk ) {
+                       // Could be an offsite preview attempt. This is very unsafe if
+                       // HTML is enabled, as it could be an attack.
+                       $parsedNote = '';
+                       if ( $this->textbox1 !== '' ) {
+                               // Do not put big scary notice, if previewing the empty
+                               // string, which happens when you initially edit
+                               // a category page, due to automatic preview-on-open.
+                               $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
+                                       wfMsg( 'session_fail_preview_html' ) . "</div>", true, /* interface */true );
+                       }
+                       wfProfileOut( __METHOD__ );
+                       return $parsedNote;
+               }
+
                if ( $this->mTriedSave && !$this->mTokenOk ) {
                        if ( $this->mTokenOkExceptSuffix ) {
                                $note = wfMsg( 'token_suffix_mismatch' );
@@ -2314,25 +2332,10 @@ HTML
 
                $parserOptions = ParserOptions::newFromUser( $wgUser );
                $parserOptions->setEditSection( false );
+               $parserOptions->setTidy( true );
                $parserOptions->setIsPreview( true );
                $parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' );
 
-               global $wgRawHtml;
-               if ( $wgRawHtml && !$this->mTokenOk ) {
-                       // Could be an offsite preview attempt. This is very unsafe if
-                       // HTML is enabled, as it could be an attack.
-                       $parsedNote = '';
-                       if ( $this->textbox1 !== '' ) {
-                               // Do not put big scary notice, if previewing the empty
-                               // string, which happens when you initially edit
-                               // a category page, due to automatic preview-on-open.
-                               $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
-                                       wfMsg( 'session_fail_preview_html' ) . "</div>", true, /* interface */true );
-                       }
-                       wfProfileOut( __METHOD__ );
-                       return $parsedNote;
-               }
-
                # don't parse non-wikitext pages, show message about preview
                # XXX: stupid php bug won't let us use $this->getContextTitle()->isCssJsSubpage() here -- This note has been there since r3530. Sure the bug was fixed time ago?
 
@@ -2359,7 +2362,6 @@ HTML
                                }
                        }
 
-                       $parserOptions->setTidy( true );
                        $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
                        $previewHTML = $parserOutput->mText;
                        $previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1 ) . "\n</pre>\n";
@@ -2378,10 +2380,10 @@ HTML
 
                                wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
 
-                               $parserOptions->setTidy( true );
                                $parserOptions->enableLimitReport();
-                               $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
-                                       $this->mTitle, $parserOptions );
+
+                               $toparse = $wgParser->preSaveTransform( $toparse, $this->mTitle, $wgUser, $parserOptions );
+                               $parserOutput = $wgParser->parse( $toparse, $this->mTitle, $parserOptions );
 
                                $previewHTML = $parserOutput->getText();
                                $this->mParserOutput = $parserOutput;
index 9b7a02c..fe85e8b 100644 (file)
@@ -1977,7 +1977,7 @@ class WikiPage extends Page {
                $edit = (object)array();
                $edit->revid = $revid;
                $edit->newText = $text;
-               $edit->pst = $this->preSaveTransform( $text, $user, $popts );
+               $edit->pst = $wgParser->preSaveTransform( $text, $this->mTitle, $user, $popts );
                $edit->popts = $this->makeParserOptions( 'canonical' );
                $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
                $edit->oldText = $this->getRawText();
@@ -2131,6 +2131,7 @@ class WikiPage extends Page {
         * This function is called right before saving the wikitext,
         * so we can do things like signatures and links-in-context.
         *
+        * @deprecated in 1.19; use Parser::preSaveTransform() instead
         * @param $text String article contents
         * @param $user User object: user doing the edit
         * @param $popts ParserOptions object: parser options, default options for
@@ -2140,6 +2141,9 @@ class WikiPage extends Page {
         */
        public function preSaveTransform( $text, User $user = null, ParserOptions $popts = null ) {
                global $wgParser, $wgUser;
+
+               wfDeprecated( __METHOD__ );
+
                $user = is_null( $user ) ? $wgUser : $user;
 
                if ( $popts === null ) {