25require_once __DIR__ .
'/Maintenance.php';
42 parent::__construct();
44 $this->
addOption(
'file',
'File with text to run.',
false,
true );
45 $this->
addOption(
'dump',
'XML dump to execute all revisions.',
false,
true );
46 $this->
addOption(
'from',
'Article from XML dump to start from.',
false,
true );
51 $this->
fatalError(
"You must provide a file or dump" );
58 $revision =
new WikiRevision();
59 $text = file_get_contents( $file );
60 $title = Title::newFromText( rawurldecode( basename( $file,
'.txt' ) ) );
61 $revision->setTitle( $title );
62 $content = ContentHandler::makeContent( $text, $title );
63 $revision->setContent( SlotRecord::MAIN, $content );
71 $this->startTime = microtime(
true );
73 if ( $this->
getOption(
'dump' ) ==
'-' ) {
76 $this->
fatalError(
"Sorry, I don't support dump filenames yet. "
77 .
"Use - and provide it on stdin on the meantime." );
80 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
83 ->getWikiImporterFactory()
86 $importer->setRevisionCallback(
88 $importer->setNoticeCallback(
static function ( $msg, $params ) {
89 echo
wfMessage( $msg, $params )->text() .
"\n";
92 $this->from = $this->
getOption(
'from',
null );
94 $importer->doImport();
98 $delta = microtime(
true ) - $this->startTime;
99 $this->
error(
"Done {$this->count} revisions in " . round( $delta, 2 ) .
" seconds " );
101 $this->
error( round( $this->count / $delta, 2 ) .
" pages/sec" );
104 # Perform the memory_get_peak_usage() when all the other data has been
105 # output so there's no damage if it dies. It is only available since
106 # 5.2.0 (since 5.2.1 if you haven't compiled with --enable-memory-limit)
107 $this->
error(
"Memory peak usage of " . memory_get_peak_usage() .
" bytes\n" );
111 parent::finalSetup( $settingsBuilder );
113 if ( $this->
getDbType() == Maintenance::DB_NONE ) {
118 $wgHooks[
'InterwikiLoadPrefix'][] =
'DumpIterator::disableInterwikis';
121 MainConfigNames::UseDatabaseMessages =>
false,
122 MainConfigNames::LocalisationCacheConf => [
'storeClass' => LCStoreNull::class ],
128 #
Title::newFromText will check on each namespaced article
if it
's an interwiki.
129 # We always answer that it is not.
139 public function handleRevision( $rev ) {
140 $title = $rev->getTitle();
142 $this->error( "Got bogus revision with null title!" );
148 if ( $this->from !== false ) {
149 if ( $this->from != $title ) {
152 $this->output( "Skipped " . ( $this->count - 1 ) . " pages\n" );
158 $this->processRevision( $rev );
164 public function checkOptions() {
170 public function conclusions() {
176 abstract public function processRevision( WikiRevision $rev );
184class SearchDump extends DumpIterator {
186 public function __construct() {
187 parent::__construct();
188 $this->addDescription( 'Runs a regex in the revisions from a dump
' );
189 $this->addOption( 'regex
', 'Searching regex
', true, true );
193 public function getDbType() {
194 return Maintenance::DB_NONE;
197 public function processRevision( WikiRevision $rev ) {
198 if ( preg_match( $this->getOption( 'regex
' ), $rev->getContent()->getTextForSearchIndex() ) ) {
199 $this->output( $rev->getTitle() . " matches at edit from " . $rev->getTimestamp() . "\n" );
204// @codeCoverageIgnoreStart
205$maintClass = SearchDump::class;
206require_once RUN_MAINTENANCE_IF_MAIN;
207// @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.
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.
$wgHooks
Config variable stub for the Hooks setting, for use by phpdoc and IDEs.