MediaWiki REL1_33
deleteDefaultMessages.php
Go to the documentation of this file.
1<?php
25require_once __DIR__ . '/Maintenance.php';
26
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Deletes all pages in the MediaWiki namespace' .
37 ' which were last edited by "MediaWiki default"' );
38 $this->addOption( 'dry-run', 'Perform a dry run, delete nothing' );
39 }
40
41 public function execute() {
42 global $wgUser;
43
44 $this->output( "Checking existence of old default messages..." );
45 $dbr = $this->getDB( DB_REPLICA );
46
47 $actorQuery = ActorMigration::newMigration()
48 ->getWhere( $dbr, 'rev_user', User::newFromName( 'MediaWiki default' ) );
49 $res = $dbr->select(
50 [ 'page', 'revision' ] + $actorQuery['tables'],
51 [ 'page_namespace', 'page_title' ],
52 [
53 'page_namespace' => NS_MEDIAWIKI,
54 $actorQuery['conds'],
55 ],
56 __METHOD__,
57 [],
58 [ 'revision' => [ 'JOIN', 'page_latest=rev_id' ] ] + $actorQuery['joins']
59 );
60
61 if ( $dbr->numRows( $res ) == 0 ) {
62 // No more messages left
63 $this->output( "done.\n" );
64 return;
65 }
66
67 $dryrun = $this->hasOption( 'dry-run' );
68 if ( $dryrun ) {
69 foreach ( $res as $row ) {
70 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
71 $this->output( "\n* [[$title]]" );
72 }
73 $this->output( "\n\nRun again without --dry-run to delete these pages.\n" );
74 return;
75 }
76
77 // Deletions will be made by $user temporarly added to the bot group
78 // in order to hide it in RecentChanges.
79 $user = User::newFromName( 'MediaWiki default' );
80 if ( !$user ) {
81 $this->fatalError( "Invalid username" );
82 }
83 $user->addGroup( 'bot' );
84 $wgUser = $user;
85
86 // Handle deletion
87 $this->output( "\n...deleting old default messages (this may take a long time!)...", 'msg' );
88 $dbw = $this->getDB( DB_MASTER );
89
90 foreach ( $res as $row ) {
92 $dbw->ping();
93 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
94 $page = WikiPage::factory( $title );
95 $error = ''; // Passed by ref
96 // FIXME: Deletion failures should be reported, not silently ignored.
97 $page->doDeleteArticle( 'No longer required', false, 0, true, $error, $user );
98 }
99
100 $this->output( "done!\n", 'msg' );
101 }
102}
103
104$maintClass = DeleteDefaultMessages::class;
105require_once RUN_MAINTENANCE_IF_MAIN;
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Maintenance script that deletes all pages in the MediaWiki namespace which were last edited by "Media...
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition User.php:585
$res
Definition database.txt:21
return true to allow those checks to and false if checking is done & $user
Definition hooks.txt:1510
require_once RUN_MAINTENANCE_IF_MAIN
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26