37require_once __DIR__ .
'/Maintenance.php';
51 parent::__construct();
52 $this->
addDescription(
'Remove pages with only 1 revision from any namespace' );
53 $this->
addOption(
'delete',
"Actually delete the page" );
54 $this->
addOption(
'ns',
'Namespace to delete from, default NS_MEDIAWIKI',
false,
true );
55 $this->
addOption(
'all',
'Delete everything regardless of revision count' );
65 $res = $dbw->newSelectQueryBuilder()
66 ->select(
'page_title' )
68 ->where( [
'page_namespace' => $ns ] )
69 ->caller( __METHOD__ )->fetchResultSet();
73 foreach ( $res as $row ) {
75 $title = Title::makeTitle( $ns, $row->page_title );
76 $id = $title->getArticleID();
79 $revs = $dbw->newSelectQueryBuilder()
82 ->where( [
'rev_page' => $id ] )
83 ->caller( __METHOD__ )->fetchFieldValues();
84 $count = count( $revs );
87 if ( $all || $count == 1 ) {
88 # echo $title->getPrefixedText(), "\t", $count, "\n";
89 $this->
output(
"delete: " . $title->getPrefixedText() .
"\n" );
94 $dbw->newDeleteQueryBuilder()
95 ->deleteFrom(
'page' )
96 ->where( [
'page_id' => $id ] )
97 ->caller( __METHOD__ )->execute();
101 $child = $this->
runChild( NukePage::class,
'nukePage.php' );
102 '@phan-var NukePage $child';
103 $child->deleteRevisions( $revs );
107 $this->
output(
"skip: " . $title->getPrefixedText() .
"\n" );
112 if ( $n_deleted > 0 ) {
115 # update statistics - better to decrement existing count, or just count
117 $pages = $dbw->newSelectQueryBuilder()
118 ->select(
'ss_total_pages' )
119 ->from(
'site_stats' )
120 ->caller( __METHOD__ )->fetchField();
121 $pages -= $n_deleted;
122 $dbw->newUpdateQueryBuilder()
123 ->update(
'site_stats' )
124 ->set( [
'ss_total_pages' => $pages ] )
125 ->where( [
'ss_row_id' => 1 ] )
126 ->caller( __METHOD__ )
131 $this->
output(
"To update the database, run the script with the --delete option.\n" );
138require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
commitTransaction(IDatabase $dbw, $fname)
Commit the transaction on a DB handle and wait for replica DB servers to catch up.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
runChild( $maintClass, $classFile=null)
Returns an instance of the given maintenance script, with all of the current arguments passed to it.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
beginTransaction(IDatabase $dbw, $fname)
Begin a transaction on a DB handle.
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.