MediaWiki  1.23.2
nukePage.php
Go to the documentation of this file.
1 <?php
26 require_once __DIR__ . '/Maintenance.php';
27 
33 class NukePage extends Maintenance {
34  public function __construct() {
35  parent::__construct();
36  $this->mDescription = "Remove a page record from the database";
37  $this->addOption( 'delete', "Actually delete the page" );
38  $this->addArg( 'title', 'Title to delete' );
39  }
40 
41  public function execute() {
42 
43  $name = $this->getArg();
44  $delete = $this->getOption( 'delete', false );
45 
46  $dbw = wfGetDB( DB_MASTER );
47  $dbw->begin( __METHOD__ );
48 
49  $tbl_pag = $dbw->tableName( 'page' );
50  $tbl_rec = $dbw->tableName( 'recentchanges' );
51  $tbl_rev = $dbw->tableName( 'revision' );
52 
53  # Get page ID
54  $this->output( "Searching for \"$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" );
61 
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 = array();
66  foreach ( $res as $row ) {
67  $revs[] = $row->rev_id;
68  }
69  $count = count( $revs );
70  $this->output( "found $count.\n" );
71 
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  }
81 
82  $dbw->commit( __METHOD__ );
83 
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  }
91 
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  $dbw->commit( __METHOD__ );
103  }
104  }
105 
106  public function deleteRevisions( $ids ) {
107  $dbw = wfGetDB( DB_MASTER );
108  $dbw->begin( __METHOD__ );
109 
110  $tbl_rev = $dbw->tableName( 'revision' );
111 
112  $set = implode( ', ', $ids );
113  $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );
114 
115  $dbw->commit( __METHOD__ );
116  }
117 }
118 
119 $maintClass = "NukePage";
120 require_once RUN_MAINTENANCE_IF_MAIN;
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
NukePage
Maintenance script that erases a page record from the database.
Definition: nukePage.php:33
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
NukePage\execute
execute()
Do the actual work.
Definition: nukePage.php:41
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SiteStatsUpdate
Class for handling updates to the site_stats table.
Definition: SiteStatsUpdate.php:24
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$maintClass
$maintClass
Definition: nukePage.php:119
NukePage\deleteRevisions
deleteRevisions( $ids)
Definition: nukePage.php:106
Maintenance\purgeRedundantText
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
Definition: Maintenance.php:943
$count
$count
Definition: UtfNormalTest2.php:96
NukePage\__construct
__construct()
Default constructor.
Definition: nukePage.php:34
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:207
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\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:246
$res
$res
Definition: database.txt:21