23require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
38 $this->
addDescription(
'Remove pages with only 1 revision from any namespace' );
39 $this->
addOption(
'delete',
"Actually delete the page" );
40 $this->
addOption(
'ns',
'Namespace to delete from, default NS_MEDIAWIKI',
false,
true );
41 $this->
addOption(
'all',
'Delete everything regardless of revision count' );
51 $res = $dbw->newSelectQueryBuilder()
52 ->select(
'page_title' )
54 ->where( [
'page_namespace' => $ns ] )
55 ->caller( __METHOD__ )->fetchResultSet();
59 foreach ( $res as $row ) {
61 $title = Title::makeTitle( $ns, $row->page_title );
62 $id = $title->getArticleID();
65 $revs = $dbw->newSelectQueryBuilder()
68 ->where( [
'rev_page' => $id ] )
69 ->caller( __METHOD__ )->fetchFieldValues();
70 $count = count( $revs );
73 if ( $all || $count == 1 ) {
74 # echo $title->getPrefixedText(), "\t", $count, "\n";
75 $this->
output(
"delete: " . $title->getPrefixedText() .
"\n" );
80 $deleteQueryBuilder = $dbw->newDeleteQueryBuilder()
81 ->deleteFrom(
'page' )
82 ->where( [
'page_id' => $id ] )
83 ->caller( __METHOD__ );
84 $deleteQueryBuilder->execute();
89 $child = $this->
createChild( NukePage::class,
'nukePage.php' );
90 '@phan-var NukePage $child';
91 $child->deleteRevisions( $revs );
95 $this->
output(
"skip: " . $title->getPrefixedText() .
"\n" );
100 if ( $n_deleted > 0 ) {
103 # update statistics - better to decrement existing count, or just count
105 $pages = $dbw->newSelectQueryBuilder()
106 ->select(
'ss_total_pages' )
107 ->from(
'site_stats' )
108 ->caller( __METHOD__ )->fetchField();
109 $pages -= $n_deleted;
110 $dbw->newUpdateQueryBuilder()
111 ->update(
'site_stats' )
112 ->set( [
'ss_total_pages' => $pages ] )
113 ->where( [
'ss_row_id' => 1 ] )
114 ->caller( __METHOD__ )
119 $this->
output(
"To update the database, run the script with the --delete option.\n" );
126require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
createChild(string $maintClass, ?string $classFile=null)
Returns an instance of the given maintenance script, with all of the current arguments passed to it.
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
commitTransactionRound( $fname)
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
beginTransactionRound( $fname)
Start a transactional batch of DB operations.
getServiceContainer()
Returns the main service container.
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.
Maintenance script that removes pages with only one revision from the MediaWiki namespace.
execute()
Do the actual work.
__construct()
Default constructor.