MediaWiki REL1_28
ParserDiffTest.php
Go to the documentation of this file.
1<?php
28{
29 public $parsers;
30 public $conf;
31 public $shortOutput = false;
32
33 public function __construct( $conf ) {
34 if ( !isset( $conf['parsers'] ) ) {
35 throw new MWException( __METHOD__ . ': no parsers specified' );
36 }
37 $this->conf = $conf;
38 }
39
40 public function init() {
41 if ( !is_null( $this->parsers ) ) {
42 return;
43 }
44
45 if ( isset( $this->conf['shortOutput'] ) ) {
46 $this->shortOutput = $this->conf['shortOutput'];
47 }
48
49 foreach ( $this->conf['parsers'] as $i => $parserConf ) {
50 if ( !is_array( $parserConf ) ) {
51 $class = $parserConf;
52 $parserConf = [ 'class' => $parserConf ];
53 } else {
54 $class = $parserConf['class'];
55 }
56 $this->parsers[$i] = new $class( $parserConf );
57 }
58 }
59
60 public function __call( $name, $args ) {
61 $this->init();
62 $results = [];
63 $mismatch = false;
64 $lastResult = null;
65 $first = true;
66 foreach ( $this->parsers as $i => $parser ) {
67 $currentResult = call_user_func_array( [ &$this->parsers[$i], $name ], $args );
68 if ( $first ) {
69 $first = false;
70 } else {
71 if ( is_object( $lastResult ) ) {
72 if ( $lastResult != $currentResult ) {
73 $mismatch = true;
74 }
75 } else {
76 if ( $lastResult !== $currentResult ) {
77 $mismatch = true;
78 }
79 }
80 }
81 $results[$i] = $currentResult;
82 $lastResult = $currentResult;
83 }
84 if ( $mismatch ) {
85 if ( count( $results ) == 2 ) {
86 $resultsList = [];
87 foreach ( $this->parsers as $i => $parser ) {
88 $resultsList[] = var_export( $results[$i], true );
89 }
90 $diff = wfDiff( $resultsList[0], $resultsList[1] );
91 } else {
92 $diff = '[too many parsers]';
93 }
94 $msg = "ParserDiffTest: results mismatch on call to $name\n";
95 if ( !$this->shortOutput ) {
96 $msg .= 'Arguments: ' . $this->formatArray( $args ) . "\n";
97 }
98 $msg .= 'Results: ' . $this->formatArray( $results ) . "\n" .
99 "Diff: $diff\n";
100 throw new MWException( $msg );
101 }
102 return $lastResult;
103 }
104
105 public function formatArray( $array ) {
106 if ( $this->shortOutput ) {
107 foreach ( $array as $key => $value ) {
108 if ( $value instanceof ParserOutput ) {
109 $array[$key] = "ParserOutput: {$value->getText()}";
110 }
111 }
112 }
113 return var_export( $array, true );
114 }
115
116 public function setFunctionHook( $id, $callback, $flags = 0 ) {
117 $this->init();
118 foreach ( $this->parsers as $parser ) {
119 $parser->setFunctionHook( $id, $callback, $flags );
120 }
121 }
122}
wfDiff( $before, $after, $params='-u')
Returns unified plain-text diff of two texts.
if( $line===false) $args
Definition cdb.php:64
MediaWiki exception.
setFunctionHook( $id, $callback, $flags=0)
__call( $name, $args)
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
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead $parser
Definition hooks.txt:2259
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2710
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37