| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
require_once __DIR__ . '/Maintenance.php'; |
| 28 |
|
| 29 |
|
| 30 |
use MediaWiki\Deferred\SiteStatsUpdate; |
| 31 |
use MediaWiki\Title\Title; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
class NukePage extends Maintenance { |
| 39 |
public function __construct() { |
| 40 |
parent::__construct(); |
| 41 |
$this->addDescription( 'Remove a page record from the database' ); |
| 42 |
$this->addOption( 'delete', "Actually delete the page" ); |
| 43 |
$this->addArg( 'title', 'Title to delete' ); |
| 44 |
} |
| 45 |
|
| 46 |
public function execute() { |
| 47 |
$name = $this->getArg( 0 ); |
| 48 |
$delete = $this->hasOption( 'delete' ); |
| 49 |
|
| 50 |
$dbw = $this->getPrimaryDB(); |
| 51 |
$this->beginTransaction( $dbw, __METHOD__ ); |
| 52 |
|
| 53 |
|
| 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" ); |
| 61 |
|
| 62 |
|
| 63 |
$this->output( "Searching for revisions..." ); |
| 64 |
|
| 65 |
$revs = $dbw->newSelectQueryBuilder() |
| 66 |
->select( 'rev_id' ) |
| 67 |
->from( 'revision' ) |
| 68 |
->where( [ 'rev_page' => $id ] ) |
| 69 |
->caller( __METHOD__ )->fetchFieldValues(); |
| 70 |
$count = count( $revs ); |
| 71 |
$this->output( "found $count.\n" ); |
| 72 |
|
| 73 |
|
| 74 |
if ( $delete ) { |
| 75 |
$this->output( "Deleting page record..." ); |
| 76 |
$dbw->newDeleteQueryBuilder() |
| 77 |
->deleteFrom( 'page' ) |
| 78 |
->where( [ 'page_id' => $id ] ) |
| 79 |
->caller( __METHOD__ )->execute(); |
| 80 |
$this->output( "done.\n" ); |
| 81 |
$this->output( "Cleaning up recent changes..." ); |
| 82 |
$dbw->newDeleteQueryBuilder() |
| 83 |
->deleteFrom( 'recentchanges' ) |
| 84 |
->where( [ 'rc_cur_id' => $id ] ) |
| 85 |
->caller( __METHOD__ )->execute(); |
| 86 |
$this->output( "done.\n" ); |
| 87 |
} |
| 88 |
|
| 89 |
$this->commitTransaction( $dbw, __METHOD__ ); |
| 90 |
|
| 91 |
|
| 92 |
if ( $delete && $count ) { |
| 93 |
$this->output( "Deleting revisions..." ); |
| 94 |
$this->deleteRevisions( $revs ); |
| 95 |
$this->output( "done.\n" ); |
| 96 |
$this->purgeRedundantText( true ); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
if ( $delete ) { |
| 101 |
$this->output( "Updating site stats..." ); |
| 102 |
|
| 103 |
$ga = $isGoodArticle ? -1 : 0; |
| 104 |
$stats = SiteStatsUpdate::factory( [ |
| 105 |
'edits' => -$count, |
| 106 |
'articles' => $ga, |
| 107 |
'pages' => -1 |
| 108 |
] ); |
| 109 |
$stats->doUpdate(); |
| 110 |
$this->output( "done.\n" ); |
| 111 |
} |
| 112 |
} else { |
| 113 |
$this->output( "not found in database.\n" ); |
| 114 |
$this->commitTransaction( $dbw, __METHOD__ ); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
public function deleteRevisions( $ids ) { |
| 119 |
$dbw = $this->getPrimaryDB(); |
| 120 |
$this->beginTransaction( $dbw, __METHOD__ ); |
| 121 |
|
| 122 |
$dbw->newDeleteQueryBuilder() |
| 123 |
->deleteFrom( 'revision' ) |
| 124 |
->where( [ 'rev_id' => $ids ] ) |
| 125 |
->caller( __METHOD__ )->execute(); |
| 126 |
|
| 127 |
$this->commitTransaction( $dbw, __METHOD__ ); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
$maintClass = NukePage::class; |
| 133 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 134 |
|