jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/403920 )

Change subject: Gradually enable constraints gadget for all users
......................................................................


Gradually enable constraints gadget for all users

Starting 2018-02-28, we enable the constraints gadget for more and more
users (selected by the first character of their user name), until by
2018-04-04 it’s enabled for all (logged in) users.

Bug: T184069
Change-Id: I6265d4557809926e7f031dd76e6dc60e187d2cff
---
M extension.json
M src/WikibaseQualityConstraintsHooks.php
M tests/phpunit/WikibaseQualityConstraintsHooksTest.php
3 files changed, 103 insertions(+), 1 deletion(-)

Approvals:
  Jonas Kress (WMDE): Looks good to me, but someone else must approve
  jenkins-bot: Verified
  Thiemo Kreuz (WMDE): Looks good to me, approved



diff --git a/extension.json b/extension.json
index 7e5c26b..661e407 100644
--- a/extension.json
+++ b/extension.json
@@ -21,7 +21,8 @@
        "Hooks": {
                "LoadExtensionSchemaUpdates": 
"WikibaseQuality\\ConstraintReport\\WikibaseQualityConstraintsHooks::onCreateSchema",
                "WikibaseChangeNotification": 
"WikibaseQuality\\ConstraintReport\\WikibaseQualityConstraintsHooks::onWikibaseChange",
-               "ArticlePurge": 
"WikibaseQuality\\ConstraintReport\\WikibaseQualityConstraintsHooks::onArticlePurge"
+               "ArticlePurge": 
"WikibaseQuality\\ConstraintReport\\WikibaseQualityConstraintsHooks::onArticlePurge",
+               "BeforePageDisplay": 
"WikibaseQuality\\ConstraintReport\\WikibaseQualityConstraintsHooks::onBeforePageDisplay"
        },
        "SpecialPages": {
                "ConstraintReport": 
"WikibaseQuality\\ConstraintReport\\Specials\\SpecialConstraintReport::newFromGlobalState"
diff --git a/src/WikibaseQualityConstraintsHooks.php 
b/src/WikibaseQualityConstraintsHooks.php
index e24a3c8..1dd1de7 100644
--- a/src/WikibaseQualityConstraintsHooks.php
+++ b/src/WikibaseQualityConstraintsHooks.php
@@ -7,6 +7,8 @@
 use JobQueueGroup;
 use JobSpecification;
 use MediaWiki\MediaWikiServices;
+use OutputPage;
+use Skin;
 use Title;
 use Wikibase\Change;
 use Wikibase\DataModel\Entity\PropertyId;
@@ -81,4 +83,59 @@
                }
        }
 
+       /**
+        * @param string $userName
+        * @param int $timestamp UTC timestamp (seconds since the Epoch)
+        * @return bool
+        */
+       public static function isGadgetEnabledForUserName( $userName, 
$timestamp ) {
+               $initial = $userName[0];
+
+               if ( $initial === 'Z' ) {
+                       $firstWeek = 0;
+               } elseif ( $initial >= 'W' && $initial < 'Z' ) {
+                       $firstWeek = 1;
+               } elseif ( $initial >= 'T' && $initial < 'W' ) {
+                       $firstWeek = 2;
+               } elseif ( $initial >= 'N' && $initial < 'T' ) {
+                       $firstWeek = 3;
+               } elseif ( $initial >= 'E' && $initial < 'N' ) {
+                       $firstWeek = 4;
+               } else {
+                       $firstWeek = 5;
+               }
+
+               $threshold = gmmktime(
+                       0, // hour
+                       0, // minute
+                       0, // second
+                       3, // month; overflows to 3 or 4 depending on day
+                       $firstWeek * 7 + 1, // day
+                       2018 // year
+               );
+
+               return $timestamp >= $threshold;
+       }
+
+       public static function onBeforePageDisplay( OutputPage &$out, Skin 
&$skin ) {
+               $repo = WikibaseRepo::getDefaultInstance();
+
+               $lookup = $repo->getEntityNamespaceLookup();
+               $title = $out->getTitle();
+               if ( $title === null ) {
+                       return;
+               }
+
+               if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) {
+                       return;
+               }
+               if ( !$out->getUser()->isLoggedIn() ) {
+                       return;
+               }
+
+               if ( self::isGadgetEnabledForUserName( 
$out->getUser()->getName(), time() ) ) {
+                       $out->addModules( 'wikibase.quality.constraints.gadget' 
);
+               }
+       }
+
 }
