Hi there, I am investigating a breakage in my extension that has occurred in MW 1.34 but which didn't seem to be a problem on MW 1.29. (I have not tested interim versions to see where the issue first arises.)
One of the parser hooks in the extension needs to perform variable expansion. What is happening is a lot more complicated than this example, but effectively <my_hook Foo="What the foo!">{{{Foo}}}</my_hook> should end up generating the following output, using variable expansion: What the foo! The semantics of variable handling need to follow the MW semantics, including default values (possibly nested), parser functions, etc. therefore it needs to use the MW parser to perform the expansion. Assuming the arguments that MW passes into the parser hook are named $Text, $Vars, $Parser and $Frame, the relevant code looks something like this (again, a bit more complicated in practice): $NewFrame = new PPTemplateFrame_DOM($Frame->preprocessor, $Frame, array(), $Vars, $Frame->title); return $Parser->replaceVariables($Text, $NewFrame); (I have included a more detailed listing of the code that I am using for doing the parse at the end of this message.) My code was working fine on MW 1.29 and earlier, but when I upgrade to 1.34 I am finding that I get a fatal exception thrown when my tag is encountered: /index.php?title=Main_Page MWException from line 373 of ~\includes\parser\PPFrame_DOM.php: PPFrame_DOM::expand: Invalid parameter type I have generated a backtrace and the top of the stack is as follows: #0 ~\includes\parser\Parser.php(3330): PPFrame_DOM->expand(PPNode_Hash_Tree, integer) #1 MyExtension.php (434): Parser->replaceVariables(string, PPTemplateFrame_DOM) #2 ~\includes\parser\Parser.php(4293): MyExtensionParserHook(string, array, Parser, PPTemplateFrame_Hash) (The subsequent call stack entries are the parent functions you would expect to see in that situation.) Can anyone see why the above code would no longer work as it did on previous versions? What is the current recommended method for manually expanding template variables from within a parser hook? Kind regards, - Mark Clements (HappyDog) ---------------------------------- Full example (with extension-specific code omitted): ---------------------------------- function MyExtensionParserHook($Text, $Vars, $Parser, $Frame) { // 1) Manipulate $Text and $Vars // (omitted) // 2) Expand variables in the resulting text. // Set up a new frame which mirrors the existing one but which also has the // field values as arguments. // If we are already in a template frame, merge the field arguments with the // existing template arguments first. if ($Frame instanceof PPTemplateFrame_DOM) { $NumberedArgs = $Frame->numberedArgs; $NamedArgs = array_merge($Frame->namedArgs, $Vars); } else { $NumberedArgs = array(); $NamedArgs = $Vars; } $NewFrame = new PPTemplateFrame_DOM($Frame->preprocessor, $Frame, $NumberedArgs, $NamedArgs, $Frame->title); // Perform a recursive parse on the input, using our newly created frame. return $Parser->replaceVariables($Text, $NewFrame); } _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l