* self::OT_HTML: all templates and extension tags
*
* @param string $tex The text to transform
- * @param PPFrame $frame Object describing the arguments passed to the template
+ * @param PPFrame $frame Object describing the arguments passed to the template.
+ * Arguments may also be provided as an associative array, as was the usual case before MW1.12.
+ * Providing arguments this way may be useful for extensions wishing to perform variable replacement explicitly.
* @param bool $argsOnly Only do argument (triple-brace) expansion, not double-brace expansion
* @private
*/
if ( $frame === false ) {
$frame = $this->getPreprocessor()->newFrame();
} elseif ( !( $frame instanceof PPFrame ) ) {
- throw new MWException( __METHOD__ . ' called using the old argument format' );
+ wfDebug( __METHOD__." called using plain parameters instead of a PPFrame instance. Creating custom frame.\n" );
+ $frame = $this->getPreprocessor()->newCustomFrame($frame);
}
$dom = $this->preprocessToDom( $text );
/** Create a new top-level frame for expansion of a page */
function newFrame();
+ /** Create a new custom frame for programmatic use of parameter replacement as used in some extensions */
+ function newCustomFrame( $args );
+
/** Preprocess text to a PPNode */
function preprocessToObj( $text, $flags = 0 );
}
return new PPFrame_DOM( $this );
}
+ function newCustomFrame( $args ) {
+ return new PPCustomFrame_DOM( $this, $args );
+ }
+
function memCheck() {
if ( $this->memoryLimit === false ) {
return;
}
}
+/**
+ * Expansion frame with custom arguments
+ * @ingroup Parser
+ */
+class PPCustomFrame_DOM extends PPFrame_DOM {
+ var $args;
+
+ function __construct( $preprocessor, $args ) {
+ $this->preprocessor = $preprocessor;
+ $this->parser = $preprocessor->parser;
+ $this->args = $args;
+ }
+
+ function __toString() {
+ $s = 'cstmframe{';
+ $first = true;
+ foreach ( $this->args as $name => $value ) {
+ if ( $first ) {
+ $first = false;
+ } else {
+ $s .= ', ';
+ }
+ $s .= "\"$name\":\"" .
+ str_replace( '"', '\\"', $value->__toString() ) . '"';
+ }
+ $s .= '}';
+ return $s;
+ }
+
+ function isEmpty() {
+ return !count( $this->args );
+ }
+
+ function getArgument( $index ) {
+ return $this->args[$index];
+ }
+}
+
/**
* @ingroup Parser
*/
return new PPFrame_Hash( $this );
}
+ function newCustomFrame( $args ) {
+ return new PPCustomFrame_Hash( $this, $args );
+ }
+
/**
* Preprocess some wikitext and return the document tree.
* This is the ghost of Parser::replace_variables().
}
}
+/**
+ * Expansion frame with custom arguments
+ * @ingroup Parser
+ */
+class PPCustomFrame_Hash extends PPFrame_Hash {
+ var $args;
+
+ function __construct( $preprocessor, $args ) {
+ $this->preprocessor = $preprocessor;
+ $this->parser = $preprocessor->parser;
+ $this->args = $args;
+ }
+
+ function __toString() {
+ $s = 'cstmframe{';
+ $first = true;
+ foreach ( $this->args as $name => $value ) {
+ if ( $first ) {
+ $first = false;
+ } else {
+ $s .= ', ';
+ }
+ $s .= "\"$name\":\"" .
+ str_replace( '"', '\\"', $value->__toString() ) . '"';
+ }
+ $s .= '}';
+ return $s;
+ }
+
+ function isEmpty() {
+ return !count( $this->args );
+ }
+
+ function getArgument( $index ) {
+ return $this->args[$index];
+ }
+}
+
/**
* @ingroup Parser
*/