| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
require_once __DIR__ . '/Maintenance.php'; |
| 25 |
|
| 26 |
|
| 27 |
use MediaWiki\Content\ContentHandler; |
| 28 |
use MediaWiki\Title\Title; |
| 29 |
use MediaWiki\User\User; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class MakeTestEdits extends Maintenance { |
| 37 |
public function __construct() { |
| 38 |
parent::__construct(); |
| 39 |
$this->addDescription( 'Make test edits for a user' ); |
| 40 |
$this->addOption( 'user', 'User name', true, true ); |
| 41 |
$this->addOption( 'count', 'Number of edits', true, true ); |
| 42 |
$this->addOption( 'namespace', 'Namespace number', false, true ); |
| 43 |
$this->setBatchSize( 100 ); |
| 44 |
} |
| 45 |
|
| 46 |
public function execute() { |
| 47 |
$user = User::newFromName( $this->getOption( 'user' ) ); |
| 48 |
if ( !$user->isRegistered() ) { |
| 49 |
$this->fatalError( "No such user exists." ); |
| 50 |
} |
| 51 |
|
| 52 |
$count = $this->getOption( 'count' ); |
| 53 |
$namespace = (int)$this->getOption( 'namespace', 0 ); |
| 54 |
$services = $this->getServiceContainer(); |
| 55 |
$wikiPageFactory = $services->getWikiPageFactory(); |
| 56 |
|
| 57 |
for ( $i = 0; $i < $count; ++$i ) { |
| 58 |
$title = Title::makeTitleSafe( $namespace, "Page " . wfRandomString( 2 ) ); |
| 59 |
$page = $wikiPageFactory->newFromTitle( $title ); |
| 60 |
$content = ContentHandler::makeContent( wfRandomString(), $title ); |
| 61 |
$summary = "Change " . wfRandomString( 6 ); |
| 62 |
|
| 63 |
$page->doUserEditContent( $content, $user, $summary ); |
| 64 |
|
| 65 |
$this->output( "Edited $title\n" ); |
| 66 |
if ( $i && ( $i % $this->getBatchSize() ) == 0 ) { |
| 67 |
$this->waitForReplication(); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
$this->output( "Done\n" ); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
$maintClass = MakeTestEdits::class; |
| 77 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 78 |
|