38require_once __DIR__ .
'/Maintenance.php';
55 parent::__construct();
56 $this->addDescription(
'Does something with a dump' );
57 $this->addOption(
'file',
'File with text to run.',
false,
true );
58 $this->addOption(
'dump',
'XML dump to execute all revisions.',
false,
true );
59 $this->addOption(
'from',
'Article from XML dump to start from.',
false,
true );
63 if ( !( $this->hasOption(
'file' ) xor $this->hasOption(
'dump' ) ) ) {
64 $this->fatalError(
"You must provide a file or dump" );
69 if ( $this->hasOption(
'file' ) ) {
70 $file = $this->getOption(
'file' );
72 $text = file_get_contents( $file );
73 $title = Title::newFromText( rawurldecode( basename( $file,
'.txt' ) ) );
74 $revision->setTitle( $title );
75 $content = ContentHandler::makeContent( $text, $title );
76 $revision->setContent( SlotRecord::MAIN, $content );
84 $this->startTime = microtime(
true );
86 if ( $this->getOption(
'dump' ) ==
'-' ) {
89 $this->fatalError(
"Sorry, I don't support dump filenames yet. "
90 .
"Use - and provide it on stdin on the meantime." );
93 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
95 $importer = $this->getServiceContainer()
96 ->getWikiImporterFactory()
99 $importer->setRevisionCallback(
100 [ $this,
'handleRevision' ] );
101 $importer->setNoticeCallback(
static function ( $msg,
$params ) {
105 $this->from = $this->getOption(
'from',
null );
107 $importer->doImport();
111 $delta = microtime(
true ) - $this->startTime;
112 $this->error(
"Done {$this->count} revisions in " . round( $delta, 2 ) .
" seconds " );
114 $this->error( round( $this->count / $delta, 2 ) .
" pages/sec" );
117 # Perform the memory_get_peak_usage() when all the other data has been
118 # output so there's no damage if it dies. It is only available since
119 # 5.2.0 (since 5.2.1 if you haven't compiled with --enable-memory-limit)
120 $this->error(
"Memory peak usage of " . memory_get_peak_usage() .
" bytes\n" );
124 parent::finalSetup( $settingsBuilder );
126 if ( $this->getDbType() == Maintenance::DB_NONE ) {
131 $wgHooks[
'InterwikiLoadPrefix'][] =
'DumpIterator::disableInterwikis';
134 MainConfigNames::UseDatabaseMessages =>
false,
135 MainConfigNames::LocalisationCacheConf => [
'storeClass' => LCStoreNull::class ],
141 # Title::newFromText will check on each namespaced article if it's an interwiki.
142 # We always answer that it is not.
153 $title = $rev->getTitle();
155 $this->error(
"Got bogus revision with null title!" );
161 if ( $this->from !==
false ) {
162 if ( $this->from != $title ) {
165 $this->output(
"Skipped " . ( $this->count - 1 ) .
" pages\n" );
202 parent::__construct();
203 $this->addDescription(
'Runs a regex in the revisions from a dump' );
204 $this->addOption(
'regex',
'Searching regex',
true,
true );
208 return Maintenance::DB_NONE;
215 if ( preg_match( $this->getOption(
'regex' ), $rev->
getContent()->getTextForSearchIndex() ) ) {
223require_once RUN_MAINTENANCE_IF_MAIN;
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
array $params
The job parameters.
Base class for iterating over a dump.
static disableInterwikis( $prefix, &$data)
processRevision(WikiRevision $rev)
Core function which does whatever the maintenance script is designed to do.
conclusions()
Stub function for giving data about what was computed.
checkOptions()
Stub function for processing additional options.
handleRevision( $rev)
Callback function for each revision, child classes should override processRevision instead.
finalSetup(SettingsBuilder $settingsBuilder)
Imports a XML dump from a file (either from file upload, files on disk, or HTTP)
A content handler knows how do deal with a specific type of content on a wiki page.
A class containing constants representing the names of configuration variables.
Maintenance script that runs a regex in the revisions from a dump.
processRevision(WikiRevision $rev)
Represents a revision, log entry or upload during the import process.
getContent( $role=SlotRecord::MAIN)
$wgHooks
Config variable stub for the Hooks setting, for use by phpdoc and IDEs.