MediaWiki  master
Go to the documentation of this file.
1 <?php
25 require_once __DIR__ . '/Maintenance.php';
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  }
41  public function execute() {
42  global $wgUser;
44  $this->output( "Checking existence of old default messages..." );
45  $dbr = $this->getDB( DB_REPLICA );
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  );
61  if ( $dbr->numRows( $res ) == 0 ) {
62  // No more messages left
63  $this->output( "done.\n" );
64  return;
65  }
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  }
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;
86  // Handle deletion
87  $this->output( "\n...deleting old default messages (this may take a long time!)...", 'msg' );
88  $dbw = $this->getDB( DB_MASTER );
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  }
100  $this->output( "done!\n", 'msg' );
101  }
102 }
105 require_once RUN_MAINTENANCE_IF_MAIN;
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
Maintenance script that deletes all pages in the MediaWiki namespace which were last edited by "Media...
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
hasOption( $name)
Checks to see if a particular option exists.
Definition: maintenance.txt:50
Definition: defines.php:26
static newMigration()
Static constructor.
Definition: database.txt:21
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
addDescription( $text)
Set the description text.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
output( $out, $channel=null)
Throw some output to the user.
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
Definition: Defines.php:68
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:589
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
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
Definition: defines.php:25
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:594
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473