2015-12-08 21:35:34 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Make test edits for a user to populate a test wiki
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2015-12-08 21:35:34 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
2015-12-08 21:35:34 +00:00
|
|
|
|
2024-10-21 17:06:13 +00:00
|
|
|
use MediaWiki\Content\ContentHandler;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-09-19 12:13:45 +00:00
|
|
|
use MediaWiki\User\User;
|
2020-05-01 00:36:46 +00:00
|
|
|
|
2015-12-08 21:35:34 +00:00
|
|
|
/**
|
|
|
|
|
* Make test edits for a user to populate a test wiki
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
|
|
|
|
class MakeTestEdits extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Make test edits for a user' );
|
2015-12-08 21:35:34 +00:00
|
|
|
$this->addOption( 'user', 'User name', true, true );
|
|
|
|
|
$this->addOption( 'count', 'Number of edits', true, true );
|
|
|
|
|
$this->addOption( 'namespace', 'Namespace number', false, true );
|
|
|
|
|
$this->setBatchSize( 100 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
$user = User::newFromName( $this->getOption( 'user' ) );
|
2022-04-29 18:32:20 +00:00
|
|
|
if ( !$user->isRegistered() ) {
|
2017-11-20 00:36:54 +00:00
|
|
|
$this->fatalError( "No such user exists." );
|
2015-12-08 21:35:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$count = $this->getOption( 'count' );
|
|
|
|
|
$namespace = (int)$this->getOption( 'namespace', 0 );
|
2023-08-31 09:21:12 +00:00
|
|
|
$services = $this->getServiceContainer();
|
2020-11-12 20:36:35 +00:00
|
|
|
$wikiPageFactory = $services->getWikiPageFactory();
|
2015-12-08 21:35:34 +00:00
|
|
|
|
|
|
|
|
for ( $i = 0; $i < $count; ++$i ) {
|
|
|
|
|
$title = Title::makeTitleSafe( $namespace, "Page " . wfRandomString( 2 ) );
|
2020-11-12 20:36:35 +00:00
|
|
|
$page = $wikiPageFactory->newFromTitle( $title );
|
2015-12-08 21:35:34 +00:00
|
|
|
$content = ContentHandler::makeContent( wfRandomString(), $title );
|
|
|
|
|
$summary = "Change " . wfRandomString( 6 );
|
|
|
|
|
|
2021-06-24 08:42:19 +00:00
|
|
|
$page->doUserEditContent( $content, $user, $summary );
|
2015-12-08 21:35:34 +00:00
|
|
|
|
|
|
|
|
$this->output( "Edited $title\n" );
|
2017-11-05 08:09:51 +00:00
|
|
|
if ( $i && ( $i % $this->getBatchSize() ) == 0 ) {
|
2022-10-24 18:31:49 +00:00
|
|
|
$this->waitForReplication();
|
2015-12-08 21:35:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->output( "Done\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = MakeTestEdits::class;
|
2015-12-08 21:35:34 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|