makeTestEdits.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * Make test edits for a user to populate a test wiki
  26. *
  27. * @ingroup Maintenance
  28. */
  29. class MakeTestEdits extends Maintenance {
  30. public function __construct() {
  31. parent::__construct();
  32. $this->addDescription( 'Make test edits for a user' );
  33. $this->addOption( 'user', 'User name', true, true );
  34. $this->addOption( 'count', 'Number of edits', true, true );
  35. $this->addOption( 'namespace', 'Namespace number', false, true );
  36. $this->setBatchSize( 100 );
  37. }
  38. public function execute() {
  39. $user = User::newFromName( $this->getOption( 'user' ) );
  40. if ( !$user->getId() ) {
  41. $this->fatalError( "No such user exists." );
  42. }
  43. $count = $this->getOption( 'count' );
  44. $namespace = (int)$this->getOption( 'namespace', 0 );
  45. for ( $i = 0; $i < $count; ++$i ) {
  46. $title = Title::makeTitleSafe( $namespace, "Page " . wfRandomString( 2 ) );
  47. $page = WikiPage::factory( $title );
  48. $content = ContentHandler::makeContent( wfRandomString(), $title );
  49. $summary = "Change " . wfRandomString( 6 );
  50. $page->doEditContent( $content, $summary, 0, false, $user );
  51. $this->output( "Edited $title\n" );
  52. if ( $i && ( $i % $this->getBatchSize() ) == 0 ) {
  53. wfWaitForSlaves();
  54. }
  55. }
  56. $this->output( "Done\n" );
  57. }
  58. }
  59. $maintClass = MakeTestEdits::class;
  60. require_once RUN_MAINTENANCE_IF_MAIN;