39require_once __DIR__ .
'/Maintenance.php';
56 parent::__construct();
58 $this->
addOption(
'file',
'File with text to run.',
false,
true );
59 $this->
addOption(
'dump',
'XML dump to execute all revisions.',
false,
true );
60 $this->
addOption(
'from',
'Article from XML dump to start from.',
false,
true );
65 $this->
fatalError(
"You must provide a file or dump" );
73 $text = file_get_contents( $file );
74 $title = Title::newFromText( rawurldecode( basename( $file,
'.txt' ) ) );
75 $revision->setTitle( $title );
76 $content = ContentHandler::makeContent( $text, $title );
77 $revision->setContent( SlotRecord::MAIN, $content );
85 $this->startTime = microtime(
true );
87 if ( $this->
getOption(
'dump' ) ==
'-' ) {
90 $this->
fatalError(
"Sorry, I don't support dump filenames yet. "
91 .
"Use - and provide it on stdin on the meantime." );
94 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
97 ->getWikiImporterFactory()
100 $importer->setRevisionCallback(
101 [ $this,
'handleRevision' ] );
102 $importer->setNoticeCallback(
static function ( $msg, $params ) {
103 echo
wfMessage( $msg, $params )->text() .
"\n";
106 $this->from = $this->
getOption(
'from',
null );
108 $importer->doImport();
112 $delta = microtime(
true ) - $this->startTime;
113 $this->
error(
"Done {$this->count} revisions in " . round( $delta, 2 ) .
" seconds " );
115 $this->
error( round( $this->count / $delta, 2 ) .
" pages/sec" );
118 # Perform the memory_get_peak_usage() when all the other data has been
119 # output so there's no damage if it dies. It is only available since
120 # 5.2.0 (since 5.2.1 if you haven't compiled with --enable-memory-limit)
121 $this->
error(
"Memory peak usage of " . memory_get_peak_usage() .
" bytes\n" );
125 parent::finalSetup( $settingsBuilder );
127 if ( $this->
getDbType() == Maintenance::DB_NONE ) {
132 $wgHooks[
'InterwikiLoadPrefix'][] =
'DumpIterator::disableInterwikis';
135 MainConfigNames::UseDatabaseMessages =>
false,
136 MainConfigNames::LocalisationCacheConf => [
'storeClass' => LCStoreNull::class ],
142 #
Title::newFromText will check on each namespaced article
if it
's an interwiki.
143 # We always answer that it is not.
153 public function handleRevision( $rev ) {
154 $title = $rev->getTitle();
156 $this->error( "Got bogus revision with null title!" );
162 if ( $this->from !== false ) {
163 if ( $this->from != $title ) {
166 $this->output( "Skipped " . ( $this->count - 1 ) . " pages\n" );
172 $this->processRevision( $rev );
178 public function checkOptions() {
184 public function conclusions() {
190 abstract public function processRevision( WikiRevision $rev );
198class SearchDump extends DumpIterator {
200 public function __construct() {
201 parent::__construct();
202 $this->addDescription( 'Runs a regex in the revisions from a dump
' );
203 $this->addOption( 'regex
', 'Searching regex
', true, true );
207 public function getDbType() {
208 return Maintenance::DB_NONE;
211 public function processRevision( WikiRevision $rev ) {
212 if ( preg_match( $this->getOption( 'regex
' ), $rev->getContent()->getTextForSearchIndex() ) ) {
213 $this->output( $rev->getTitle() . " matches at edit from " . $rev->getTimestamp() . "\n" );
218// @codeCoverageIgnoreStart
219$maintClass = SearchDump::class;
220require_once RUN_MAINTENANCE_IF_MAIN;
221// @codeCoverageIgnoreEnd
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined('MW_SETUP_CALLBACK'))
Base class for iterating over a dump.
__construct()
Default constructor.
execute()
Do the actual work.
conclusions()
Stub function for giving data about what was computed.
static disableInterwikis(string $prefix, array &$data)
checkOptions()
Stub function for processing additional options.
handleRevision( $rev)
Callback function for each revision, child classes should override processRevision instead.
finalSetup(SettingsBuilder $settingsBuilder)
Handle some last-minute setup here.
Imports a XML dump from a file (either from file upload, files on disk, or HTTP)
Base class for content handling.
A class containing constants representing the names of configuration variables.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
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.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
getStdin( $len=null)
Return input from stdin.
addDescription( $text)
Set the description text.
Represents a revision, log entry or upload during the import process.
$wgHooks
Config variable stub for the Hooks setting, for use by phpdoc and IDEs.