MediaWiki
master
Toggle main menu visibility
makeTestEdits.php
Go to the documentation of this file.
1
<?php
9
// @codeCoverageIgnoreStart
10
require_once __DIR__ .
'/Maintenance.php'
;
11
// @codeCoverageIgnoreEnd
12
13
use
MediaWiki\Content\ContentHandler
;
14
use
MediaWiki\Maintenance\Maintenance
;
15
use MediaWiki\Title\Title;
16
use MediaWiki\User\User;
17
23
class
MakeTestEdits
extends
Maintenance
{
24
public
function
__construct
() {
25
parent::__construct();
26
$this->addDescription(
'Make test edits for a user'
);
27
$this->addOption(
'user'
,
'User name'
,
true
,
true
);
28
$this->addOption(
'count'
,
'Number of edits'
,
true
,
true
);
29
$this->addOption(
'namespace'
,
'Namespace number'
,
false
,
true
);
30
$this->addOption(
'watchlist'
,
'Add edited pages to user watchlist'
,
false
,
false
);
31
$this->setBatchSize( 100 );
32
}
33
34
public
function
execute
() {
35
$user =
User::newFromName
( $this->getOption(
'user'
) );
36
if
( !$user->isRegistered() ) {
37
$this->fatalError(
"No such user exists."
);
38
}
39
40
$count = (int)$this->getOption(
'count'
);
41
$namespace = (int)$this->getOption(
'namespace'
, 0 );
42
$batchSize = $this->getBatchSize();
43
$services = $this->getServiceContainer();
44
$wikiPageFactory = $services->getWikiPageFactory();
45
$watchedItemStore = $services->getWatchedItemStore();
46
48
$titleBatches = $this->newBatchIterator(
49
static
function
() use ( $namespace, $count ) {
50
for
( $i = 0; $i < $count; ++$i ) {
51
yield
Title::makeTitleSafe
( $namespace,
"Page "
.
wfRandomString
( 2 ) );
52
}
53
}
54
);
55
56
$watchlist = $this->getOption(
'watchlist'
);
57
foreach
( $titleBatches as $titleBatch ) {
58
$editedTitles = $watchlist ? [] :
null
;
59
$this->beginTransactionRound( __METHOD__ );
60
foreach
( $titleBatch as $title ) {
61
$page = $wikiPageFactory->newFromTitle( $title );
62
$content =
ContentHandler::makeContent
(
wfRandomString
(), $title );
63
$summary =
"Change "
.
wfRandomString
( 6 );
64
65
$page->doUserEditContent( $content, $user, $summary );
66
67
// Collect titles for watchlist if requested
68
if
( $watchlist ) {
69
$editedTitles[] = $title;
70
}
71
72
$this->output(
"Edited $title\n"
);
73
}
74
if
( $editedTitles ) {
75
$watchedItemStore->
addWatchBatchForUser
( $user, $editedTitles );
76
}
77
$this->commitTransactionRound( __METHOD__ );
78
}
79
80
$this->output(
"Done\n"
);
81
}
82
}
83
84
// @codeCoverageIgnoreStart
85
$maintClass
= MakeTestEdits::class;
86
require_once RUN_MAINTENANCE_IF_MAIN;
87
// @codeCoverageIgnoreEnd
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition
GlobalFunctions.php:169
$maintClass
$maintClass
Definition
addChangeTag.php:56
MakeTestEdits
Make test edits for a user to populate a test wiki.
Definition
makeTestEdits.php:23
MakeTestEdits\execute
execute()
Definition
makeTestEdits.php:34
MakeTestEdits\__construct
__construct()
Definition
makeTestEdits.php:24
MediaWiki\Content\ContentHandler
Base class for content handling.
Definition
ContentHandler.php:74
MediaWiki\Content\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:100
MediaWiki\Title\Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition
Title.php:635
MediaWiki\User\User\newFromName
static newFromName( $name, $validate='valid')
Definition
User.php:610
MediaWiki\Watchlist\WatchedItemStoreInterface\addWatchBatchForUser
addWatchBatchForUser(UserIdentity $user, array $targets, ?string $expiry=null)
MediaWiki\Maintenance
Definition
applyChangeTag.php:11
maintenance
makeTestEdits.php
Generated on
for MediaWiki by
1.18.0