Lucas Werkmeister (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/389774 )

Change subject: Add staleness indication to CheckResult and API
......................................................................

Add staleness indication to CheckResult and API

A CheckResult may be marked as “stale” (potentially outdated), and the
API indicates this by adding a `stale` property (set to true) for stale
results in the API output. API clients, including the gadget, can check
this property to see if they should indicate staleness to the user.

Note that if using JSON version 1 of the API (the default), MediaWiki
rewrites the boolean `true` to an empty string, which is falsy in
JavaScript. See [1] for more details.

UniqueValueChecker unconditionally marks its result as stale. This is
just a temporary measure so that this change can be tested manually – a
later change will improve this to only mark the result stale if the
SPARQL query result was cached (fixing T170672).

[1]: https://www.mediawiki.org/wiki/API:JSON_version_2

Bug: T179844
Change-Id: I56b4cb01d8db6e9fb74e00e1128de74b9ea8794d
---
M api/CheckConstraints.php
M includes/ConstraintCheck/Checker/UniqueValueChecker.php
M includes/ConstraintCheck/Result/CheckResult.php
3 files changed, 32 insertions(+), 1 deletion(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
 refs/changes/74/389774/1

diff --git a/api/CheckConstraints.php b/api/CheckConstraints.php
index bed10bd..2669e63 100644
--- a/api/CheckConstraints.php
+++ b/api/CheckConstraints.php
@@ -372,6 +372,9 @@
                                if ( $checkResult->getContext()->getType() === 
Context::TYPE_STATEMENT ) {
                                        $result['claim'] = 
$checkResult->getContext()->getSnakStatement()->getGuid();
                                }
+                               if ( $checkResult->getStale() ) {
+                                       $result['stale'] = true;
+                               }
                        }
 
                        $checkResult->getContext()->storeCheckResultInArray( 
$result, $constraintReport );
diff --git a/includes/ConstraintCheck/Checker/UniqueValueChecker.php 
b/includes/ConstraintCheck/Checker/UniqueValueChecker.php
index 0cc8a00..908b9d2 100644
--- a/includes/ConstraintCheck/Checker/UniqueValueChecker.php
+++ b/includes/ConstraintCheck/Checker/UniqueValueChecker.php
@@ -93,7 +93,8 @@
                                         ->escaped();
                }
 
-               return new CheckResult( $context, $constraint, $parameters, 
$status, $message );
+               return ( new CheckResult( $context, $constraint, $parameters, 
$status, $message ) )
+                       ->makeStale();
        }
 
        public function checkConstraintParameters( Constraint $constraint ) {
diff --git a/includes/ConstraintCheck/Result/CheckResult.php 
b/includes/ConstraintCheck/Result/CheckResult.php
index 04b993f..7409556 100644
--- a/includes/ConstraintCheck/Result/CheckResult.php
+++ b/includes/ConstraintCheck/Result/CheckResult.php
@@ -90,6 +90,11 @@
        private $message;
 
        /**
+        * @var bool true if this result may be stale
+        */
+       private $stale;
+
+       /**
         * @param Context $context
         * @param Constraint $constraint
         * @param array[] $parameters (string => string[]) parsed constraint 
parameters
@@ -109,6 +114,7 @@
                $this->parameters = $parameters;
                $this->status = $status;
                $this->message = $message;
+               $this->stale = false;
        }
 
        /**
@@ -196,4 +202,25 @@
                return $this->message;
        }
 
+       /**
+        * Whether this result is potentially stale or guaranteed to be fresh.
+        * A check result is initially fresh,
+        * but may be marked as potentially stale by calling {@see 
CheckResult::makeStale()}.
+        *
+        * @return bool
+        */
+       public function getStale() {
+               return $this->stale;
+       }
+
+       /**
+        * Mark this result as potentially stale.
+        *
+        * @return self
+        */
+       public function makeStale() {
+               $this->stale = true;
+               return $this;
+       }
+
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I56b4cb01d8db6e9fb74e00e1128de74b9ea8794d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>

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

Reply via email to