25 require_once __DIR__ .
'/Maintenance.php';
39 parent::__construct();
40 $this->
addDescription(
'Deletes all pages in the MediaWiki namespace' .
41 ' which were last edited by "MediaWiki default"' );
42 $this->
addOption(
'dry-run',
'Perform a dry run, delete nothing' );
46 $services = MediaWikiServices::getInstance();
48 $this->
output(
"Checking existence of old default messages..." );
51 $userFactory = $services->getUserFactory();
52 $actorQuery = ActorMigration::newMigration()
53 ->getWhere(
$dbr,
'rev_user', $userFactory->newFromName(
'MediaWiki default' ) );
56 ->select( [
'page_namespace',
'page_title' ] )
57 ->tables( [
'page',
'revision' ] + $actorQuery[
'tables'] )
62 ->joinConds( [
'revision' => [
'JOIN',
'page_latest=rev_id' ] ] + $actorQuery[
'joins'] )
63 ->caller( __METHOD__ )
66 if (
$res->numRows() == 0 ) {
68 $this->
output(
"done.\n" );
74 foreach (
$res as $row ) {
76 $this->
output(
"\n* [[$title]]" );
78 $this->
output(
"\n\nRun again without --dry-run to delete these pages.\n" );
88 $userGroupManager = $services->getUserGroupManager();
89 $userGroupManager->addUserToGroup( $user,
'bot' );
90 StubGlobalUser::setUser( $user );
93 $this->
output(
"\n...deleting old default messages (this may take a long time!)...",
'msg' );
96 $wikiPageFactory = $services->getWikiPageFactory();
98 foreach (
$res as $row ) {
102 $page = $wikiPageFactory->newFromTitle(
$title );
104 $page->doDeleteArticleReal(
'No longer required', $user );
107 $this->
output(
"done!\n",
'msg' );
112 require_once RUN_MAINTENANCE_IF_MAIN;
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=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
output( $out, $channel=null)
Throw some output to the user.
waitForReplication()
Wait for replica DBs to catch up.
hasOption( $name)
Checks to see if a particular option was set.
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 makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.