Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fast track deletion for unused wikis #605

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
16 changes: 12 additions & 4 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,18 @@
"CreateWikiStateDays": {
"description": "Array. Integer values in days when a wiki is deemed inactive, closed, removed (hidden) and deleted. Number of days passed since last change - not from initial inactivity.",
"value": {
"inactive": 45,
"closed": 15,
"removed": 120,
"deleted": 7
"no-edits": {
"inactive": 15,
"closed": 30,
"removed": 0,
"deleted": 0
},
"default": {
"inactive": 45,
"closed": 15,
"removed": 120,
"deleted": 7
}
}
},
"CreateWikiSubdomain": {
Expand Down
4 changes: 3 additions & 1 deletion maintenance/checkLastWikiActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ public function execute(): void {
}

private function getTimestamp(): int {
$default_id = $this->getServiceContainer()->getUserFactory->newFromName("MediaWiki default")->getActorId();
$dbr = $this->getReplicaDB();
$timestamp = $dbr->newSelectQueryBuilder()
->select( 'MAX(rc_timestamp)' )
->from( 'recentchanges' )
->where( [
$dbr->expr( 'rc_log_type', '!=', 'renameuser' ),
$dbr->expr( 'rc_log_type', '!=', 'newusers' ),
$dbr->expr( 'rc_actor', '!=', $default_id ),
] )
->caller( __METHOD__ )
->fetchField();

return (int)$timestamp;
return (int)$timestamp; // Evalutes no results as a 0
}
}

Expand Down
14 changes: 8 additions & 6 deletions maintenance/manageInactiveWikisV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function execute(): void {
foreach ( $res as $row ) {
$dbName = $row->wiki_dbname;
$remoteWiki = $remoteWikiFactory->newInstance( $dbName );
$inactiveDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['inactive'];
$inactiveDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['default']['inactive'];

// Check if the wiki is inactive based on creation date
if ( $remoteWiki->getCreationDate() < date( 'YmdHis', strtotime( "-{$inactiveDays} days" ) ) ) {
Expand All @@ -65,11 +65,6 @@ private function checkLastActivity(
string $dbName,
RemoteWikiFactory $remoteWiki
): bool {
$inactiveDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['inactive'];
$closeDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['closed'];
$removeDays = (int)$this->getConfig()->get( ConfigNames::StateDays )['removed'];
$canWrite = $this->hasOption( 'write' );

/** @var CheckLastWikiActivity $activity */
$activity = $this->runChild(
CheckLastWikiActivity::class,
Expand All @@ -83,6 +78,13 @@ private function checkLastActivity(

$lastActivityTimestamp = $activity->timestamp;

$track = ( $lastActivityTimestamp !== 0 ) ? 'default': 'no-edits'

$inactiveDays = (int)$this->getConfig()->get( ConfigNames::StateDays )[$track]['inactive'];
$closeDays = (int)$this->getConfig()->get( ConfigNames::StateDays )[$track]['closed'];
$removeDays = (int)$this->getConfig()->get( ConfigNames::StateDays )[$track]['removed'];
$canWrite = $this->hasOption( 'write' );

// If the wiki is still active, mark it as active
if ( $lastActivityTimestamp > date( 'YmdHis', strtotime( "-{$inactiveDays} days" ) ) ) {
if ( $canWrite && $remoteWiki->isInactive() ) {
Expand Down
Loading