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 @@ -383,10 +383,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
9 changes: 9 additions & 0 deletions maintenance/checkLastWikiActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ public function execute(): void {
}

public function getTimestamp(): int {
$defaultActor = $this->getServiceContainer()
->getUserFactory()
->newFromName( 'MediaWiki default' )
->getActorId();

$dbr = $this->getDB( DB_REPLICA );

// Get the latest revision timestamp
$revTimestamp = $dbr->newSelectQueryBuilder()
->select( 'MAX(rev_timestamp)' )
->from( 'revision' )
->where( [
$dbr->expr( 'rev_actor', '!=', $defaultActor ),
] )
->caller( __METHOD__ )
->fetchField();

Expand All @@ -39,6 +47,7 @@ public function getTimestamp(): int {
->where( [
$dbr->expr( 'log_type', '!=', 'renameuser' ),
$dbr->expr( 'log_type', '!=', 'newusers' ),
$dbr->expr( 'log_actor', '!=', $defaultActor ),
] )
->caller( __METHOD__ )
->fetchField();
Expand Down
15 changes: 9 additions & 6 deletions maintenance/manageInactiveWikis.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ 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 )['no-edits']['inactive'];


// Check if the wiki is inactive based on creation date
if ( $remoteWiki->getCreationDate() < date( 'YmdHis', strtotime( "-{$inactiveDays} days" ) ) ) {
Expand All @@ -65,11 +66,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 +79,13 @@ private function checkLastActivity(

$lastActivityTimestamp = $activity->getTimestamp();

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary parentheses and syntax error. (missing semicolon)

$track = $lastActivityTimestamp ? 'default' : 'no-edits';

Also we need some validation here if configured incorrectly. If no-edits is not set at all, always use default, if neither is not set use the old behavior and add null checks with ??. Maybe this should be split to seperate method? I guess we could just throw ConfigException if configured incorrectly also...


$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