26use Wikimedia\Timestamp\ConvertibleTimestamp;
29require_once __DIR__ .
'/Maintenance.php';
46 parent::__construct();
48 $this->
addOption(
'file',
'File with text to run.',
false,
true );
49 $this->
addOption(
'dump',
'XML dump to execute all revisions.',
false,
true );
50 $this->
addOption(
'from',
'Article from XML dump to start from.',
false,
true );
55 $this->
fatalError(
"You must provide a file or dump" );
63 $text = file_get_contents( $file );
64 $title = Title::newFromText( rawurldecode( basename( $file,
'.txt' ) ) );
65 $revision->setTitle( $title );
66 $content = ContentHandler::makeContent( $text, $title );
67 $revision->setContent( SlotRecord::MAIN, $content );
75 $this->startTime = ConvertibleTimestamp::hrtime();
77 if ( $this->
getOption(
'dump' ) ==
'-' ) {
80 $this->
fatalError(
"Sorry, I don't support dump filenames yet. "
81 .
"Use - and provide it on stdin on the meantime." );
84 $user = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
87 ->getWikiImporterFactory()
90 $importer->setRevisionCallback(
92 $importer->setNoticeCallback(
static function ( $msg, $params ) {
93 echo
wfMessage( $msg, $params )->text() .
"\n";
96 $this->from = $this->
getOption(
'from',
null );
98 $importer->doImport();
102 $delta = ( ConvertibleTimestamp::hrtime() - $this->startTime ) / 1e9;
103 $this->
error(
"Done {$this->count} revisions in " . round( $delta, 2 ) .
" seconds " );
105 $this->
error( round( $this->count / $delta, 2 ) .
" pages/sec" );
108 # Perform the memory_get_peak_usage() when all the other data has been
109 # output so there's no damage if it dies. It is only available since
110 # 5.2.0 (since 5.2.1 if you haven't compiled with --enable-memory-limit)
111 $this->
error(
"Memory peak usage of " . memory_get_peak_usage() .
" bytes\n" );
115 parent::finalSetup( $settingsBuilder );
117 if ( $this->
getDbType() == Maintenance::DB_NONE ) {
122 $wgHooks[
'InterwikiLoadPrefix'][] =
'DumpIterator::disableInterwikis';
125 MainConfigNames::UseDatabaseMessages =>
false,
126 MainConfigNames::LocalisationCacheConf => [
'storeClass' => LCStoreNull::class ],
132 #
Title::newFromText will check on each namespaced article
if it
's an interwiki.
133 # We always answer that it is not.
143 public function handleRevision( $rev ) {
144 $title = $rev->getTitle();
146 $this->error( "Got bogus revision with null title!" );
152 if ( $this->from !== false ) {
153 if ( $this->from != $title ) {
156 $this->output( "Skipped " . ( $this->count - 1 ) . " pages\n" );
162 $this->processRevision( $rev );
168 public function checkOptions() {
174 public function conclusions() {
180 abstract public function processRevision( WikiRevision $rev );
188class SearchDump extends DumpIterator {
190 public function __construct() {
191 parent::__construct();
192 $this->addDescription( 'Runs a regex in the revisions from a dump
' );
193 $this->addOption( 'regex
', 'Searching regex
', true, true );
197 public function getDbType() {
198 return Maintenance::DB_NONE;
201 public function processRevision( WikiRevision $rev ) {
202 if ( preg_match( $this->getOption( 'regex
' ), $rev->getContent()->getTextForSearchIndex() ) ) {
203 $this->output( $rev->getTitle() . " matches at edit from " . $rev->getTimestamp() . "\n" );
208// @codeCoverageIgnoreStart
209$maintClass = SearchDump::class;
210require_once RUN_MAINTENANCE_IF_MAIN;
211// @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...
error( $err)
Throw an error to the user.
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.
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.