MediaWiki REL1_30
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 $res = $dbr->select( [ 'page', 'revision' ],
47 [ 'page_namespace', 'page_title' ],
48 [
49 'page_namespace' => NS_MEDIAWIKI,
50 'page_latest=rev_id',
51 'rev_user_text' => 'MediaWiki default',
52 ]
53 );
54
55 if ( $dbr->numRows( $res ) == 0 ) {
56 // No more messages left
57 $this->output( "done.\n" );
58 return;
59 }
60
61 $dryrun = $this->hasOption( 'dry-run' );
62 if ( $dryrun ) {
63 foreach ( $res as $row ) {
64 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
65 $this->output( "\n* [[$title]]" );
66 }
67 $this->output( "\n\nRun again without --dry-run to delete these pages.\n" );
68 return;
69 }
70
71 // Deletions will be made by $user temporarly added to the bot group
72 // in order to hide it in RecentChanges.
73 $user = User::newFromName( 'MediaWiki default' );
74 if ( !$user ) {
75 $this->error( "Invalid username", true );
76 }
77 $user->addGroup( 'bot' );
78 $wgUser = $user;
79
80 // Handle deletion
81 $this->output( "\n...deleting old default messages (this may take a long time!)...", 'msg' );
82 $dbw = $this->getDB( DB_MASTER );
83
84 foreach ( $res as $row ) {
86 $dbw->ping();
87 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
88 $page = WikiPage::factory( $title );
89 $error = ''; // Passed by ref
90 // FIXME: Deletion failures should be reported, not silently ignored.
91 $page->doDeleteArticle( 'No longer required', false, 0, true, $error, $user );
92 }
93
94 $this->output( "done!\n", 'msg' );
95 }
96}
97
98$maintClass = "DeleteDefaultMessages";
99require_once RUN_MAINTENANCE_IF_MAIN;
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
$wgUser
Definition Setup.php:817
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...
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular param exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:121
if(! $regexes) $dbr
Definition cleanup.php:94
$res
Definition database.txt:21
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition hooks.txt:2581
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
require_once RUN_MAINTENANCE_IF_MAIN
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26