MediaWiki  1.34.0
makeTestEdits.php
Go to the documentation of this file.
1 <?php
23 require_once __DIR__ . '/Maintenance.php';
24 
30 class MakeTestEdits extends Maintenance {
31  public function __construct() {
32  parent::__construct();
33  $this->addDescription( 'Make test edits for a user' );
34  $this->addOption( 'user', 'User name', true, true );
35  $this->addOption( 'count', 'Number of edits', true, true );
36  $this->addOption( 'namespace', 'Namespace number', false, true );
37  $this->setBatchSize( 100 );
38  }
39 
40  public function execute() {
41  $user = User::newFromName( $this->getOption( 'user' ) );
42  if ( !$user->getId() ) {
43  $this->fatalError( "No such user exists." );
44  }
45 
46  $count = $this->getOption( 'count' );
47  $namespace = (int)$this->getOption( 'namespace', 0 );
48 
49  for ( $i = 0; $i < $count; ++$i ) {
50  $title = Title::makeTitleSafe( $namespace, "Page " . wfRandomString( 2 ) );
51  $page = WikiPage::factory( $title );
53  $summary = "Change " . wfRandomString( 6 );
54 
55  $page->doEditContent( $content, $summary, 0, false, $user );
56 
57  $this->output( "Edited $title\n" );
58  if ( $i && ( $i % $this->getBatchSize() ) == 0 ) {
60  }
61  }
62 
63  $this->output( "Done\n" );
64  }
65 }
66 
67 $maintClass = MakeTestEdits::class;
68 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:504
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:515
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
wfWaitForSlaves
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Definition: GlobalFunctions.php:2718
MakeTestEdits\__construct
__construct()
Default constructor.
Definition: makeTestEdits.php:31
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:142
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:267
$title
$title
Definition: testCompression.php:34
ContentHandler\makeContent
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Definition: ContentHandler.php:135
$maintClass
$maintClass
Definition: makeTestEdits.php:67
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:613
$content
$content
Definition: router.php:78
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:302
Maintenance\getBatchSize
getBatchSize()
Returns batch size.
Definition: Maintenance.php:386
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
MakeTestEdits
Make test edits for a user to populate a test wiki.
Definition: makeTestEdits.php:30
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:394
MakeTestEdits\execute
execute()
Do the actual work.
Definition: makeTestEdits.php:40
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition: GlobalFunctions.php:274