Add the other existing $skin.css/.js to the message files too to be consistent
[lhc/web/wiklou.git] / includes / Parser_DiffTest.php
1 <?php
2
3 /**
4 * @ingroup Parser
5 */
6 class Parser_DiffTest
7 {
8 var $parsers, $conf;
9
10 var $dfUniqPrefix;
11
12 function __construct( $conf ) {
13 if ( !isset( $conf['parsers'] ) ) {
14 throw new MWException( __METHOD__ . ': no parsers specified' );
15 }
16 $this->conf = $conf;
17 $this->dtUniqPrefix = "\x7fUNIQ" . Parser::getRandomString();
18 }
19
20 function init() {
21 if ( !is_null( $this->parsers ) ) {
22 return;
23 }
24
25 global $wgHooks;
26 static $doneHook = false;
27 if ( !$doneHook ) {
28 $doneHook = true;
29 $wgHooks['ParserClearState'][] = array( $this, 'onClearState' );
30 }
31
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'];
38 }
39 $this->parsers[$i] = new $class( $parserConf );
40 }
41 }
42
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;
57 }
58 } else {
59 if ( $lastResult !== $currentResult ) {
60 $mismatch = true;
61 }
62 }
63 }
64 $results[$i] = $currentResult;
65 $lastResult = $currentResult;
66 }
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" );
71 }
72 return $lastResult;
73 }
74
75 function setFunctionHook( $id, $callback, $flags = 0 ) {
76 $this->init();
77 foreach ( $this->parsers as $i => $parser ) {
78 $parser->setFunctionHook( $id, $callback, $flags );
79 }
80 }
81
82 function onClearState( &$parser ) {
83 // hack marker prefixes to get identical output
84 $parser->mUniqPrefix = $this->dtUniqPrefix;
85 return true;
86 }
87 }