Skip to content

Commit d7c472a

Browse files
neslihanturanjenkins-bot
authored andcommitted
Implement visual changes behind a feature flag.
When the setting is turned to true, Wikidata item updates reflected to Wikipedia Recent Changes due to Entity Usage will have an icon next to it according to the message content. Bug: T397258 Change-Id: Ief19f0c108364cc8bc6efe581a4262d8de9721ad
1 parent 1e5c364 commit d7c472a

File tree

8 files changed

+131
-8
lines changed

8 files changed

+131
-8
lines changed

client/config/WikibaseClient.default.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@
156156
* @see https://phabricator.wikimedia.org/T312097
157157
*/
158158
'enableMulLanguageCode' => false,
159+
160+
/**
161+
* @var bool Whether to enable the icons for changes coming from Wikibase displayed in Recent Changes (T397258)
162+
*/
163+
'enableWikidataIconsInClientWatchlist' => false,
159164
];
160165

161166
// Some defaults depend on information not available at this time.

client/includes/Hooks/FormatAutocommentsHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use MediaWiki\Hook\FormatAutocommentsHook;
88
use MediaWiki\Language\Language;
9+
use Wikibase\Client\WikibaseClient;
910
use Wikibase\Lib\Formatters\AutoCommentFormatter;
1011
use Wikibase\Lib\SettingsArray;
1112

@@ -51,7 +52,8 @@ public function onFormatAutocomments( &$comment, $pre, $auto, $post, $title, $lo
5152

5253
$formatter = new AutoCommentFormatter(
5354
$this->contentLanguage,
54-
[ 'wikibase-entity' ]
55+
[ 'wikibase-entity' ],
56+
WikibaseClient::getSettings()->getSetting( 'enableWikidataIconsInClientWatchlist' )
5557
);
5658
$formattedComment = $formatter->formatAutoComment( $auto );
5759

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
"wikibase-entity-summary-wbsetitem": "add",
3+
"wikibase-entity-summary-wbcreate-new": "add",
4+
"wikibase-entity-summary-wbcreateredirect": "update",
5+
"wikibase-entity-summary-wbeditentity": "add",
6+
"wikibase-entity-summary-wbeditentity-create": "add",
7+
"wikibase-entity-summary-wbeditentity-update": "update",
8+
"wikibase-entity-summary-wbeditentity-override": "update",
9+
"wikibase-entity-summary-wbeditentity-update-languages": "update",
10+
"wikibase-entity-summary-wbeditentity-update-languages-short": "update",
11+
"wikibase-entity-summary-wbeditentity-update-languages-and-other": "update",
12+
"wikibase-entity-summary-wbeditentity-update-languages-and-other-short": "update",
13+
"wikibase-entity-summary-wbsetreference": "update",
14+
"wikibase-entity-summary-wbsetreference-add": "add",
15+
"wikibase-entity-summary-wbsetreference-set": "update",
16+
"wikibase-entity-summary-wbsetlabel-add": "add",
17+
"wikibase-entity-summary-wbsetlabel-set": "update",
18+
"wikibase-entity-summary-wbsetlabel-remove": "subtract",
19+
"wikibase-entity-summary-wbsetdescription-add": "add",
20+
"wikibase-entity-summary-wbsetdescription-set": "update",
21+
"wikibase-entity-summary-wbsetdescription-remove": "subtract",
22+
"wikibase-entity-summary-wbsetaliases-set": "update",
23+
"wikibase-entity-summary-wbsetaliases-add-remove": "update",
24+
"wikibase-entity-summary-wbsetaliases-add": "add",
25+
"wikibase-entity-summary-wbsetaliases-remove": "subtract",
26+
"wikibase-entity-summary-wbsetaliases-update": "update",
27+
"wikibase-entity-summary-wbsetlabeldescriptionaliases": "update",
28+
"wikibase-entity-summary-wbsetsitelink-add": "add",
29+
"wikibase-entity-summary-wbsetsitelink-add-both": "add",
30+
"wikibase-entity-summary-wbsetsitelink-set": "update",
31+
"wikibase-entity-summary-wbsetsitelink-set-badges": "update",
32+
"wikibase-entity-summary-wbsetsitelink-set-both": "update",
33+
"wikibase-entity-summary-wbsetsitelink-remove": "subtract",
34+
"wikibase-entity-summary-wblinktitles-create": "add",
35+
"wikibase-entity-summary-wblinktitles-connect": "update",
36+
"wikibase-entity-summary-wbcreateclaim-value": "add",
37+
"wikibase-entity-summary-wbcreateclaim-novalue": "add",
38+
"wikibase-entity-summary-wbcreateclaim-somevalue": "add",
39+
"wikibase-entity-summary-wbcreateclaim": "add",
40+
"wikibase-entity-summary-wbsetclaimvalue": "update",
41+
"wikibase-entity-summary-wbremoveclaims": "update",
42+
"wikibase-entity-summary-wbremoveclaims-remove": "subtract",
43+
"wikibase-entity-summary-wbremoveclaims-update": "update",
44+
"wikibase-entity-summary-special-create-item": "add",
45+
"wikibase-entity-summary-wbcreateclaim-create": "add",
46+
"wikibase-entity-summary-wbsetclaim-update": "update",
47+
"wikibase-entity-summary-wbsetclaim-create": "add",
48+
"wikibase-entity-summary-wbsetclaim-update-qualifiers": "update",
49+
"wikibase-entity-summary-wbsetclaim-update-references": "update",
50+
"wikibase-entity-summary-wbsetclaim-update-rank": "update",
51+
"wikibase-entity-summary-clientsitelink-update": "update",
52+
"wikibase-entity-summary-clientsitelink-remove": "subtract",
53+
"wikibase-entity-summary-wbsetqualifier-add": "add",
54+
"wikibase-entity-summary-wbsetqualifier-update": "update",
55+
"wikibase-entity-summary-wbremovequalifiers-remove": "subtract",
56+
"wikibase-entity-summary-wbremovequalifiers-update": "update",
57+
"wikibase-entity-summary-wbremovereferences-remove": "subtract",
58+
"wikibase-entity-summary-wbremovereferences-update": "update",
59+
"wikibase-entity-summary-wbmergeitems-from": "merge",
60+
"wikibase-entity-summary-wbmergeitems-to": "merge",
61+
"wikibase-item-summary-wbcreate-new": "add",
62+
"wikibase-item-summary-wbeditentity": "add",
63+
"wikibase-item-summary-wbeditentity-create": "add",
64+
"wikibase-item-summary-wbeditentity-create-item": "add",
65+
"wikibase-item-summary-wbeditentity-update": "update",
66+
"wikibase-item-summary-wbeditentity-override": "update",
67+
"wikibase-item-summary-wblinktitles-create": "add",
68+
"wikibase-item-summary-wblinktitles-connect": "update",
69+
"wikibase-property-summary-wbcreate-new": "add",
70+
"wikibase-property-summary-wbeditentity-create": "add",
71+
"wikibase-property-summary-wbeditentity-create-property": "add",
72+
"wikibase-property-summary-wbeditentity-update": "update",
73+
"wikibase-property-summary-wbeditentity-override": "update",
74+
"wikibase-property-summary-special-create-property": "add"
75+
}