diff --git a/tests/phpunit/WikibaseQualityConstraintsHooksTest.php 
b/tests/phpunit/WikibaseQualityConstraintsHooksTest.php
index 4df2606..3dc27f5 100644
--- a/tests/phpunit/WikibaseQualityConstraintsHooksTest.php
+++ b/tests/phpunit/WikibaseQualityConstraintsHooksTest.php
@@ -104,4 +104,48 @@
                yield 'property-copy-constraint' => [ $change, true ];
        }
 
+       /**
+        * @dataProvider isGadgetEnabledForUserNameProvider
+        * @param string $userName
+        * @param int $timestamp
+        * @param bool $expected
+        */
+       public function testIsGadgetEnabledForUserName( $userName, $timestamp, 
$expected ) {
+               $actual = 
WikibaseQualityConstraintsHooks::isGadgetEnabledForUserName(
+                       $userName,
+                       $timestamp
+               );
+
+               $this->assertSame( $expected, $actual );
+       }
+
+       public function isGadgetEnabledForUserNameProvider() {
+               yield 'enabled for no one' => [ 'Z', strtotime( '2018-02-28' ), 
false ];
+               yield 'enabled for Z' => [ 'Z', strtotime( '2018-03-01' ), true 
];
+               yield 'not enabled for Y' => [ 'Y', strtotime( '2018-03-01' ), 
false ];
+               yield 'still not enabled for Y' => [ 'Y', strtotime( 
'2018-03-07' ), false ];
+               yield 'enabled for Y' => [ 'Y', strtotime( '2018-03-08' ), true 
];
+               yield 'enabled for W' => [ 'W', strtotime( '2018-03-08' ), true 
];
+               yield 'not enabled for V' => [ 'V', strtotime( '2018-03-08' ), 
false ];
+               yield 'still not enabled for V' => [ 'V', strtotime( 
'2018-03-14' ), false ];
+               yield 'enabled for V' => [ 'V', strtotime( '2018-03-15' ), true 
];
+               yield 'enabled for T' => [ 'T', strtotime( '2018-03-15' ), true 
];
+               yield 'not enabled for S' => [ 'S', strtotime( '2018-03-15' ), 
false ];
+               yield 'still not enabled for S' => [ 'S', strtotime( 
'2018-03-21' ), false ];
+               yield 'enabled for S' => [ 'S', strtotime( '2018-03-22' ), true 
];
+               yield 'enabled for N' => [ 'N', strtotime( '2018-03-22' ), true 
];
+               yield 'not enabled for M' => [ 'M', strtotime( '2018-03-22' ), 
false ];
+               yield 'still not enabled for M' => [ 'M', strtotime( 
'2018-03-28' ), false ];
+               yield 'enabled for M' => [ 'M', strtotime( '2018-03-29' ), true 
];
+               yield 'enabled for E' => [ 'E', strtotime( '2018-03-29' ), true 
];
+               yield 'not enabled for D' => [ 'D', strtotime( '2018-03-29' ), 
false ];
+               yield 'still not enabled for D' => [ 'D', strtotime( 
'2018-04-04' ), false ];
+               yield 'enabled for D' => [ 'D', strtotime( '2018-04-05' ), true 
];
+               yield 'enabled for A' => [ 'A', strtotime( '2018-04-05' ), true 
];
+               foreach ( [ 'Ω', 'Я', 'א', 'ا' ] as $nonAscii ) {
+                       yield 'not enabled for ' . $nonAscii => [ $nonAscii, 
strtotime( '2018-04-04' ), false ];
+                       yield 'enabled for ' . $nonAscii => [ $nonAscii, 
strtotime( '2018-04-05' ), true ];
+               }
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/403920
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6265d4557809926e7f031dd76e6dc60e187d2cff
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Kreuz (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to