MediaWiki  1.23.14
Parser_DiffTest.php
Go to the documentation of this file.
1 <?php
28 {
30  var $shortOutput = false;
31 
33 
34  function __construct( $conf ) {
35  if ( !isset( $conf['parsers'] ) ) {
36  throw new MWException( __METHOD__ . ': no parsers specified' );
37  }
38  $this->conf = $conf;
39  }
40 
41  function init() {
42  if ( !is_null( $this->parsers ) ) {
43  return;
44  }
45 
47  static $doneHook = false;
48  if ( !$doneHook ) {
49  $doneHook = true;
50  $wgHooks['ParserClearState'][] = array( $this, 'onClearState' );
51  }
52  if ( isset( $this->conf['shortOutput'] ) ) {
53  $this->shortOutput = $this->conf['shortOutput'];
54  }
55 
56  foreach ( $this->conf['parsers'] as $i => $parserConf ) {
57  if ( !is_array( $parserConf ) ) {
58  $class = $parserConf;
59  $parserConf = array( 'class' => $parserConf );
60  } else {
61  $class = $parserConf['class'];
62  }
63  $this->parsers[$i] = new $class( $parserConf );
64  }
65  }
66 
67  function __call( $name, $args ) {
68  $this->init();
69  $results = array();
70  $mismatch = false;
71  $lastResult = null;
72  $first = true;
73  foreach ( $this->parsers as $i => $parser ) {
74  $currentResult = call_user_func_array( array( &$this->parsers[$i], $name ), $args );
75  if ( $first ) {
76  $first = false;
77  } else {
78  if ( is_object( $lastResult ) ) {
79  if ( $lastResult != $currentResult ) {
80  $mismatch = true;
81  }
82  } else {
83  if ( $lastResult !== $currentResult ) {
84  $mismatch = true;
85  }
86  }
87  }
88  $results[$i] = $currentResult;
89  $lastResult = $currentResult;
90  }
91  if ( $mismatch ) {
92  if ( count( $results ) == 2 ) {
93  $resultsList = array();
94  foreach ( $this->parsers as $i => $parser ) {
95  $resultsList[] = var_export( $results[$i], true );
96  }
97  $diff = wfDiff( $resultsList[0], $resultsList[1] );
98  } else {
99  $diff = '[too many parsers]';
100  }
101  $msg = "Parser_DiffTest: results mismatch on call to $name\n";
102  if ( !$this->shortOutput ) {
103  $msg .= 'Arguments: ' . $this->formatArray( $args ) . "\n";
104  }
105  $msg .= 'Results: ' . $this->formatArray( $results ) . "\n" .
106  "Diff: $diff\n";
107  throw new MWException( $msg );
108  }
109  return $lastResult;
110  }
111 
112  function formatArray( $array ) {
113  if ( $this->shortOutput ) {
114  foreach ( $array as $key => $value ) {
115  if ( $value instanceof ParserOutput ) {
116  $array[$key] = "ParserOutput: {$value->getText()}";
117  }
118  }
119  }
120  return var_export( $array, true );
121  }
122 
123  function setFunctionHook( $id, $callback, $flags = 0 ) {
124  $this->init();
125  foreach ( $this->parsers as $parser ) {
126  $parser->setFunctionHook( $id, $callback, $flags );
127  }
128  }
129 
134  function onClearState( &$parser ) {
135  // hack marker prefixes to get identical output
136  if ( !isset( $this->dtUniqPrefix ) ) {
137  $this->dtUniqPrefix = $parser->uniqPrefix();
138  } else {
139  $parser->mUniqPrefix = $this->dtUniqPrefix;
140  }
141  return true;
142  }
143 }
Parser_DiffTest\__call
__call( $name, $args)
Definition: Parser_DiffTest.php:67
Parser_DiffTest\$dtUniqPrefix
$dtUniqPrefix
Definition: Parser_DiffTest.php:32
ParserOutput
Definition: ParserOutput.php:24
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfDiff
wfDiff( $before, $after, $params='-u')
Returns unified plain-text diff of two texts.
Definition: GlobalFunctions.php:3228
$wgHooks
$wgHooks['ArticleShow'][]
Definition: hooks.txt:110
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2124
MWException
MediaWiki exception.
Definition: MWException.php:26
$parser
do that in ParserLimitReportFormat instead $parser
Definition: hooks.txt:1961
Parser_DiffTest\$shortOutput
$shortOutput
Definition: Parser_DiffTest.php:30
Parser_DiffTest
Definition: Parser_DiffTest.php:27
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Parser_DiffTest\setFunctionHook
setFunctionHook( $id, $callback, $flags=0)
Definition: Parser_DiffTest.php:123
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$value
$value
Definition: styleTest.css.php:45
Parser_DiffTest\init
init()
Definition: Parser_DiffTest.php:41
$args
if( $line===false) $args
Definition: cdb.php:62
Parser_DiffTest\onClearState
onClearState(&$parser)
Definition: Parser_DiffTest.php:134
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Parser_DiffTest\$conf
$conf
Definition: Parser_DiffTest.php:29
Parser_DiffTest\formatArray
formatArray( $array)
Definition: Parser_DiffTest.php:112
Parser_DiffTest\__construct
__construct( $conf)
Definition: Parser_DiffTest.php:34
Parser_DiffTest\$parsers
$parsers
Definition: Parser_DiffTest.php:29