client/tests/phpunit/integration/includes/RecentChanges/ChangeLineFormatterTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class ChangeLineFormatterTest extends MediaWikiLangTestCase {
4646
protected function setUp(): void {
4747
parent::setUp();
4848

49+
$clientSettings = clone WikibaseClient::getSettings();
50+
$clientSettings->setSetting( 'enableWikidataIconsInClientWatchlist', true );
51+
$this->setService( 'WikibaseClient.Settings', $clientSettings );
52+
4953
// these are required because MediaWiki\CommentFormatter\CommentFormatter is used in ChangeLineFormatter
5054
// @todo eliminate Linker or at least use of Linker in Wikibase :)
5155
$this->overrideConfigValues( [
@@ -410,7 +414,7 @@ public static function getEditSiteLinkPatterns() {
410414
'/title=Special%3AEntityPage%2FQ4&curid=5&action=history/',
411415
'/title=Special%3AEntityPage%2FQ4&curid=5&diff=92&oldid=90/',
412416
'/<span class="comment">\('
413-
. '‎<span dir="auto"><span class="autocomment">Changed claim: <\/span><\/span> '
417+
. '‎<span dir="auto"><span class="autocomment"><i class="mw-update-icon"><\/i>Changed claim: <\/span><\/span> '
414418
. '<a .*?>Property:P213<\/a>: <a .*?>Q850<\/a>'
415419
. '\)<\/span>/',
416420
];

lib/includes/Formatters/AutoCommentFormatter.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Wikibase\Lib\Formatters;
44

5+
use MediaWiki\Html\Html;
56
use MediaWiki\Language\Language;
67
use MediaWiki\Message\Message;
78

@@ -23,6 +24,12 @@ class AutoCommentFormatter {
2324
private $messagePrefixes;
2425

2526
/**
27+
* @var bool Feature flag to turn icons for Wikibase changes displayed on
28+
* client Recent Change page on for some wikis temporarily (T397258)
29+
*/
30+
private $enableWikidataIconsInClientWatchlist;
31+
/**
32+
* /**
2633
* Local message lookup cache. The number of summary messages is limited,
2734
* so this shouldn't grow beyond a few dozen entries.
2835
*
@@ -35,10 +42,13 @@ class AutoCommentFormatter {
3542
* @param string[] $messagePrefixes Prefixes to try when constructing the message key from
3643
* the name given in the autocomment block. Typically something like
3744
* [ 'wikibase-item', 'wikibase-entity' ].
45+
* @param bool $enableWikidataIconsInClientWatchlist Feature flag to turn icons for Wikibase
46+
* changes displayed on client Recent Change page on for some wikis temporarily (T397258)
3847
*/
39-
public function __construct( Language $language, array $messagePrefixes ) {
48+
public function __construct( Language $language, array $messagePrefixes, bool $enableWikidataIconsInClientWatchlist ) {
4049
$this->language = $language;
4150
$this->messagePrefixes = $messagePrefixes;
51+
$this->enableWikidataIconsInClientWatchlist = $enableWikidataIconsInClientWatchlist;
4252
}
4353

4454
/**
@@ -98,6 +108,7 @@ public function formatAutoComment( $auto ) {
98108
return null;
99109
}
100110

111+
$icon = $this->enableWikidataIconsInClientWatchlist ? $this->decideIconForTheKey( $msg->getKey() ) : '';
101112
$args = array_map( function ( $arg ) {
102113
// MediaWiki HTML-escaped the auto-comment already,
103114
// undo that, then wikitext-escape the args for the message
@@ -107,7 +118,7 @@ public function formatAutoComment( $auto ) {
107118
}, $args );
108119
// render the autocomment
109120
$auto = $msg->params( $args )->parse();
110-
return $auto;
121+
return $icon . $auto;
111122
}
112123

113124
/**
@@ -139,4 +150,15 @@ public function wrapAutoComment( $pre, $comment, $post ) {
139150
return $comment;
140151
}
141152

153+
/**
154+
* @param string $key for Wikibase change
155+
* @return string proper icon in proper styling
156+
*/
157+
public function decideIconForTheKey( $key ): string {
158+
$iconMap = json_decode( file_get_contents( __DIR__ . '/../../../client/resources/jsons/wb.icon.key.map.json' ), true );
159+
if ( !isset( $iconMap[$key] ) ) {
160+
return ''; //given key is not found then no icon will be displayed
161+
}
162+
return Html::rawElement( 'i', [ 'class' => 'mw-' . $iconMap[$key] . '-icon' ] );
163+
}
142164
}

lib/tests/phpunit/Formatters/AutoCommentFormatterTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public static function provideTestAutoComment() {
4141
'wbsetitem',
4242
'(wikibase-item-summary-wbsetitem)',
4343
],
44+
'Existing message with no params and with entity' => [
45+
[ 'wikibase-entity' ],
46+
'wbeditentity',
47+
'<i class="mw-add-icon"></i>(wikibase-entity-summary-wbeditentity)',
48+
],
4449
'Existing message with 1 parameter' => [
4550
[ 'wikibase-item', 'wikibase-entity' ],
4651
'wbsetlabel-add:|FOO',
@@ -49,7 +54,7 @@ public static function provideTestAutoComment() {
4954
'Existing message with 2 parameters' => [
5055
[ 'wikibase-entity' ],
5156
'wbsetaliases-set:10|FOO',
52-
'(wikibase-entity-summary-wbsetaliases-set: 10, FOO)',
57+
'<i class="mw-update-icon"></i>(wikibase-entity-summary-wbsetaliases-set: 10, FOO)',
5358
],
5459
];
5560
}
@@ -60,7 +65,7 @@ public static function provideTestAutoComment() {
6065
public function testFormatAutoComment( array $prefixes, $auto, $expected ) {
6166
// If the Translate extension is installed, its handler for ParserBeforeInternalParse can trigger DB access
6267
$this->clearHook( 'ParserBeforeInternalParse' );
63-
$formatter = new AutoCommentFormatter( $this->language, $prefixes );
68+
$formatter = new AutoCommentFormatter( $this->language, $prefixes, true );
6469
$value = $formatter->formatAutoComment( $auto );
6570
$this->assertEquals( $expected, $value );
6671
}
@@ -108,7 +113,7 @@ public static function provideWrapAutoComment() {
108113
* @dataProvider provideWrapAutoComment
109114
*/
110115
public function testWrapAutoComment( $pre, $comment, $post, $expected ) {
111-
$formatter = new AutoCommentFormatter( $this->language, [] );
116+
$formatter = new AutoCommentFormatter( $this->language, [], true );
112117
$value = $formatter->wrapAutoComment( $pre, $comment, $post );
113118
$this->assertEquals( $expected, $value );
114119
}

repo/config/Wikibase.default.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,4 +488,9 @@
488488
* @see https://phabricator.wikimedia.org/T404842
489489
*/
490490
'tmpEnableGraphQL' => false,
491+
492+
/**
493+
* @var bool Whether to enable the icons for changes coming from Wikibase displayed in Recent Changes (T397258)
494+
*/
495+
'enableWikidataIconsInClientWatchlist' => false,
491496
];

repo/includes/RepoHooks.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,12 @@ public function onFormatAutocomments( &$comment, $pre, $auto, $post, $title, $lo
684684
StubUserLang::unstub( $wgLang );
685685
}
686686

687-
$formatter = new AutoCommentFormatter( $wgLang, [ 'wikibase-' . $entityType, 'wikibase-entity' ] );
687+
$enableWikidataIconsInClientWatchlist = WikibaseRepo::getSettings()->getSetting( 'enableWikidataIconsInClientWatchlist' );
688+
$formatter = new AutoCommentFormatter(
689+
$wgLang,
690+
[ 'wikibase-' . $entityType, 'wikibase-entity' ],
691+
$enableWikidataIconsInClientWatchlist
692+
);
688693
$formattedComment = $formatter->formatAutoComment( $auto );
689694

690695
if ( is_string( $formattedComment ) ) {

0 commit comments

Comments
 (0)