2007-11-20 10:55:08 +00:00
|
|
|
<?php
|
2010-08-22 14:31:05 +00:00
|
|
|
/**
|
|
|
|
|
* Fake parser that output the difference of two different parsers
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
|
|
|
|
* @ingroup Parser
|
|
|
|
|
*/
|
2007-11-20 10:55:08 +00:00
|
|
|
class Parser_DiffTest
|
|
|
|
|
{
|
|
|
|
|
var $parsers, $conf;
|
2008-08-15 16:03:38 +00:00
|
|
|
var $shortOutput = false;
|
2007-11-20 10:55:08 +00:00
|
|
|
|
2010-10-15 22:12:19 +00:00
|
|
|
var $dtUniqPrefix;
|
2008-02-05 08:23:58 +00:00
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
function __construct( $conf ) {
|
|
|
|
|
if ( !isset( $conf['parsers'] ) ) {
|
|
|
|
|
throw new MWException( __METHOD__ . ': no parsers specified' );
|
|
|
|
|
}
|
|
|
|
|
$this->conf = $conf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
|
if ( !is_null( $this->parsers ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-02-05 08:23:58 +00:00
|
|
|
|
|
|
|
|
global $wgHooks;
|
|
|
|
|
static $doneHook = false;
|
|
|
|
|
if ( !$doneHook ) {
|
|
|
|
|
$doneHook = true;
|
|
|
|
|
$wgHooks['ParserClearState'][] = array( $this, 'onClearState' );
|
|
|
|
|
}
|
2008-08-15 16:03:38 +00:00
|
|
|
if ( isset( $this->conf['shortOutput'] ) ) {
|
|
|
|
|
$this->shortOutput = $this->conf['shortOutput'];
|
|
|
|
|
}
|
2008-02-05 08:23:58 +00:00
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
foreach ( $this->conf['parsers'] as $i => $parserConf ) {
|
|
|
|
|
if ( !is_array( $parserConf ) ) {
|
|
|
|
|
$class = $parserConf;
|
2008-01-24 04:29:56 +00:00
|
|
|
$parserConf = array( 'class' => $parserConf );
|
2007-11-20 10:55:08 +00:00
|
|
|
} else {
|
|
|
|
|
$class = $parserConf['class'];
|
|
|
|
|
}
|
|
|
|
|
$this->parsers[$i] = new $class( $parserConf );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function __call( $name, $args ) {
|
|
|
|
|
$this->init();
|
|
|
|
|
$results = array();
|
|
|
|
|
$mismatch = false;
|
|
|
|
|
$lastResult = null;
|
|
|
|
|
$first = true;
|
|
|
|
|
foreach ( $this->parsers as $i => $parser ) {
|
|
|
|
|
$currentResult = call_user_func_array( array( &$this->parsers[$i], $name ), $args );
|
|
|
|
|
if ( $first ) {
|
|
|
|
|
$first = false;
|
|
|
|
|
} else {
|
2008-02-05 08:23:58 +00:00
|
|
|
if ( is_object( $lastResult ) ) {
|
|
|
|
|
if ( $lastResult != $currentResult ) {
|
|
|
|
|
$mismatch = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ( $lastResult !== $currentResult ) {
|
|
|
|
|
$mismatch = true;
|
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$results[$i] = $currentResult;
|
|
|
|
|
$lastResult = $currentResult;
|
|
|
|
|
}
|
|
|
|
|
if ( $mismatch ) {
|
2008-08-26 14:37:15 +00:00
|
|
|
if ( count( $results ) == 2 ) {
|
|
|
|
|
$resultsList = array();
|
|
|
|
|
foreach ( $this->parsers as $i => $parser ) {
|
|
|
|
|
$resultsList[] = var_export( $results[$i], true );
|
|
|
|
|
}
|
|
|
|
|
$diff = wfDiff( $resultsList[0], $resultsList[1] );
|
|
|
|
|
} else {
|
|
|
|
|
$diff = '[too many parsers]';
|
|
|
|
|
}
|
|
|
|
|
$msg = "Parser_DiffTest: results mismatch on call to $name\n";
|
|
|
|
|
if ( !$this->shortOutput ) {
|
|
|
|
|
$msg .= 'Arguments: ' . $this->formatArray( $args ) . "\n";
|
|
|
|
|
}
|
|
|
|
|
$msg .= 'Results: ' . $this->formatArray( $results ) . "\n" .
|
|
|
|
|
"Diff: $diff\n";
|
|
|
|
|
throw new MWException( $msg );
|
2007-11-20 10:55:08 +00:00
|
|
|
}
|
|
|
|
|
return $lastResult;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-15 16:03:38 +00:00
|
|
|
function formatArray( $array ) {
|
|
|
|
|
if ( $this->shortOutput ) {
|
|
|
|
|
foreach ( $array as $key => $value ) {
|
|
|
|
|
if ( $value instanceof ParserOutput ) {
|
|
|
|
|
$array[$key] = "ParserOutput: {$value->getText()}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return var_export( $array, true );
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-20 10:55:08 +00:00
|
|
|
function setFunctionHook( $id, $callback, $flags = 0 ) {
|
|
|
|
|
$this->init();
|
2010-10-14 20:53:04 +00:00
|
|
|
foreach ( $this->parsers as $parser ) {
|
2007-11-20 10:55:08 +00:00
|
|
|
$parser->setFunctionHook( $id, $callback, $flags );
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-02-05 08:23:58 +00:00
|
|
|
|
2011-02-08 23:18:13 +00:00
|
|
|
/**
|
|
|
|
|
* @param $parser Parser
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2008-02-05 08:23:58 +00:00
|
|
|
function onClearState( &$parser ) {
|
|
|
|
|
// hack marker prefixes to get identical output
|
2010-10-15 22:12:19 +00:00
|
|
|
if ( !isset( $this->dtUniqPrefix ) ) {
|
2010-10-17 14:10:26 +00:00
|
|
|
$this->dtUniqPrefix = $parser->uniqPrefix();
|
2010-10-15 22:12:19 +00:00
|
|
|
} else {
|
|
|
|
|
$parser->mUniqPrefix = $this->dtUniqPrefix;
|
|
|
|
|
}
|
2008-02-05 08:23:58 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
2007-11-20 10:55:08 +00:00
|
|
|
}
|