2007-01-17 21:47:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove pages with only 1 revision from the MediaWiki namespace, without
|
|
|
|
|
* flooding recent changes, delete logs, etc.
|
|
|
|
|
* Irreversible (can't use standard undelete) and does not update link tables
|
|
|
|
|
*
|
|
|
|
|
* This is mainly useful to run before maintenance/update.php when upgrading
|
|
|
|
|
* to 1.9, to prevent flooding recent changes/deletion logs. It's intended
|
|
|
|
|
* to be conservative, so it's possible that a few entries will be left for
|
|
|
|
|
* deletion by the upgrade script. It's also possible that it hasn't been
|
|
|
|
|
* tested thouroughly enough, and will delete something it shouldn't; so
|
|
|
|
|
* back up your DB if there's anything in the MediaWiki that is important to
|
|
|
|
|
* you.
|
|
|
|
|
*
|
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
|
|
|
|
|
*
|
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
|
2007-01-17 21:47:55 +00:00
|
|
|
* @author Steve Sanbeg
|
|
|
|
|
* based on nukePage by Rob Church
|
|
|
|
|
*/
|
|
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
require_once( dirname( __FILE__ ) . '/Maintenance.php' );
|
2007-01-17 21:47:55 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
class NukeNS extends Maintenance {
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->mDescription = "Remove pages with only 1 revision from any namespace";
|
|
|
|
|
$this->addOption( 'delete', "Actually delete the page" );
|
|
|
|
|
$this->addOption( 'ns', 'Namespace to delete from, default NS_MEDIAWIKI', false, true );
|
2011-07-22 16:10:22 +00:00
|
|
|
$this->addOption( 'all', 'Delete everything regardless of revision count' );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2007-01-17 21:47:55 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
|
|
|
|
$ns = $this->getOption( 'ns', NS_MEDIAWIKI );
|
|
|
|
|
$delete = $this->getOption( 'delete', false );
|
2011-07-22 16:10:22 +00:00
|
|
|
$all = $this->getOption( 'all', false );
|
2009-08-02 19:35:17 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2012-02-24 18:45:24 +00:00
|
|
|
$dbw->begin( __METHOD__ );
|
2007-01-17 21:47:55 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$tbl_pag = $dbw->tableName( 'page' );
|
|
|
|
|
$tbl_rev = $dbw->tableName( 'revision' );
|
|
|
|
|
$res = $dbw->query( "SELECT page_title FROM $tbl_pag WHERE page_namespace = $ns" );
|
2007-01-17 21:47:55 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$n_deleted = 0;
|
2007-01-19 17:16:45 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
// echo "$ns_name:".$row->page_title, "\n";
|
2009-08-17 21:15:31 +00:00
|
|
|
$title = Title::makeTitle( $ns, $row->page_title );
|
2009-08-02 19:35:17 +00:00
|
|
|
$id = $title->getArticleID();
|
2007-01-17 21:47:55 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
// Get corresponding revisions
|
|
|
|
|
$res2 = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
|
|
|
|
|
$revs = array();
|
2007-01-17 21:47:55 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
foreach ( $res2 as $row2 ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$revs[] = $row2->rev_id;
|
|
|
|
|
}
|
|
|
|
|
$count = count( $revs );
|
2007-01-17 21:47:55 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
// skip anything that looks modified (i.e. multiple revs)
|
2011-07-22 16:10:22 +00:00
|
|
|
if ( $all || $count == 1 ) {
|
2010-05-22 16:50:39 +00:00
|
|
|
# echo $title->getPrefixedText(), "\t", $count, "\n";
|
2009-08-17 21:15:31 +00:00
|
|
|
$this->output( "delete: " . $title->getPrefixedText() . "\n" );
|
2007-01-17 21:47:55 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
// as much as I hate to cut & paste this, it's a little different, and
|
|
|
|
|
// I already have the id & revs
|
|
|
|
|
if ( $delete ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
|
2012-02-24 18:45:24 +00:00
|
|
|
$dbw->commit( __METHOD__ );
|
2009-08-02 19:35:17 +00:00
|
|
|
// Delete revisions as appropriate
|
2011-07-22 16:10:22 +00:00
|
|
|
$child = $this->runChild( 'NukePage', 'nukePage.php' );
|
2009-08-02 19:35:17 +00:00
|
|
|
$child->deleteRevisions( $revs );
|
|
|
|
|
$this->purgeRedundantText( true );
|
|
|
|
|
$n_deleted ++;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2009-08-17 21:15:31 +00:00
|
|
|
$this->output( "skip: " . $title->getPrefixedText() . "\n" );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-02-24 18:45:24 +00:00
|
|
|
$dbw->commit( __METHOD__ );
|
2007-01-17 21:47:55 +00:00
|
|
|
|
2009-08-17 21:15:31 +00:00
|
|
|
if ( $n_deleted > 0 ) {
|
2010-05-22 16:50:39 +00:00
|
|
|
# update statistics - better to decrement existing count, or just count
|
|
|
|
|
# the page table?
|
2009-08-17 21:15:31 +00:00
|
|
|
$pages = $dbw->selectField( 'site_stats', 'ss_total_pages' );
|
|
|
|
|
$pages -= $n_deleted;
|
|
|
|
|
$dbw->update(
|
2010-05-22 16:50:39 +00:00
|
|
|
'site_stats',
|
|
|
|
|
array( 'ss_total_pages' => $pages ),
|
2009-08-17 21:15:31 +00:00
|
|
|
array( 'ss_row_id' => 1 ),
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2009-08-17 21:15:31 +00:00
|
|
|
if ( !$delete ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "To update the database, run the script with the --delete option.\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-01-17 21:47:55 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$maintClass = "NukeNS";
|
2011-01-13 22:58:55 +00:00
|
|
|
require_once( RUN_MAINTENANCE_IF_MAIN );
|