MediaWiki  1.34.0
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;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
PreprocessDump
Maintenance script that takes page text out of an XML dump file and preprocesses it to obj.
Definition: preprocessDump.php:39
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
$wgParserConf
$wgParserConf
Parser configuration.
Definition: DefaultSettings.php:4135
PreprocessDump\$mPPNodeCount
$mPPNodeCount
Definition: preprocessDump.php:43
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:215
PreprocessDump\__construct
__construct()
Default constructor.
Definition: preprocessDump.php:53
PreprocessDump\getStripList
getStripList()
Definition: preprocessDump.php:47
Preprocessor
Definition: Preprocessor.php:30
$wgPreprocessorCacheThreshold
$wgPreprocessorCacheThreshold
Preprocessor caching threshold Setting it to 'false' will disable the preprocessor cache.
Definition: DefaultSettings.php:4329
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:267
PreprocessDump\checkOptions
checkOptions()
Definition: preprocessDump.php:63
PreprocessDump\getDbType
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition: preprocessDump.php:59
$maintClass
$maintClass
Definition: preprocessDump.php:105
PreprocessDump\$mTitle
$mTitle
Definition: preprocessDump.php:42
$content
$content
Definition: router.php:78
Maintenance\DB_NONE
const DB_NONE
Constants for DB access type.
Definition: Maintenance.php:87
DumpIterator
Base class for interating over a dump.
Definition: dumpIterator.php:36
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:302
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:481
PreprocessDump\processRevision
processRevision( $rev)
Callback function for each revision, preprocessToObj()
Definition: preprocessDump.php:87
PreprocessDump\$mPreprocessor
Preprocessor $mPreprocessor
Definition: preprocessDump.php:45
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option exists.
Definition: Maintenance.php:288