35 require_once __DIR__ .
'/dumpIterator.php';
47 private $saveFailed =
false;
49 private $stripParametersEnabled;
51 private $showParsedOutput;
60 parent::__construct();
61 $this->
addDescription(
'Run a file or dump with several parsers' );
62 $this->
addOption(
'parser1',
'The first parser to compare.',
true,
true );
63 $this->
addOption(
'parser2',
'The second parser to compare.',
true,
true );
66 'Folder in which articles which differ will be stored.',
70 $this->
addOption(
'show-diff',
'Show a diff of the two renderings.',
false,
false );
73 'Binary to use for diffing (can also be provided by DIFF env var).',
79 'Remove parameters of html tags to increase readability.',
85 'Show the parsed html if both Parsers give the same output.',
92 if ( $this->
hasOption(
'save-failed' ) ) {
93 $this->saveFailed = $this->
getOption(
'save-failed' );
96 $this->stripParametersEnabled = $this->
hasOption(
'strip-parameters' );
97 $this->showParsedOutput = $this->
hasOption(
'show-parsed-output' );
99 $this->showDiff = $this->
hasOption(
'show-diff' );
100 if ( $this->showDiff ) {
101 $bin = $this->
getOption(
'diff-bin', getenv(
'DIFF' ) );
115 $this->
error(
"{$this->failed} failed revisions out of {$this->count}" );
116 if ( $this->count > 0 ) {
117 $this->
output(
" (" . ( $this->failed / $this->count ) .
"%)\n" );
121 private function stripParameters( $text ) {
122 if ( !$this->stripParametersEnabled ) {
126 return preg_replace(
'/(<a) [^>]+>/',
'$1>', $text );
136 $parser1Name = $this->
getOption(
'parser1' );
137 $parser2Name = $this->
getOption(
'parser2' );
139 self::checkParserLocally( $parser1Name );
140 self::checkParserLocally( $parser2Name );
142 $parser1 =
new $parser1Name();
143 $parser2 =
new $parser2Name();
148 $this->
error(
"Page {$title->getPrefixedText()} does not contain wikitext "
149 .
"but {$content->getModel()}\n" );
155 '@phan-var WikitextContent $content';
156 $text = strval(
$content->getText() );
158 $output1 = $parser1->parse( $text, $title, $this->options );
159 $output2 = $parser2->parse( $text, $title, $this->options );
161 if ( $output1->getText() != $output2->getText() ) {
163 $this->
error(
"Parsing for {$title->getPrefixedText()} differs\n" );
165 if ( $this->saveFailed ) {
167 $this->saveFailed .
'/' . rawurlencode( $title->getPrefixedText() ) .
".txt",
171 if ( $this->showDiff ) {
173 explode(
"\n", $this->stripParameters( $output1->getText() ) ),
174 explode(
"\n", $this->stripParameters( $output2->getText() ) )
177 $unifiedDiff = $formatter->format( $diffs );
179 $this->
output( $unifiedDiff );
182 $this->
output( $title->getPrefixedText() .
"\tOK\n" );
184 if ( $this->showParsedOutput ) {
185 $this->
output( $this->stripParameters( $output1->getText() ) );
190 private static function checkParserLocally( $parserName ) {
192 if ( !class_exists( $parserName ) && file_exists(
"$parserName.php" ) ) {
200 require_once RUN_MAINTENANCE_IF_MAIN;
const CONTENT_MODEL_WIKITEXT
Maintenance script to take page text out of an XML dump file and render basic HTML out to files.
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.
Base class for iterating 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.
static newFromUser( $user)
Get a ParserOptions object from a given user.
Represents a revision, log entry or upload during the import process.
getContent( $role=SlotRecord::MAIN)
$wgDiff
Config variable stub for the Diff setting, for use by phpdoc and IDEs.