From 730c2c01a843cac4a98a12fe22ad7c2745abfe71 Mon Sep 17 00:00:00 2001 From: Jackmcbarn Date: Sun, 6 Apr 2014 21:03:02 -0400 Subject: [PATCH] Allow passing parameters to preload When pages are loaded in the edit box via preload, allow parameter substitution. The interface-style $1 is used rather than the template-style {{{1}}} to avoid conflicts with preloads that add template parameters. Syntax is: action=edit&preload=Foo&preloadparams[]=first&preloadparams[]=second Bug: 12853 Change-Id: If02cf4b3dba9f9d22a956d8bfff224677cbce00d --- includes/EditPage.php | 8 +++++--- includes/content/AbstractContent.php | 2 +- includes/content/Content.php | 3 ++- includes/content/WikitextContent.php | 5 +++-- includes/parser/Parser.php | 6 +++++- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index f57fc60581..c0d8d26f68 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -910,8 +910,9 @@ 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 { @@ -1116,12 +1117,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 ) ) { @@ -1175,7 +1177,7 @@ class EditPage { $content = $converted; } - return $content->preloadTransform( $title, $parserOptions ); + return $content->preloadTransform( $title, $parserOptions, $params ); } /** diff --git a/includes/content/AbstractContent.php b/includes/content/AbstractContent.php index f2f0c9d635..77d354294d 100644 --- a/includes/content/AbstractContent.php +++ b/includes/content/AbstractContent.php @@ -375,7 +375,7 @@ abstract class AbstractContent implements Content { * * @see Content::preloadTransform */ - public function preloadTransform( Title $title, ParserOptions $popts ) { + public function preloadTransform( Title $title, ParserOptions $popts, $params = array() ) { return $this; } diff --git a/includes/content/Content.php b/includes/content/Content.php index 075635d330..e9c6ac024d 100644 --- a/includes/content/Content.php +++ b/includes/content/Content.php @@ -437,10 +437,11 @@ interface Content { * * @param Title $title * @param ParserOptions $parserOptions + * @param array $params * * @return Content */ - public function preloadTransform( Title $title, ParserOptions $parserOptions ); + public function preloadTransform( Title $title, ParserOptions $parserOptions, $params = array() ); /** * Prepare Content for saving. Called before Content is saved by WikiPage::doEditContent() and in diff --git a/includes/content/WikitextContent.php b/includes/content/WikitextContent.php index 605222ef3d..13ef1b96db 100644 --- a/includes/content/WikitextContent.php +++ b/includes/content/WikitextContent.php @@ -154,14 +154,15 @@ class WikitextContent extends TextContent { * * @param Title $title * @param ParserOptions $popts + * @param array $params * * @return Content */ - public function preloadTransform( Title $title, ParserOptions $popts ) { + public function preloadTransform( Title $title, ParserOptions $popts, $params = array() ) { global $wgParser; $text = $this->getNativeData(); - $plt = $wgParser->getPreloadText( $text, $title, $popts ); + $plt = $wgParser->getPreloadText( $text, $title, $popts, $params ); return new WikitextContent( $plt ); } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index d7584ca67f..3b448e45d2 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -650,9 +650,13 @@ class Parser { * @param $text String * @param $title Title * @param $options ParserOptions + * @param $params Array * @return String */ - public function getPreloadText( $text, Title $title, ParserOptions $options ) { + public function getPreloadText( $text, Title $title, ParserOptions $options, $params = array() ) { + $msg = new RawMessage( $text ); + $text = $msg->params( $params )->plain(); + # Parser (re)initialisation $this->startParse( $title, $options, self::OT_PLAIN, true ); -- 2.20.1