Add the other existing $skin.css/.js to the message files too to be consistent
[mediawiki.git] / includes / Parser_DiffTest.php
blobbe3702cf821c6c253a38fef9b4926d0d29f83416
1 <?php
3 /**
4 * @ingroup Parser
5 */
6 class Parser_DiffTest
8 var $parsers, $conf;
10 var $dfUniqPrefix;
12 function __construct( $conf ) {
13 if ( !isset( $conf['parsers'] ) ) {
14 throw new MWException( __METHOD__ . ': no parsers specified' );
16 $this->conf = $conf;
17 $this->dtUniqPrefix = "\x7fUNIQ" . Parser::getRandomString();
20 function init() {
21 if ( !is_null( $this->parsers ) ) {
22 return;
25 global $wgHooks;
26 static $doneHook = false;
27 if ( !$doneHook ) {
28 $doneHook = true;
29 $wgHooks['ParserClearState'][] = array( $this, 'onClearState' );
32 foreach ( $this->conf['parsers'] as $i => $parserConf ) {
33 if ( !is_array( $parserConf ) ) {
34 $class = $parserConf;
35 $parserConf = array( 'class' => $parserConf );
36 } else {
37 $class = $parserConf['class'];
39 $this->parsers[$i] = new $class( $parserConf );
43 function __call( $name, $args ) {
44 $this->init();
45 $results = array();
46 $mismatch = false;
47 $lastResult = null;
48 $first = true;
49 foreach ( $this->parsers as $i => $parser ) {
50 $currentResult = call_user_func_array( array( &$this->parsers[$i], $name ), $args );
51 if ( $first ) {
52 $first = false;
53 } else {
54 if ( is_object( $lastResult ) ) {
55 if ( $lastResult != $currentResult ) {
56 $mismatch = true;
58 } else {
59 if ( $lastResult !== $currentResult ) {
60 $mismatch = true;
64 $results[$i] = $currentResult;
65 $lastResult = $currentResult;
67 if ( $mismatch ) {
68 throw new MWException( "Parser_DiffTest: results mismatch on call to $name\n" .
69 'Arguments: ' . var_export( $args, true ) . "\n" .
70 'Results: ' . var_export( $results, true ) . "\n" );
72 return $lastResult;
75 function setFunctionHook( $id, $callback, $flags = 0 ) {
76 $this->init();
77 foreach ( $this->parsers as $i => $parser ) {
78 $parser->setFunctionHook( $id, $callback, $flags );
82 function onClearState( &$parser ) {
83 // hack marker prefixes to get identical output
84 $parser->mUniqPrefix = $this->dtUniqPrefix;
85 return true;