From 14ebd075390e3021c43579053b6267203c78212b Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Sun, 7 Feb 2010 11:59:58 +0000 Subject: [PATCH] Initialize parser properly in getTransclusionText() --- includes/EditPage.php | 4 ++-- includes/parser/Parser.php | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 7cf8abfa95..b0f90fe70c 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -227,13 +227,13 @@ class EditPage { * @return string The contents of the page. */ protected function getPreloadedText( $preload ) { - global $wgParser; + global $wgParser, $wgUser; if ( !empty( $this->mPreloadText ) ) { return $this->mPreloadText; } else { $preloadTitle = Title::newFromText( $preload ); if ( isset( $preloadTitle ) && $preloadTitle->userCanRead() ) { - return $wgParser->getTransclusionText( $preloadTitle ); + return $wgParser->getTransclusionText( $preloadTitle, ParserOptions::newFromUser( $wgUser ) ); } } } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 3f97d78bba..02e05c8806 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -15,7 +15,7 @@ * (which in turn the browser understands, and can display). * *
- * There are five main entry points into the Parser class:
+ * There are six main entry points into the Parser class:
  * parse()
  *   produces HTML output
  * preSaveTransform().
@@ -26,6 +26,8 @@
  *   Cleans a signature before saving it to preferences
  * extractSections()
  *   Extracts sections from an article for section editing
+ * getTransclusionText()
+ *   Extracts the text of a template with only , etc., parsed
  *
  * Globals used:
  *    objects:   $wgLang, $wgContLang
@@ -82,6 +84,7 @@ class Parser
 	const OT_WIKI = 2;
 	const OT_PREPROCESS = 3;
 	const OT_MSG = 3;
+	const OT_INCLUDES = 4;
 
 	// Marker Suffix needs to be accessible staticly.
 	const MARKER_SUFFIX = "-QINU\x7f";
@@ -500,7 +503,13 @@ class Parser
 	 *
 	 * This is not called by the parser itself, see braceSubstitution for its transclusion. 
 	 */
-	public function getTransclusionText( $title ) {
+	public function getTransclusionText( $title, $options ) {
+		// Must initialize first
+		$this->clearState();
+		$this->setOutputType( self::OT_INCLUDES );
+		$this->mOptions = $options;
+		$this->setTitle( new FakeTitle ); 
+
 		list( $text, $title ) = $this->getTemplateDom( $title );
 		$flags = PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES;
 		return $this->getPreprocessor()->newFrame()->expand( $text, $flags );
-- 
2.20.1