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 if ( !$identity->exists() ) {
69 $articleId = $identity->getId();
72 if ( isset( self::$tagCache[$articleId][$tag] ) ) {
73 return self::$tagCache[$articleId][$tag];
76 $db = wfGetDB( DB_REPLICA );
78 'rt_page' => $articleId,
82 $options = [
'ORDER BY' =>
'rt_revision DESC' ];
83 $value = $db->selectField(
'revtag',
'rt_revision', $conds, __METHOD__, $options );
85 return $value ===
false ? null : (int)$value;
88 public function removeTags( PageIdentity $identity,
string ...$tag ): void {
89 if ( !$identity->exists() ) {
93 $articleId = $identity->getId();
95 $dbw = wfGetDB( DB_PRIMARY );
97 'rt_page' => $articleId,
100 $dbw->delete(
'revtag', $conds, __METHOD__ );
102 unset( self::$tagCache[$articleId] );
109 $tables = [
'revtag',
'page' ];
113 'rt_revision = page_latest',
114 'rt_type' => $revTags,
116 $options = [
'GROUP BY' =>
'rt_page' ];
118 $res = $dbr->select( $tables, $fields, $conds, __METHOD__, $options );
120 foreach ( $res as $row ) {
121 $results[] = (int)$row->rt_page;