MediaWiki  master
makeTestEdits.php
Go to the documentation of this file.
1 <?php
23 require_once __DIR__ . '/Maintenance.php';
24 
27 
33 class MakeTestEdits extends Maintenance {
34  public function __construct() {
35  parent::__construct();
36  $this->addDescription( 'Make test edits for a user' );
37  $this->addOption( 'user', 'User name', true, true );
38  $this->addOption( 'count', 'Number of edits', true, true );
39  $this->addOption( 'namespace', 'Namespace number', false, true );
40  $this->setBatchSize( 100 );
41  }
42 
43  public function execute() {
44  $user = User::newFromName( $this->getOption( 'user' ) );
45  if ( !$user->isRegistered() ) {
46  $this->fatalError( "No such user exists." );
47  }
48 
49  $count = $this->getOption( 'count' );
50  $namespace = (int)$this->getOption( 'namespace', 0 );
51  $services = $this->getServiceContainer();
52  $wikiPageFactory = $services->getWikiPageFactory();
53 
54  for ( $i = 0; $i < $count; ++$i ) {
55  $title = Title::makeTitleSafe( $namespace, "Page " . wfRandomString( 2 ) );
56  $page = $wikiPageFactory->newFromTitle( $title );
58  $summary = "Change " . wfRandomString( 6 );
59 
60  $page->doUserEditContent( $content, $user, $summary );
61 
62  $this->output( "Edited $title\n" );
63  if ( $i && ( $i % $this->getBatchSize() ) == 0 ) {
64  $this->waitForReplication();
65  }
66  }
67 
68  $this->output( "Done\n" );
69  }
70 }
71 
72 $maintClass = MakeTestEdits::class;
73 require_once RUN_MAINTENANCE_IF_MAIN;
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:66
output( $out, $channel=null)
Throw some output to the user.
waitForReplication()
Wait for replica DBs to catch up.
getServiceContainer()
Returns the main service container.
getBatchSize()
Returns batch size.
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.
setBatchSize( $s=0)
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Make test edits for a user to populate a test wiki.
execute()
Do the actual work.
__construct()
Default constructor.
Represents a title within MediaWiki.
Definition: Title.php:76
internal since 1.36
Definition: User.php:98
$maintClass
$content
Definition: router.php:76