deleteDefaultMessages.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Deletes all pages in the MediaWiki namespace which were last edited by
  4. * "MediaWiki default".
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. * http://www.gnu.org/copyleft/gpl.html
  20. *
  21. * @file
  22. * @ingroup Maintenance
  23. */
  24. require_once __DIR__ . '/Maintenance.php';
  25. /**
  26. * Maintenance script that deletes all pages in the MediaWiki namespace
  27. * which were last edited by "MediaWiki default".
  28. *
  29. * @ingroup Maintenance
  30. */
  31. class DeleteDefaultMessages extends Maintenance {
  32. public function __construct() {
  33. parent::__construct();
  34. $this->addDescription( 'Deletes all pages in the MediaWiki namespace' .
  35. ' which were last edited by "MediaWiki default"' );
  36. }
  37. public function execute() {
  38. global $wgUser;
  39. $this->output( "Checking existence of old default messages..." );
  40. $dbr = $this->getDB( DB_SLAVE );
  41. $res = $dbr->select( [ 'page', 'revision' ],
  42. [ 'page_namespace', 'page_title' ],
  43. [
  44. 'page_namespace' => NS_MEDIAWIKI,
  45. 'page_latest=rev_id',
  46. 'rev_user_text' => 'MediaWiki default',
  47. ]
  48. );
  49. if ( $dbr->numRows( $res ) == 0 ) {
  50. # No more messages left
  51. $this->output( "done.\n" );
  52. return;
  53. }
  54. # Deletions will be made by $user temporarly added to the bot group
  55. # in order to hide it in RecentChanges.
  56. $user = User::newFromName( 'MediaWiki default' );
  57. if ( !$user ) {
  58. $this->error( "Invalid username", true );
  59. }
  60. $user->addGroup( 'bot' );
  61. $wgUser = $user;
  62. # Handle deletion
  63. $this->output( "\n...deleting old default messages (this may take a long time!)...", 'msg' );
  64. $dbw = $this->getDB( DB_MASTER );
  65. foreach ( $res as $row ) {
  66. wfWaitForSlaves();
  67. $dbw->ping();
  68. $title = Title::makeTitle( $row->page_namespace, $row->page_title );
  69. $page = WikiPage::factory( $title );
  70. $error = ''; // Passed by ref
  71. // FIXME: Deletion failures should be reported, not silently ignored.
  72. $page->doDeleteArticle( 'No longer required', false, 0, true, $error, $user );
  73. }
  74. $this->output( "done!\n", 'msg' );
  75. }
  76. }
  77. $maintClass = "DeleteDefaultMessages";
  78. require_once RUN_MAINTENANCE_IF_MAIN;