38require_once __DIR__ .
'/dumpIterator.php';
52 private $saveFailed =
false;
54 private $stripParametersEnabled;
56 private $showParsedOutput;
65 parent::__construct();
66 $this->
addDescription(
'Run a file or dump with several parsers' );
67 $this->
addOption(
'parser1',
'The first parser to compare.',
true,
true );
68 $this->
addOption(
'parser2',
'The second parser to compare.',
true,
true );
71 'Folder in which articles which differ will be stored.',
75 $this->
addOption(
'show-diff',
'Show a diff of the two renderings.',
false,
false );
78 'Binary to use for diffing (can also be provided by DIFF env var).',
84 'Remove parameters of html tags to increase readability.',
90 'Show the parsed html if both Parsers give the same output.',
97 if ( $this->
hasOption(
'save-failed' ) ) {
98 $this->saveFailed = $this->
getOption(
'save-failed' );
101 $this->stripParametersEnabled = $this->
hasOption(
'strip-parameters' );
102 $this->showParsedOutput = $this->
hasOption(
'show-parsed-output' );
104 $this->showDiff = $this->
hasOption(
'show-diff' );
105 if ( $this->showDiff ) {
106 $bin = $this->
getOption(
'diff-bin', getenv(
'DIFF' ) );
114 $this->options = ParserOptions::newFromUser( $user );
120 $this->
error(
"{$this->failed} failed revisions out of {$this->count}" );
121 if ( $this->count > 0 ) {
122 $this->
output(
" (" . ( $this->failed / $this->count ) .
"%)\n" );
126 private function stripParameters( $text ) {
127 if ( !$this->stripParametersEnabled ) {
131 return preg_replace(
'/(<a) [^>]+>/',
'$1>', $text );
140 $parser1Name = $this->
getOption(
'parser1' );
141 $parser2Name = $this->
getOption(
'parser2' );
143 self::checkParserLocally( $parser1Name );
144 self::checkParserLocally( $parser2Name );
146 $parser1 =
new $parser1Name();
147 $parser2 =
new $parser2Name();
152 $this->
error(
"Page {$title->getPrefixedText()} does not contain wikitext "
153 .
"but {$content->getModel()}\n" );
159 '@phan-var WikitextContent $content';
160 $text = strval( $content->getText() );
162 $output1 = $parser1->parse( $text, $title, $this->options );
163 $output2 = $parser2->parse( $text, $title, $this->options );
165 if ( $output1->getText() != $output2->getText() ) {
167 $this->
error(
"Parsing for {$title->getPrefixedText()} differs\n" );
169 if ( $this->saveFailed ) {
171 $this->saveFailed .
'/' . rawurlencode( $title->getPrefixedText() ) .
".txt",
175 if ( $this->showDiff ) {
177 explode(
"\n", $this->stripParameters( $output1->getText() ) ),
178 explode(
"\n", $this->stripParameters( $output2->getText() ) )
181 $unifiedDiff = $formatter->format( $diffs );
183 $this->
output( $unifiedDiff );
186 $this->
output( $title->getPrefixedText() .
"\tOK\n" );
188 if ( $this->showParsedOutput ) {
189 $this->
output( $this->stripParameters( $output1->getText() ) );
194 private static function checkParserLocally( $parserName ) {
196 if ( !class_exists( $parserName ) && file_exists(
"$parserName.php" ) ) {
205require_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.
Content object for wiki text pages.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
addDescription( $text)
Set the description text.
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.