MediaWiki  master
preprocessDump.php
Go to the documentation of this file.
1 <?php
30 
31 require_once __DIR__ . '/dumpIterator.php';
32 
40 
41  /* Variables for dressing up as a parser */
42  public $mTitle = 'PreprocessDump';
43  public $mPPNodeCount = 0;
46 
47  public function getStripList() {
48  $parser = MediaWikiServices::getInstance()->getParser();
49 
50  return $parser->getStripList();
51  }
52 
53  public function __construct() {
54  parent::__construct();
55  $this->addOption( 'cache', 'Use and populate the preprocessor cache.', false, false );
56  $this->addOption( 'preprocessor', 'Preprocessor to use.', false, false );
57  }
58 
59  public function getDbType() {
60  return Maintenance::DB_NONE;
61  }
62 
63  public function checkOptions() {
65 
66  if ( !$this->hasOption( 'cache' ) ) {
67  $wgPreprocessorCacheThreshold = false;
68  }
69 
70  if ( $this->hasOption( 'preprocessor' ) ) {
71  $name = $this->getOption( 'preprocessor' );
72  } elseif ( isset( $wgParserConf['preprocessorClass'] ) ) {
73  $name = $wgParserConf['preprocessorClass'];
74  } else {
75  $name = Preprocessor_DOM::class;
76  }
77 
78  $parser = MediaWikiServices::getInstance()->getParser();
79  $parser->firstCallInit();
80  $this->mPreprocessor = new $name( $parser );
81  }
82 
87  public function processRevision( $rev ) {
88  $content = $rev->getContent( RevisionRecord::RAW );
89 
90  if ( $content->getModel() !== CONTENT_MODEL_WIKITEXT ) {
91  return;
92  }
94  '@phan-var WikitextContent $content';
95 
96  try {
97  $this->mPreprocessor->preprocessToObj( strval( $content->getText() ), 0 );
98  } catch ( Exception $e ) {
99  $this->error( "Caught exception " . $e->getMessage() . " in "
100  . $rev->getTitle()->getPrefixedText() );
101  }
102  }
103 }
104 
105 $maintClass = PreprocessDump::class;
106 require_once RUN_MAINTENANCE_IF_MAIN;
const DB_NONE
Constants for DB access type.
Definition: Maintenance.php:91
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:215
Preprocessor $mPreprocessor
error( $err, $die=0)
Throw an error to the user.
getOption( $name, $default=null)
Get an option, or return the default.
hasOption( $name)
Checks to see if a particular option exists.
$maintClass
$wgPreprocessorCacheThreshold
Preprocessor caching threshold Setting it to &#39;false&#39; will disable the preprocessor cache...
Maintenance script that takes page text out of an XML dump file and preprocesses it to obj...
$wgParserConf
Parser configuration.
Base class for interating over a dump.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
$content
Definition: router.php:78
processRevision( $rev)
Callback function for each revision, preprocessToObj()