MediaWiki REL1_28
Go to the documentation of this file.
26require_once __DIR__ . '/Maintenance.php';
33class NukePage extends Maintenance {
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Remove a page record from the database' );
37 $this->addOption( 'delete', "Actually delete the page" );
38 $this->addArg( 'title', 'Title to delete' );
39 }
41 public function execute() {
43 $name = $this->getArg();
44 $delete = $this->getOption( 'delete', false );
46 $dbw = $this->getDB( DB_MASTER );
47 $this->beginTransaction( $dbw, __METHOD__ );
49 $tbl_pag = $dbw->tableName( 'page' );
50 $tbl_rec = $dbw->tableName( 'recentchanges' );
51 $tbl_rev = $dbw->tableName( 'revision' );
53 # Get page ID
54 $this->output( "Searching for \"$name\"..." );
55 $title = Title::newFromText( $name );
56 if ( $title ) {
57 $id = $title->getArticleID();
58 $real = $title->getPrefixedText();
59 $isGoodArticle = $title->isContentPage();
60 $this->output( "found \"$real\" with ID $id.\n" );
62 # Get corresponding revisions
63 $this->output( "Searching for revisions..." );
64 $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
65 $revs = [];
66 foreach ( $res as $row ) {
67 $revs[] = $row->rev_id;
68 }
69 $count = count( $revs );
70 $this->output( "found $count.\n" );
72 # Delete the page record and associated recent changes entries
73 if ( $delete ) {
74 $this->output( "Deleting page record..." );
75 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
76 $this->output( "done.\n" );
77 $this->output( "Cleaning up recent changes..." );
78 $dbw->query( "DELETE FROM $tbl_rec WHERE rc_cur_id = $id" );
79 $this->output( "done.\n" );
80 }
82 $this->commitTransaction( $dbw, __METHOD__ );
84 # Delete revisions as appropriate
85 if ( $delete && $count ) {
86 $this->output( "Deleting revisions..." );
87 $this->deleteRevisions( $revs );
88 $this->output( "done.\n" );
89 $this->purgeRedundantText( true );
90 }
92 # Update stats as appropriate
93 if ( $delete ) {
94 $this->output( "Updating site stats..." );
95 $ga = $isGoodArticle ? -1 : 0; // if it was good, decrement that too
96 $stats = new SiteStatsUpdate( 0, -$count, $ga, -1 );
97 $stats->doUpdate();
98 $this->output( "done.\n" );
99 }
100 } else {
101 $this->output( "not found in database.\n" );
102 $this->commitTransaction( $dbw, __METHOD__ );
103 }
104 }
106 public function deleteRevisions( $ids ) {
107 $dbw = $this->getDB( DB_MASTER );
108 $this->beginTransaction( $dbw, __METHOD__ );
110 $tbl_rev = $dbw->tableName( 'revision' );
112 $set = implode( ', ', $ids );
113 $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );
115 $this->commitTransaction( $dbw, __METHOD__ );
116 }
119$maintClass = "NukePage";
120require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true)
Add some args that are needed.
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Maintenance script that erases a page record from the database.
Definition nukePage.php:33
deleteRevisions( $ids)
Definition nukePage.php:106
Default constructor.
Definition nukePage.php:34
Do the actual work.
Definition nukePage.php:41
Class for handling updates to the site_stats table.
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
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
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
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:37
Definition nukePage.php:119
Definition defines.php:23