MediaWiki  1.29.2
deleteDefaultMessages.php
Go to the documentation of this file.
1 <?php
25 require_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  }
39 
40  public function execute() {
42 
43  $this->output( "Checking existence of old default messages..." );
44  $dbr = $this->getDB( DB_REPLICA );
45  $res = $dbr->select( [ 'page', 'revision' ],
46  [ 'page_namespace', 'page_title' ],
47  [
48  'page_namespace' => NS_MEDIAWIKI,
49  'page_latest=rev_id',
50  'rev_user_text' => 'MediaWiki default',
51  ]
52  );
53 
54  if ( $dbr->numRows( $res ) == 0 ) {
55  # No more messages left
56  $this->output( "done.\n" );
57 
58  return;
59  }
60 
61  # Deletions will be made by $user temporarly added to the bot group
62  # in order to hide it in RecentChanges.
63  $user = User::newFromName( 'MediaWiki default' );
64  if ( !$user ) {
65  $this->error( "Invalid username", true );
66  }
67  $user->addGroup( 'bot' );
68  $wgUser = $user;
69 
70  # Handle deletion
71  $this->output( "\n...deleting old default messages (this may take a long time!)...", 'msg' );
72  $dbw = $this->getDB( DB_MASTER );
73 
74  foreach ( $res as $row ) {
76  $dbw->ping();
77  $title = Title::makeTitle( $row->page_namespace, $row->page_title );
79  $error = ''; // Passed by ref
80  // FIXME: Deletion failures should be reported, not silently ignored.
81  $page->doDeleteArticle( 'No longer required', false, 0, true, $error, $user );
82  }
83 
84  $this->output( "done!\n", 'msg' );
85  }
86 }
87 
88 $maintClass = "DeleteDefaultMessages";
89 require_once RUN_MAINTENANCE_IF_MAIN;
$wgUser
$wgUser
Definition: Setup.php:781
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
DeleteDefaultMessages
Maintenance script that deletes all pages in the MediaWiki namespace which were last edited by "Media...
Definition: deleteDefaultMessages.php:33
$user
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 account $user
Definition: hooks.txt:246
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:556
$res
$res
Definition: database.txt:21
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
wfWaitForSlaves
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Definition: GlobalFunctions.php:3214
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:934
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:120
$page
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2536
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:514
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
DB_MASTER
const DB_MASTER
Definition: defines.php:26
DeleteDefaultMessages\execute
execute()
Do the actual work.
Definition: deleteDefaultMessages.php:40
$maintClass
$maintClass
Definition: deleteDefaultMessages.php:88
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1251
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:392
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:373
NS_MEDIAWIKI
const NS_MEDIAWIKI
Definition: Defines.php:70
DeleteDefaultMessages\__construct
__construct()
Default constructor.
Definition: deleteDefaultMessages.php:34