From f367303c9eb9695a7496595429e2b579e8285f81 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 5 Feb 2010 16:49:21 +0000 Subject: [PATCH] bug 5210 - add getTransclusionText() to the Parser to remove the horrible (and very broken) attempt to reimplement bits of the preprocessor in EditPage.php. --- RELEASE-NOTES | 1 + includes/EditPage.php | 13 ++----------- includes/parser/Parser.php | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 30ff67cda4..1aa4a2509c 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -825,6 +825,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 18758) API read of watchlist's wl_notificationtimestamp * (bug 20809) Expose EditFormPreloadText via the API * (bug 18427) Comment (edit summary) parser option for API +* (bug 5210) preload parser should parse (as well as ) === Languages updated in 1.16 === diff --git a/includes/EditPage.php b/includes/EditPage.php index ad9c993275..7cf8abfa95 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -227,22 +227,13 @@ class EditPage { * @return string The contents of the page. */ protected function getPreloadedText( $preload ) { + global $wgParser; if ( !empty( $this->mPreloadText ) ) { return $this->mPreloadText; - } elseif ( $preload === '' ) { - return ''; } else { $preloadTitle = Title::newFromText( $preload ); if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) { - $rev = Revision::newFromTitle( $preloadTitle ); - if ( is_object( $rev ) ) { - $text = $rev->getText(); - // TODO FIXME: AAAAAAAAAAA, this shouldn't be implementing - // its own mini-parser! -ævar - $text = preg_replace( '~~', '', $text ); - return $text; - } else - return ''; + return $wgParser->getTransclusionText( $preloadTitle ); } } } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index a26b49fc9c..dbbe93ec69 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -492,6 +492,22 @@ class Parser return $text; } + /** + * Get the wikitext of a page as though it was transcluded. + * + * Specifically etc. are parsed, redirects are followed, comments + * are removed, but templates arguments and parser functions are untouched. + * + * This is not called by the parser itself, see braceSubstitution for its transclusion. + * + * @public + */ + function getTransclusionText( $title ) { + list($text, $title) = $this->getTemplateDom( $title ); + $flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES; + return $this->getPreprocessor()->newFrame()->expand( $text, $flags ); + } + /** * Get a random string * -- 2.20.1