MediaWiki master
makeTestEdits.php
Go to the documentation of this file.
1<?php
23// @codeCoverageIgnoreStart
24require_once __DIR__ . '/Maintenance.php';
25// @codeCoverageIgnoreEnd
26
31
38 public function __construct() {
39 parent::__construct();
40 $this->addDescription( 'Make test edits for a user' );
41 $this->addOption( 'user', 'User name', true, true );
42 $this->addOption( 'count', 'Number of edits', true, true );
43 $this->addOption( 'namespace', 'Namespace number', false, true );
44 $this->setBatchSize( 100 );
45 }
46
47 public function execute() {
48 $user = User::newFromName( $this->getOption( 'user' ) );
49 if ( !$user->isRegistered() ) {
50 $this->fatalError( "No such user exists." );
51 }
52
53 $count = $this->getOption( 'count' );
54 $namespace = (int)$this->getOption( 'namespace', 0 );
55 $batchSize = $this->getBatchSize();
56 $services = $this->getServiceContainer();
57 $wikiPageFactory = $services->getWikiPageFactory();
58
60 $titleBatches = $this->newBatchIterator(
61 static function () use ( $namespace, $count ) {
62 for ( $i = 0; $i < $count; ++$i ) {
63 yield Title::makeTitleSafe( $namespace, "Page " . wfRandomString( 2 ) );
64 }
65 }
66 );
67
68 foreach ( $titleBatches as $titleBatch ) {
69 $this->beginTransactionRound( __METHOD__ );
70 foreach ( $titleBatch as $title ) {
71 $page = $wikiPageFactory->newFromTitle( $title );
72 $content = ContentHandler::makeContent( wfRandomString(), $title );
73 $summary = "Change " . wfRandomString( 6 );
74
75 $page->doUserEditContent( $content, $user, $summary );
76
77 $this->output( "Edited $title\n" );
78 }
79 $this->commitTransactionRound( __METHOD__ );
80 }
81
82 $this->output( "Done\n" );
83 }
84}
85
86// @codeCoverageIgnoreStart
87$maintClass = MakeTestEdits::class;
88require_once RUN_MAINTENANCE_IF_MAIN;
89// @codeCoverageIgnoreEnd
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Make test edits for a user to populate a test wiki.
execute()
Do the actual work.
__construct()
Default constructor.
A content handler knows how do deal with a specific type of content on a wiki page.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output 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.
getOption( $name, $default=null)
Get an option, or return the default.
newBatchIterator( $source)
Wrap an entry iterator into a generator that returns batches of said entries.
commitTransactionRound( $fname)
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
beginTransactionRound( $fname)
Start a transactional batch of DB operations.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Represents a title within MediaWiki.
Definition Title.php:78
internal since 1.36
Definition User.php:93
$maintClass