Editcount: Migrate to fluent style query

Change-Id: Ica309a5986aed42b04c5150d45376c629df01ac6
This commit is contained in:
NekoCharm 2023-12-13 00:07:46 +08:00 committed by Winston Sung
parent b7b699d9ac
commit 116bf43c5a
2 changed files with 27 additions and 24 deletions

View file

@ -9,7 +9,7 @@
"license-name": "GPL-2.0-or-later",
"type": "specialpage",
"requires": {
"MediaWiki": ">= 1.32.0"
"MediaWiki": ">= 1.36.0"
},
"SpecialPages": {
"Editcount": "Editcount"

View file

@ -69,22 +69,24 @@ class Editcount extends IncludableSpecialPage {
return [];
}
$dbr = wfGetDB( DB_REPLICA );
$actorWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $user );
$res = $dbr->select(
[ 'revision', 'page' ] + $actorWhere['tables'],
[ 'page_namespace', 'COUNT(*) AS count' ],
[ $actorWhere['conds'] ],
__METHOD__,
[ 'GROUP BY' => 'page_namespace' ],
[ 'page' => [ 'JOIN', 'page_id = rev_page' ] ] + $actorWhere['joins']
);
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getReplicaDatabase();
$actorNormalization = MediaWikiServices::getInstance()->getActorNormalization();
$actorId = $actorNormalization->findActorId( $user, $dbr );
$query = $dbr->newSelectQueryBuilder()
->caller( __METHOD__ )
->select( [ 'page_namespace', 'count' => 'COUNT(*)' ] )
->from( 'revision' )
->join( 'page', null, 'page_id = rev_page' )
->join( 'actor', null, 'rev_actor = actor_id' )
->where( [ "actor_id" => $actorId ] )
->groupBy( 'page_namespace' );
$res = $query->fetchResultSet();
$nscount = [];
$nsCount = [];
foreach ( $res as $row ) {
$nscount[$row->page_namespace] = (int)$row->count;
$nsCount[$row->page_namespace] = (int)$row->count;
}
return $nscount;
return $nsCount;
}
/**
@ -99,15 +101,16 @@ class Editcount extends IncludableSpecialPage {
return 0;
}
$dbr = wfGetDB( DB_REPLICA );
$actorWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $user );
return (int)$dbr->selectField(
[ 'revision', 'page' ] + $actorWhere['tables'],
'COUNT(*)',
[ 'page_namespace' => $ns, $actorWhere['conds'] ],
__METHOD__,
[],
[ 'page' => [ 'JOIN', 'page_id = rev_page' ] ] + $actorWhere['joins']
);
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getReplicaDatabase();
$actorNormalization = MediaWikiServices::getInstance()->getActorNormalization();
$actorId = $actorNormalization->findActorId( $user, $dbr );
$query = $dbr->newSelectQueryBuilder()
->caller( __METHOD__ )
->select( 'COUNT(*)' )
->from( 'revision' )
->join( 'page', null, 'page_id = rev_page' )
->join( 'actor', null, 'rev_actor = actor_id' )
->where( [ "actor_id" => $actorId, "page_namespace" => $ns ] );
return $query->fetchField();
}
}