r103228 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103227‎ | r103228 | r103229 >
Date:21:46, 15 November 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
Deprecated WikiPage::preSaveTransform() in favour of Parser::preSaveTransform() and updated callers; added wfDeprecated() call since there are no callers in extensions
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/WikiPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/EditPage.php
@@ -2091,13 +2091,16 @@
20922092 * save and then make a comparison.
20932093 */
20942094 function showDiff() {
 2095+ global $wgUser, $wgContLang, $wgParser;
 2096+
20952097 $oldtext = $this->mArticle->fetchContent();
20962098 $newtext = $this->mArticle->replaceSection(
20972099 $this->section, $this->textbox1, $this->summary, $this->edittime );
20982100
20992101 wfRunHooks( 'EditPageGetDiffText', array( $this, &$newtext ) );
21002102
2101 - $newtext = $this->mArticle->preSaveTransform( $newtext );
 2103+ $popts = ParserOptions::newFromUserAndLang( $wgUser, $wgContLang );
 2104+ $newtext = $wgParser->preSaveTransform( $newtext, $this->mTitle, $wgUser, $popts );
21022105 $oldtitle = wfMsgExt( 'currentrev', array( 'parseinline' ) );
21032106 $newtitle = wfMsgExt( 'yourtext', array( 'parseinline' ) );
21042107 if ( $oldtext !== false || $newtext != '' ) {
@@ -2296,10 +2299,25 @@
22972300 * @return string
22982301 */
22992302 function getPreviewText() {
2300 - global $wgOut, $wgUser, $wgParser;
 2303+ global $wgOut, $wgUser, $wgParser, $wgRawHtml;
23012304
23022305 wfProfileIn( __METHOD__ );
23032306
 2307+ if ( $wgRawHtml && !$this->mTokenOk ) {
 2308+ // Could be an offsite preview attempt. This is very unsafe if
 2309+ // HTML is enabled, as it could be an attack.
 2310+ $parsedNote = '';
 2311+ if ( $this->textbox1 !== '' ) {
 2312+ // Do not put big scary notice, if previewing the empty
 2313+ // string, which happens when you initially edit
 2314+ // a category page, due to automatic preview-on-open.
 2315+ $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
 2316+ wfMsg( 'session_fail_preview_html' ) . "</div>", true, /* interface */true );
 2317+ }
 2318+ wfProfileOut( __METHOD__ );
 2319+ return $parsedNote;
 2320+ }
 2321+
23042322 if ( $this->mTriedSave && !$this->mTokenOk ) {
23052323 if ( $this->mTokenOkExceptSuffix ) {
23062324 $note = wfMsg( 'token_suffix_mismatch' );
@@ -2314,25 +2332,10 @@
23152333
23162334 $parserOptions = ParserOptions::newFromUser( $wgUser );
23172335 $parserOptions->setEditSection( false );
 2336+ $parserOptions->setTidy( true );
23182337 $parserOptions->setIsPreview( true );
23192338 $parserOptions->setIsSectionPreview( !is_null($this->section) && $this->section !== '' );
23202339
2321 - global $wgRawHtml;
2322 - if ( $wgRawHtml && !$this->mTokenOk ) {
2323 - // Could be an offsite preview attempt. This is very unsafe if
2324 - // HTML is enabled, as it could be an attack.
2325 - $parsedNote = '';
2326 - if ( $this->textbox1 !== '' ) {
2327 - // Do not put big scary notice, if previewing the empty
2328 - // string, which happens when you initially edit
2329 - // a category page, due to automatic preview-on-open.
2330 - $parsedNote = $wgOut->parse( "<div class='previewnote'>" .
2331 - wfMsg( 'session_fail_preview_html' ) . "</div>", true, /* interface */true );
2332 - }
2333 - wfProfileOut( __METHOD__ );
2334 - return $parsedNote;
2335 - }
2336 -
23372340 # don't parse non-wikitext pages, show message about preview
23382341 # 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?
23392342
@@ -2359,7 +2362,6 @@
23602363 }
23612364 }
23622365
2363 - $parserOptions->setTidy( true );
23642366 $parserOutput = $wgParser->parse( $previewtext, $this->mTitle, $parserOptions );
23652367 $previewHTML = $parserOutput->mText;
23662368 $previewHTML .= "<pre class=\"$class\" dir=\"ltr\">\n" . htmlspecialchars( $this->textbox1 ) . "\n</pre>\n";
@@ -2378,11 +2380,11 @@
23792381
23802382 wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
23812383
2382 - $parserOptions->setTidy( true );
23832384 $parserOptions->enableLimitReport();
2384 - $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
2385 - $this->mTitle, $parserOptions );
23862385
 2386+ $toparse = $wgParser->preSaveTransform( $toparse, $this->mTitle, $wgUser, $parserOptions );
 2387+ $parserOutput = $wgParser->parse( $toparse, $this->mTitle, $parserOptions );
 2388+
23872389 $previewHTML = $parserOutput->getText();
23882390 $this->mParserOutput = $parserOutput;
23892391 $wgOut->addParserOutputNoText( $parserOutput );
Index: trunk/phase3/includes/WikiPage.php
@@ -1977,7 +1977,7 @@
19781978 $edit = (object)array();
19791979 $edit->revid = $revid;
19801980 $edit->newText = $text;
1981 - $edit->pst = $this->preSaveTransform( $text, $user, $popts );
 1981+ $edit->pst = $wgParser->preSaveTransform( $text, $this->mTitle, $user, $popts );
19821982 $edit->popts = $this->makeParserOptions( 'canonical' );
19831983 $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $edit->popts, true, true, $revid );
19841984 $edit->oldText = $this->getRawText();
@@ -2131,6 +2131,7 @@
21322132 * This function is called right before saving the wikitext,
21332133 * so we can do things like signatures and links-in-context.
21342134 *
 2135+ * @deprecated in 1.19; use Parser::preSaveTransform() instead
21352136 * @param $text String article contents
21362137 * @param $user User object: user doing the edit
21372138 * @param $popts ParserOptions object: parser options, default options for
@@ -2140,6 +2141,9 @@
21412142 */
21422143 public function preSaveTransform( $text, User $user = null, ParserOptions $popts = null ) {
21432144 global $wgParser, $wgUser;
 2145+
 2146+ wfDeprecated( __METHOD__ );
 2147+
21442148 $user = is_null( $user ) ? $wgUser : $user;
21452149
21462150 if ( $popts === null ) {

Comments

#Comment by IAlex (talk | contribs)   21:48, 15 November 2011

And I forgot to say that I moved the part of code responsible to check for edit token when $wgRawHtml is true to the top of EditPage::getPreviewText() to avoid running useless code.

Status & tagging log