Go to the documentation of this file.
29 require_once __DIR__ .
'/Maintenance.php';
43 parent::__construct();
45 $this->
addOption(
'file',
'File with text to run.',
false,
true );
46 $this->
addOption(
'dump',
'XML dump to execute all revisions.',
false,
true );
47 $this->
addOption(
'from',
'Article from XML dump to start from.',
false,
true );
52 $this->
fatalError(
"You must provide a file or dump" );
60 $revision->setText( file_get_contents( $this->
getOption(
'file' ) ) );
62 rawurldecode( basename( $this->
getOption(
'file' ),
'.txt' ) )
70 $this->startTime = microtime(
true );
72 if ( $this->
getOption(
'dump' ) ==
'-' ) {
75 $this->
fatalError(
"Sorry, I don't support dump filenames yet. "
76 .
"Use - and provide it on stdin on the meantime." );
80 $importer->setRevisionCallback(
81 [ $this,
'handleRevision' ] );
82 $importer->setNoticeCallback(
function ( $msg, $params ) {
83 echo
wfMessage( $msg, $params )->text() .
"\n";
86 $this->from = $this->
getOption(
'from',
null );
88 $importer->doImport();
93 $this->
error(
"Done {$this->count} revisions in " . round( $delta, 2 ) .
" seconds " );
95 $this->
error( round( $this->count / $delta, 2 ) .
" pages/sec" );
98 # Perform the memory_get_peak_usage() when all the other data has been
99 # output so there's no damage if it dies. It is only available since
100 # 5.2.0 (since 5.2.1 if you haven't compiled with --enable-memory-limit)
101 $this->
error(
"Memory peak usage of " . memory_get_peak_usage() .
" bytes\n" );
105 parent::finalSetup();
111 $wgHooks[
'InterwikiLoadPrefix'][] =
'DumpIterator::disableInterwikis';
116 # Title::newFromText will check on each namespaced article if it's an interwiki.
117 # We always answer that it is not.
128 $title = $rev->getTitle();
130 $this->
error(
"Got bogus revision with null title!" );
136 if ( $this->from !==
false ) {
137 if ( $this->from !=
$title ) {
140 $this->
output(
"Skipped " . ( $this->count - 1 ) .
" pages\n" );
169 parent::__construct();
170 $this->
addDescription(
'Runs a regex in the revisions from a dump' );
171 $this->
addOption(
'regex',
'Searching regex',
true,
true );
182 if ( preg_match( $this->
getOption(
'regex' ), $rev->getContent()->getTextForSearchIndex() ) ) {
183 $this->
output( $rev->getTitle() .
" matches at edit from " . $rev->getTimestamp() .
"\n" );
const RUN_MAINTENANCE_IF_MAIN
XML file reader for the page data importer.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
__construct()
Default constructor.
getStdin( $len=null)
Return input from stdin.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
handleRevision( $rev)
Callback function for each revision, child classes should override processRevision instead.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addDescription( $text)
Set the description text.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Imports a XML dump from a file (either from file upload, files on disk, or HTTP)
execute()
Do the actual work.
Maintenance script that runs a regex in the revisions from a dump.
__construct()
Default constructor.
$wgUseDatabaseMessages
Translation using MediaWiki: namespace.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
$wgLocalisationCacheConf
Localisation cache configuration.
static disableInterwikis( $prefix, &$data)
const DB_NONE
Constants for DB access type.
Base class for interating over a dump.
getOption( $name, $default=null)
Get an option, or return the default.
Represents a revision, log entry or upload during the import process.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
finalSetup()
Handle some last-minute setup here.
hasOption( $name)
Checks to see if a particular option exists.