25 require_once __DIR__ .
'/Maintenance.php';
40 parent::__construct();
41 $this->
addDescription(
'Deletes all pages in the MediaWiki namespace' .
42 ' which were last edited by "MediaWiki default"' );
43 $this->
addOption(
'dry-run',
'Perform a dry run, delete nothing' );
49 $this->
output(
"Checking existence of old default messages..." );
52 $userFactory = $services->getUserFactory();
53 $actorQuery = ActorMigration::newMigration()
54 ->getWhere( $dbr,
'rev_user', $userFactory->newFromName(
'MediaWiki default' ) );
56 $res = $dbr->newSelectQueryBuilder()
57 ->select( [
'page_namespace',
'page_title' ] )
58 ->tables( [
'page',
'revision' ] + $actorQuery[
'tables'] )
63 ->joinConds( [
'revision' => [
'JOIN',
'page_latest=rev_id' ] ] + $actorQuery[
'joins'] )
64 ->caller( __METHOD__ )
67 if ( $res->numRows() == 0 ) {
69 $this->
output(
"done.\n" );
75 foreach ( $res as $row ) {
76 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
77 $this->
output(
"\n* [[$title]]" );
79 $this->
output(
"\n\nRun again without --dry-run to delete these pages.\n" );
85 $user = User::newSystemUser(
'MediaWiki default', [
'steal' =>
true ] );
89 $userGroupManager = $services->getUserGroupManager();
90 $userGroupManager->addUserToGroup( $user,
'bot' );
91 StubGlobalUser::setUser( $user );
94 $this->
output(
"\n...deleting old default messages (this may take a long time!)...",
'msg' );
97 $wikiPageFactory = $services->getWikiPageFactory();
98 $delPageFactory = $services->getDeletePageFactory();
100 foreach ( $res as $row ) {
103 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
104 $page = $wikiPageFactory->newFromTitle( $title );
106 $delPageFactory->newDeletePage( $page, $user )->deleteUnsafe(
'No longer required' );
109 $this->
output(
"done!\n",
'msg' );
114 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.
getServiceContainer()
Returns the main service container.
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.