MediaWiki  master
makeTestEdits.php
Go to the documentation of this file.
1 <?php
23 require_once __DIR__ . '/Maintenance.php';
24 
26 
32 class MakeTestEdits extends Maintenance {
33  public function __construct() {
34  parent::__construct();
35  $this->addDescription( 'Make test edits for a user' );
36  $this->addOption( 'user', 'User name', true, true );
37  $this->addOption( 'count', 'Number of edits', true, true );
38  $this->addOption( 'namespace', 'Namespace number', false, true );
39  $this->setBatchSize( 100 );
40  }
41 
42  public function execute() {
43  $user = User::newFromName( $this->getOption( 'user' ) );
44  if ( !$user->getId() ) {
45  $this->fatalError( "No such user exists." );
46  }
47 
48  $count = $this->getOption( 'count' );
49  $namespace = (int)$this->getOption( 'namespace', 0 );
50  $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
51 
52  for ( $i = 0; $i < $count; ++$i ) {
53  $title = Title::makeTitleSafe( $namespace, "Page " . wfRandomString( 2 ) );
54  $page = WikiPage::factory( $title );
56  $summary = "Change " . wfRandomString( 6 );
57 
58  $page->doEditContent( $content, $summary, 0, false, $user );
59 
60  $this->output( "Edited $title\n" );
61  if ( $i && ( $i % $this->getBatchSize() ) == 0 ) {
62  $lbFactory->waitForReplication();
63  }
64  }
65 
66  $this->output( "Done\n" );
67  }
68 }
69 
70 $maintClass = MakeTestEdits::class;
71 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:38
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:146
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:480
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:323
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:535
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:53
MakeTestEdits\__construct
__construct()
Default constructor.
Definition: makeTestEdits.php:33
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:146
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: Maintenance.php:241
$title
$title
Definition: testCompression.php:38
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:140
$maintClass
$maintClass
Definition: makeTestEdits.php:70
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:621
$content
$content
Definition: router.php:76
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:277
Maintenance\getBatchSize
getBatchSize()
Returns batch size.
Definition: Maintenance.php:362
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:429
MakeTestEdits
Make test edits for a user to populate a test wiki.
Definition: makeTestEdits.php:32
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:370
MakeTestEdits\execute
execute()
Do the actual work.
Definition: makeTestEdits.php:42
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition: GlobalFunctions.php:274