31require_once __DIR__ .
'/dumpIterator.php';
56 parent::__construct();
57 $this->saveFailed =
false;
58 $this->
addDescription(
'Run a file or dump with several parsers' );
59 $this->
addOption(
'parser1',
'The first parser to compare.',
true,
true );
60 $this->
addOption(
'parser2',
'The second parser to compare.',
true,
true );
63 'Folder in which articles which differ will be stored.',
67 $this->
addOption(
'show-diff',
'Show a diff of the two renderings.',
false,
false );
70 'Binary to use for diffing (can also be provided by DIFF env var).',
76 'Remove parameters of html tags to increase readability.',
82 'Show the parsed html if both Parsers give the same output.',
89 if ( $this->
hasOption(
'save-failed' ) ) {
90 $this->saveFailed = $this->
getOption(
'save-failed' );
93 $this->stripParametersEnabled = $this->
hasOption(
'strip-parameters' );
94 $this->showParsedOutput = $this->
hasOption(
'show-parsed-output' );
96 $this->showDiff = $this->
hasOption(
'show-diff' );
97 if ( $this->showDiff ) {
98 $bin = $this->
getOption(
'diff-bin', getenv(
'DIFF' ) );
106 $this->options = ParserOptions::newFromUser( $user );
112 $this->
error(
"{$this->failed} failed revisions out of {$this->count}" );
113 if ( $this->count > 0 ) {
114 $this->
output(
" (" . ( $this->failed / $this->count ) .
"%)\n" );
119 if ( !$this->stripParametersEnabled ) {
123 return preg_replace(
'/(<a) [^>]+>/',
'$1>', $text );
133 $parser1Name = $this->
getOption(
'parser1' );
134 $parser2Name = $this->
getOption(
'parser2' );
139 $parser1 =
new $parser1Name();
140 $parser2 =
new $parser2Name();
145 $this->
error(
"Page {$title->getPrefixedText()} does not contain wikitext "
146 .
"but {$content->getModel()}\n" );
152 '@phan-var WikitextContent $content';
153 $text = strval(
$content->getText() );
155 $output1 = $parser1->parse( $text,
$title, $this->options );
156 $output2 = $parser2->parse( $text,
$title, $this->options );
158 if ( $output1->getText() != $output2->getText() ) {
160 $this->
error(
"Parsing for {$title->getPrefixedText()} differs\n" );
162 if ( $this->saveFailed ) {
164 $this->saveFailed .
'/' . rawurlencode(
$title->getPrefixedText() ) .
".txt",
168 if ( $this->showDiff ) {
174 $unifiedDiff = $formatter->format( $diffs );
176 $this->
output( $unifiedDiff );
181 if ( $this->showParsedOutput ) {
189 if ( !class_exists( $parserName ) && file_exists(
"$parserName.php" ) ) {
197require_once RUN_MAINTENANCE_IF_MAIN;
$wgAutoloadClasses
Array mapping class names to filenames, for autoloading.
$wgDiff
Path to the GNU diff utility.
const CONTENT_MODEL_WIKITEXT
Maintenance script to take page text out of an XML dump file and render basic HTML out to files.
bool $stripParametersEnabled
static checkParserLocally( $parserName)
conclusions()
Stub function for giving data about what was computed.
processRevision(WikiRevision $rev)
Callback function for each revision, parse with both parsers and compare.
__construct()
Default constructor.
checkOptions()
Stub function for processing additional options.
Class representing a 'diff' between two sequences of strings.
Base class for interating over a dump.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Set options of the Parser.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Represents a revision, log entry or upload during the import process.
getContent( $role=SlotRecord::MAIN)