2declare( strict_types = 1 );
4namespace MediaWiki\Extension\Translate\MessageGroupProcessing;
7use MediaWiki\Page\PageIdentity;
32 private static $tagCache = [];
36 PageIdentity $identity,
41 if ( !$identity->exists() ) {
45 $articleId = $identity->getId();
47 $dbw = wfGetDB( DB_PRIMARY );
49 'rt_page' => $articleId,
52 $dbw->delete(
'revtag', $conds, __METHOD__ );
54 if ( $value !==
null ) {
55 $conds[
'rt_value'] = serialize( implode(
'|', $value ) );
58 $conds[
'rt_revision'] = $revisionId;
59 $dbw->insert(
'revtag', $conds, __METHOD__ );
61 self::$tagCache[$articleId][$tag] = $revisionId;
64 public function getLatestRevisionWithTag( PageIdentity $identity,
string $tag ): ?int {
65 $response = $this->getLatestRevisionsForTags( $identity, $tag );
66 return $response[$tag] ??
null;
71 if ( !$identity->exists() ) {
75 $articleId = $identity->getId();
81 foreach ( $tags as $tag ) {
82 if ( isset( self::$tagCache[$articleId][$tag] ) ) {
83 $response[$tag] = self::$tagCache[$articleId][$tag];
85 $remainingTags[] = $tag;
89 if ( !$remainingTags ) {
94 $dbr = Utilities::getSafeReadDB();
95 $vars = [
'MAX(rt_revision) AS rt_revision',
'rt_type' ];
97 'rt_page' => $articleId,
98 'rt_type' => $remainingTags
101 $options = [
'GROUP BY' => [
'rt_type' ] ];
102 $results = $dbr->select(
'revtag', $vars, $conds, __METHOD__, $options );
104 foreach ( $results as $row ) {
105 $response[$row->rt_type] = (int)$row->rt_revision;
111 public function removeTags( PageIdentity $identity,
string ...$tag ): void {
112 if ( !$identity->exists() ) {
116 $articleId = $identity->getId();
118 $dbw = wfGetDB( DB_PRIMARY );
120 'rt_page' => $articleId,
123 $dbw->delete(
'revtag', $conds, __METHOD__ );
125 unset( self::$tagCache[$articleId] );
132 $tables = [
'revtag',
'page' ];
136 'rt_revision = page_latest',
137 'rt_type' => $revTags,
139 $options = [
'GROUP BY' =>
'rt_page' ];
141 $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options );
143 foreach ( $res as $row ) {
144 $results[] = (int)$row->rt_page;