Allow passing parameters to preload
authorJackmcbarn <jackmcbarn@gmail.com>
Mon, 7 Apr 2014 01:03:02 +0000 (21:03 -0400)
committerJackmcbarn <jackmcbarn@gmail.com>
Mon, 7 Apr 2014 01:03:02 +0000 (21:03 -0400)
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
includes/content/AbstractContent.php
includes/content/Content.php
includes/content/WikitextContent.php
includes/parser/Parser.php

index f57fc60..c0d8d26 100644 (file)
@@ -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 );
        }
 
        /**
index f2f0c9d..77d3542 100644 (file)
@@ -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;
        }
 
index 075635d..e9c6ac0 100644 (file)
@@ -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
index 605222e..13ef1b9 100644 (file)
@@ -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 );
        }
index d7584ca..3b448e4 100644 (file)
@@ -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 );