MediaWiki  master
preprocessDump.php
Go to the documentation of this file.
1 <?php
29 
30 require_once __DIR__ . '/dumpIterator.php';
31 
39 
40  /* Variables for dressing up as a parser */
41  public $mTitle = 'PreprocessDump';
42  public $mPPNodeCount = 0;
45 
46  public function getStripList() {
47  $parser = MediaWikiServices::getInstance()->getParser();
48 
49  return $parser->getStripList();
50  }
51 
52  public function __construct() {
53  parent::__construct();
54  $this->addOption( 'cache', 'Use and populate the preprocessor cache.', false, false );
55  $this->addOption( 'preprocessor', 'This option is ignored', false, false );
56  }
57 
58  public function getDbType() {
59  return Maintenance::DB_NONE;
60  }
61 
62  public function checkOptions() {
64 
65  if ( !$this->hasOption( 'cache' ) ) {
66  $wgPreprocessorCacheThreshold = false;
67  }
68 
69  $parser = MediaWikiServices::getInstance()->getParser();
70  $parser->firstCallInit();
71  $this->mPreprocessor = new Preprocessor_Hash( $parser );
72  }
73 
78  public function processRevision( WikiRevision $rev ) {
79  $content = $rev->getContent();
80 
81  if ( $content->getModel() !== CONTENT_MODEL_WIKITEXT ) {
82  return;
83  }
85  '@phan-var WikitextContent $content';
86 
87  try {
88  $this->mPreprocessor->preprocessToObj( strval( $content->getText() ), 0 );
89  } catch ( Exception $e ) {
90  $this->error( "Caught exception " . $e->getMessage() . " in "
91  . $rev->getTitle()->getPrefixedText() );
92  }
93  }
94 }
95 
96 $maintClass = PreprocessDump::class;
97 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:38
PreprocessDump
Maintenance script that takes page text out of an XML dump file and preprocesses it to obj.
Definition: preprocessDump.php:38
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:154
PreprocessDump\$mPPNodeCount
$mPPNodeCount
Definition: preprocessDump.php:42
WikiRevision\getTitle
getTitle()
Definition: WikiRevision.php:428
Preprocessor_Hash
Differences from DOM schema:
Definition: Preprocessor_Hash.php:43
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
Definition: Defines.php:224
PreprocessDump\__construct
__construct()
Default constructor.
Definition: preprocessDump.php:52
PreprocessDump\getStripList
getStripList()
Definition: preprocessDump.php:46
Preprocessor
Definition: Preprocessor.php:30
$wgPreprocessorCacheThreshold
$wgPreprocessorCacheThreshold
Preprocessor caching threshold Setting it to 'false' will disable the preprocessor cache.
Definition: DefaultSettings.php:4726
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:245
PreprocessDump\checkOptions
checkOptions()
Stub function for processing additional options.
Definition: preprocessDump.php:62
WikiRevision\getContent
getContent( $role=SlotRecord::MAIN)
Definition: WikiRevision.php:493
PreprocessDump\getDbType
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition: preprocessDump.php:58
$maintClass
$maintClass
Definition: preprocessDump.php:96
PreprocessDump\$mTitle
$mTitle
Definition: preprocessDump.php:41
$content
$content
Definition: router.php:76
Maintenance\DB_NONE
const DB_NONE
Constants for DB access type.
Definition: Maintenance.php:60
DumpIterator
Base class for interating over a dump.
Definition: dumpIterator.php:36
WikiRevision
Represents a revision, log entry or upload during the import process.
Definition: WikiRevision.php:39
PreprocessDump\processRevision
processRevision(WikiRevision $rev)
Callback function for each revision, preprocessToObj()
Definition: preprocessDump.php:78
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:463
PreprocessDump\$mPreprocessor
Preprocessor $mPreprocessor
Definition: preprocessDump.php:44
Maintenance\hasOption
hasOption( $name)
Checks to see if a particular option exists.
Definition: Maintenance.php:266