Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
MakeTestEdits | |
0.00% |
0 / 23 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
30 |
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 | require_once __DIR__ . '/Maintenance.php'; |
24 | |
25 | use MediaWiki\Title\Title; |
26 | use MediaWiki\User\User; |
27 | |
28 | /** |
29 | * Make test edits for a user to populate a test wiki |
30 | * |
31 | * @ingroup Maintenance |
32 | */ |
33 | class MakeTestEdits extends Maintenance { |
34 | public function __construct() { |
35 | parent::__construct(); |
36 | $this->addDescription( 'Make test edits for a user' ); |
37 | $this->addOption( 'user', 'User name', true, true ); |
38 | $this->addOption( 'count', 'Number of edits', true, true ); |
39 | $this->addOption( 'namespace', 'Namespace number', false, true ); |
40 | $this->setBatchSize( 100 ); |
41 | } |
42 | |
43 | public function execute() { |
44 | $user = User::newFromName( $this->getOption( 'user' ) ); |
45 | if ( !$user->isRegistered() ) { |
46 | $this->fatalError( "No such user exists." ); |
47 | } |
48 | |
49 | $count = $this->getOption( 'count' ); |
50 | $namespace = (int)$this->getOption( 'namespace', 0 ); |
51 | $services = $this->getServiceContainer(); |
52 | $wikiPageFactory = $services->getWikiPageFactory(); |
53 | |
54 | for ( $i = 0; $i < $count; ++$i ) { |
55 | $title = Title::makeTitleSafe( $namespace, "Page " . wfRandomString( 2 ) ); |
56 | $page = $wikiPageFactory->newFromTitle( $title ); |
57 | $content = ContentHandler::makeContent( wfRandomString(), $title ); |
58 | $summary = "Change " . wfRandomString( 6 ); |
59 | |
60 | $page->doUserEditContent( $content, $user, $summary ); |
61 | |
62 | $this->output( "Edited $title\n" ); |
63 | if ( $i && ( $i % $this->getBatchSize() ) == 0 ) { |
64 | $this->waitForReplication(); |
65 | } |
66 | } |
67 | |
68 | $this->output( "Done\n" ); |
69 | } |
70 | } |
71 | |
72 | $maintClass = MakeTestEdits::class; |
73 | require_once RUN_MAINTENANCE_IF_MAIN; |