2006-01-25 21:08:29 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Erase a page record from the database
|
|
|
|
|
* Irreversible (can't use standard undelete) and does not update link tables
|
|
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
2012-07-25 19:31:06 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
2006-01-25 21:08:29 +00:00
|
|
|
* @author Rob Church <robchur@gmail.com>
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2009-06-24 02:02:37 +00:00
|
|
|
|
2012-07-25 19:31:06 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script that erases a page record from the database.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class NukePage extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription( 'Remove a page record from the database' );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->addOption( 'delete', "Actually delete the page" );
|
2009-08-18 23:06:24 +00:00
|
|
|
$this->addArg( 'title', 'Title to delete' );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2009-06-24 02:02:37 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
2019-02-28 11:13:49 +00:00
|
|
|
$name = $this->getArg( 0 );
|
2017-07-19 19:51:30 +00:00
|
|
|
$delete = $this->hasOption( 'delete' );
|
2009-08-02 19:35:17 +00:00
|
|
|
|
2015-12-31 00:07:37 +00:00
|
|
|
$dbw = $this->getDB( DB_MASTER );
|
2015-12-22 08:51:42 +00:00
|
|
|
$this->beginTransaction( $dbw, __METHOD__ );
|
2009-08-02 19:35:17 +00:00
|
|
|
|
|
|
|
|
# Get page ID
|
|
|
|
|
$this->output( "Searching for \"$name\"..." );
|
|
|
|
|
$title = Title::newFromText( $name );
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $title ) {
|
2013-04-18 18:48:44 +00:00
|
|
|
$id = $title->getArticleID();
|
2009-08-02 19:35:17 +00:00
|
|
|
$real = $title->getPrefixedText();
|
|
|
|
|
$isGoodArticle = $title->isContentPage();
|
|
|
|
|
$this->output( "found \"$real\" with ID $id.\n" );
|
|
|
|
|
|
|
|
|
|
# Get corresponding revisions
|
|
|
|
|
$this->output( "Searching for revisions..." );
|
2020-05-08 21:31:41 +00:00
|
|
|
|
|
|
|
|
$revs = $dbw->selectFieldValues(
|
|
|
|
|
'revision',
|
|
|
|
|
'rev_id',
|
|
|
|
|
[ 'rev_page' => $id ],
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2009-08-02 19:35:17 +00:00
|
|
|
$count = count( $revs );
|
|
|
|
|
$this->output( "found $count.\n" );
|
|
|
|
|
|
|
|
|
|
# Delete the page record and associated recent changes entries
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $delete ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Deleting page record..." );
|
2020-05-08 21:31:41 +00:00
|
|
|
$dbw->delete( 'page', [ 'page_id' => $id ], __METHOD__ );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "done.\n" );
|
|
|
|
|
$this->output( "Cleaning up recent changes..." );
|
2020-05-08 21:31:41 +00:00
|
|
|
$dbw->delete( 'recentchanges', [ 'rc_cur_id' => $id ], __METHOD__ );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "done.\n" );
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-22 08:51:42 +00:00
|
|
|
$this->commitTransaction( $dbw, __METHOD__ );
|
2009-08-02 19:35:17 +00:00
|
|
|
|
|
|
|
|
# Delete revisions as appropriate
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( $delete && $count ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Deleting revisions..." );
|
|
|
|
|
$this->deleteRevisions( $revs );
|
|
|
|
|
$this->output( "done.\n" );
|
|
|
|
|
$this->purgeRedundantText( true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Update stats as appropriate
|
|
|
|
|
if ( $delete ) {
|
|
|
|
|
$this->output( "Updating site stats..." );
|
|
|
|
|
$ga = $isGoodArticle ? -1 : 0; // if it was good, decrement that too
|
2019-07-06 06:26:17 +00:00
|
|
|
$stats = SiteStatsUpdate::factory( [
|
|
|
|
|
'edits' => -$count,
|
|
|
|
|
'articles' => $ga,
|
|
|
|
|
'pages' => -1
|
|
|
|
|
] );
|
2009-08-02 19:35:17 +00:00
|
|
|
$stats->doUpdate();
|
|
|
|
|
$this->output( "done.\n" );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->output( "not found in database.\n" );
|
2015-12-22 08:51:42 +00:00
|
|
|
$this->commitTransaction( $dbw, __METHOD__ );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleteRevisions( $ids ) {
|
2015-12-31 00:07:37 +00:00
|
|
|
$dbw = $this->getDB( DB_MASTER );
|
2015-12-22 08:51:42 +00:00
|
|
|
$this->beginTransaction( $dbw, __METHOD__ );
|
2009-08-02 19:35:17 +00:00
|
|
|
|
2020-05-08 21:31:41 +00:00
|
|
|
$dbw->delete( 'revision', [ 'rev_id' => $ids ], __METHOD__ );
|
2006-01-25 21:08:29 +00:00
|
|
|
|
2015-12-22 08:51:42 +00:00
|
|
|
$this->commitTransaction( $dbw, __METHOD__ );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2006-01-25 21:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = NukePage::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|