Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
30 / 30 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
MakeTestEdits | |
100.00% |
30 / 30 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
5 |
1 | <?php |
2 | /** |
3 | * Make test edits for a user to populate a test wiki |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | * http://www.gnu.org/copyleft/gpl.html |
19 | * |
20 | * @file |
21 | * @ingroup Maintenance |
22 | */ |
23 | // @codeCoverageIgnoreStart |
24 | require_once __DIR__ . '/Maintenance.php'; |
25 | // @codeCoverageIgnoreEnd |
26 | |
27 | use MediaWiki\Content\ContentHandler; |
28 | use MediaWiki\Maintenance\Maintenance; |
29 | use MediaWiki\Title\Title; |
30 | use MediaWiki\User\User; |
31 | |
32 | /** |
33 | * Make test edits for a user to populate a test wiki |
34 | * |
35 | * @ingroup Maintenance |
36 | */ |
37 | class MakeTestEdits extends Maintenance { |
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 | |
59 | /** @var iterable<Title[]> $titleBatches */ |
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; |
88 | require_once RUN_MAINTENANCE_IF_MAIN; |
89 | // @codeCoverageIgnoreEnd |