35require_once __DIR__ .
'/Maintenance.php';
51 parent::__construct();
53 $this->
addOption(
'file',
'File with text to run.',
false,
true );
54 $this->
addOption(
'dump',
'XML dump to execute all revisions.',
false,
true );
55 $this->
addOption(
'from',
'Article from XML dump to start from.',
false,
true );
60 $this->
fatalError(
"You must provide a file or dump" );
68 $text = file_get_contents(
$file );
69 $title = Title::newFromText( rawurldecode( basename(
$file,
'.txt' ) ) );
70 $revision->setTitle(
$title );
72 $revision->setContent( SlotRecord::MAIN,
$content );
80 $this->startTime = microtime(
true );
82 if ( $this->
getOption(
'dump' ) ==
'-' ) {
85 $this->
fatalError(
"Sorry, I don't support dump filenames yet. "
86 .
"Use - and provide it on stdin on the meantime." );
89 $importer = MediaWikiServices::getInstance()
90 ->getWikiImporterFactory()
93 $importer->setRevisionCallback(
94 [ $this,
'handleRevision' ] );
95 $importer->setNoticeCallback(
static function ( $msg, $params ) {
96 echo
wfMessage( $msg, $params )->text() .
"\n";
99 $this->from = $this->
getOption(
'from',
null );
101 $importer->doImport();
105 $delta = microtime(
true ) - $this->startTime;
106 $this->
error(
"Done {$this->count} revisions in " . round( $delta, 2 ) .
" seconds " );
108 $this->
error( round( $this->count / $delta, 2 ) .
" pages/sec" );
111 # Perform the memory_get_peak_usage() when all the other data has been
112 # output so there's no damage if it dies. It is only available since
113 # 5.2.0 (since 5.2.1 if you haven't compiled with --enable-memory-limit)
114 $this->
error(
"Memory peak usage of " . memory_get_peak_usage() .
" bytes\n" );
118 parent::finalSetup( $settingsBuilder );
124 $wgHooks[
'InterwikiLoadPrefix'][] =
'DumpIterator::disableInterwikis';
126 $settingsBuilder->putConfigValues( [
127 MainConfigNames::UseDatabaseMessages =>
false,
128 MainConfigNames::LocalisationCacheConf => [
'storeClass' => LCStoreNull::class ],
134 # Title::newFromText will check on each namespaced article if it's an interwiki.
135 # We always answer that it is not.
146 $title = $rev->getTitle();
148 $this->
error(
"Got bogus revision with null title!" );
154 if ( $this->from !==
false ) {
155 if ( $this->from !=
$title ) {
158 $this->
output(
"Skipped " . ( $this->count - 1 ) .
" pages\n" );
195 parent::__construct();
196 $this->
addDescription(
'Runs a regex in the revisions from a dump' );
197 $this->
addOption(
'regex',
'Searching regex',
true,
true );
208 if ( preg_match( $this->
getOption(
'regex' ), $rev->
getContent()->getTextForSearchIndex() ) ) {
215require_once RUN_MAINTENANCE_IF_MAIN;
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Base class for iterating over a dump.
static disableInterwikis( $prefix, &$data)
__construct()
Default constructor.
execute()
Do the actual work.
finalSetup(SettingsBuilder $settingsBuilder=null)
Handle some last-minute setup here.
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.
Imports a XML dump from a file (either from file upload, files on disk, or HTTP)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
const DB_NONE
Constants for DB access type.
output( $out, $channel=null)
Throw some output to the user.
getStdin( $len=null)
Return input from stdin.
hasOption( $name)
Checks to see if a particular option was set.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
A class containing constants representing the names of configuration variables.
Maintenance script that runs a regex in the revisions from a dump.
__construct()
Default constructor.
processRevision(WikiRevision $rev)
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.