Thread:Project:Support desk/Passing Javascript variables to a custom MediaWiki 1.16 Extension

Update: https://en.wikibooks.org/wiki/MediaWiki_Developer%27s_Handbook/Add_Button

I guess i can just ask php to ask javascript to do the query : ). but then. how to pass variables from the inline javascript to php? guess still have to find that out.

Update: I found how to get the MediaWiki variables for the page the user is reading:

jQuery( document ).ready( function( $ ) { 	$('#test').append("append"); 	$('#test').append(wgPageName);

(e.g. wgPageName is the name of the variable).

Not sure if the plan will work. Passing variable from javascript to the mediawiki extension seems the most difficult part now.

Hi. I installed MediaWiki 1.16.5 and some Semantic MediaWiki extensions at http://alteilwiki.99k.org/wiki/

How to pass javascript variables into a php parser extension that I am writing? If that is difficult, how to get the page title from mw.config in javascript? (I guess MediaWiki 1.16 has no resource loader.)

Long story: I want to query a wcf service despite the nice free webhost (Zymic. not sure if i can trust 000webhost) doesn't have SoapClient and the newest PHP. So, I add to Mediawiki: Common.js a javascript that uses jQuery to query the wcf service. Then, I write a mediawiki parser that directly reads the title of the article and the wiki text (i don't know how to change the wikitext directly, like preSaveTransform, in a mediawiki parser extension), and plan to make it write the wiki text back to the article.

However, if I pass the variables from java-script to the php extension, I guess that means the php extension is not invoked by the parser function, which means the php extension can't get the title of the page and modify the wikitext directly. The javascript can get that information (according to https://www.mediawiki.org/wiki/Manual:Interface/JavaScript).

I didn't know much about mediawiki, javascript, php, and php dom. Each of these steps took many tries (sometimes I reinstall everything).

Thank you for your help. I will be happy to know if there is an easier way too.

below is the php extension (ExampleExtension.php):

 __FILE__,	'name' => 'Example Parser Function',	'description' => 'A simple example parser function extension',	'descriptionmsg' => 'exampleextension-desc',	'version' => 1, 	'author' => 'Me',	'url' => 'https://www.mediawiki.org/wiki/Manual:Parser_functions', ); // Specify the function that will initialize the parser function. $wgHooks['ParserFirstCallInit'][] = 'ExampleExtensionSetupParserFunction'; // Allow translation of the parser function name $wgExtensionMessagesFiles['ExampleExtension'] = dirname( __FILE__ ). '/ExampleExtension.i18n.php'; // Tell MediaWiki that the parser function exists. function ExampleExtensionSetupParserFunction( &$parser ) { // Create a function hook associating the "example" magic word with the // ExampleExtensionRenderParserFunction function. See: the section // 'setFunctionHook' below for details. $parser->setFunctionHook( 'example', 'ExampleExtensionRenderParserFunction' ); // Return true so that MediaWiki continues to load extensions. return true; } // Render the output of the parser function. function ExampleExtensionRenderParserFunction( $parser, $param1 = , $param2 =  ) { // The input parameters are wikitext with templates expanded. // The output should be wikitext too.

$article = new Article($parser->getTitle, 0 ); $test = $parser->getTitle; $test2 = $article->fetchContent;

error_reporting(-1); $internal_errors = libxml_use_internal_errors(true); //hide those errors // $doc = new DOMDocument; $doc->loadHTML($test2); $div = $doc->getElementsByTagName('div');

foreach ( $div as $current) { $existID = $current->hasAttribute('cardid'); if ($existID){ $valueID = $current->getAttribute('cardid'); //the attribute has to be all lowercase. $current -> nodeValue = $valueID.'Helloworld'; //has to append with single quotation. i guess that means string. }	}

# remove <!DOCTYPE> $test2 = preg_replace(array("/^\<\!DOCTYPE.*? /si","!  $!si"),"",$doc->saveHTML);

libxml_use_internal_errors($internal_errors);

$output = "param1 is $test and param2 is $test2"; return $output; }