Editcount: support the actor table

Add support for the actor table and the temporary actor revision table.

Bug: T240893
Change-Id: I1db8cb74d808093a357af0f430f7d4b9d43e50b8
This commit is contained in:
Ostrzyciel 2019-12-17 17:22:42 +01:00
parent ec48059187
commit 13a0a67ea6

View file

@ -31,11 +31,11 @@ class Editcount extends IncludableSpecialPage {
$out = ''; $out = '';
} }
} else { } else {
$out = $contLang->formatNum( $this->editsInNs( $uid, $namespace ) ); $out = $contLang->formatNum( $this->editsInNs( $user, $namespace ) );
} }
$this->getOutput()->addHTML( $out ); $this->getOutput()->addHTML( $out );
} else { } else {
$nscount = $this->editsByNs( $uid ); $nscount = $this->editsByNs( $user );
$html = new EditcountHTML; $html = new EditcountHTML;
$html->setContext( $this->getContext() ); $html->setContext( $this->getContext() );
$html->outputHTML( $username, $uid, $nscount ); $html->outputHTML( $username, $uid, $nscount );
@ -59,25 +59,23 @@ class Editcount extends IncludableSpecialPage {
/** /**
* Count the number of edits of a user by namespace * Count the number of edits of a user by namespace
* *
* @param int $uid The user ID to check * @param User $user The user to check
* @return int[] * @return int[]
*/ */
protected function editsByNs( $uid ) { protected function editsByNs( $user ) {
if ( $uid <= 0 ) { if ( !$user || $user->getId() <= 0 ) {
return []; return [];
} }
$dbr = wfGetDB( DB_REPLICA ); $dbr = wfGetDB( DB_REPLICA );
$actorWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $user );
$res = $dbr->select( $res = $dbr->select(
[ 'user', 'revision', 'page' ], [ 'revision', 'page' ] + $actorWhere['tables'],
[ 'page_namespace', 'COUNT(*) AS count' ], [ 'page_namespace', 'COUNT(*) AS count' ],
[ [ $actorWhere['conds'] ],
'user_id' => $uid,
'rev_user = user_id',
'rev_page = page_id'
],
__METHOD__, __METHOD__,
[ 'GROUP BY' => 'page_namespace' ] [ 'GROUP BY' => 'page_namespace' ],
[ 'page' => [ 'JOIN', 'page.page_id = rev_page' ] ] + $actorWhere['joins']
); );
$nscount = []; $nscount = [];
@ -90,27 +88,24 @@ class Editcount extends IncludableSpecialPage {
/** /**
* Count the number of edits of a user in a given namespace * Count the number of edits of a user in a given namespace
* *
* @param int $uid The user ID to check * @param User $user The user to check
* @param int $ns The namespace to check * @param int $ns The namespace to check
* @return int * @return int
*/ */
protected function editsInNs( $uid, $ns ) { protected function editsInNs( $user, $ns ) {
if ( $uid <= 0 ) { if ( !$user || $user->getId() <= 0 ) {
return 0; return 0;
} }
$dbr = wfGetDB( DB_REPLICA ); $dbr = wfGetDB( DB_REPLICA );
$actorWhere = ActorMigration::newMigration()->getWhere( $dbr, 'rev_user', $user );
return (int)$dbr->selectField( return (int)$dbr->selectField(
[ 'user', 'revision', 'page' ], [ 'revision', 'page' ] + $actorWhere['tables'],
[ 'COUNT(*) AS count' ], 'COUNT(*)',
[ [ 'page_namespace' => $ns, $actorWhere['conds'] ],
'user_id' => $uid,
'page_namespace' => $ns,
'rev_user = user_id',
'rev_page = page_id'
],
__METHOD__, __METHOD__,
[ 'GROUP BY' => 'page_namespace' ] [],
[ 'page' => [ 'JOIN', 'page.page_id = rev_page' ] ] + $actorWhere['joins']
); );
} }
} }