jenkins-bot has submitted this change and it was merged.
Change subject: Filter out retired WikiGrok claims from WikiGrok pages
......................................................................
Filter out retired WikiGrok claims from WikiGrok pages
Claims that are retired after aggregation are removed from the page
questions on next page links update.
Bug: T94445
Change-Id: I019a6118c58c8204a88c3e5e7ca97c428276af43
---
M WikiGrok.php
M includes/Hooks.php
M includes/ResponseStore.php
M includes/ResponseStoreDB.php
4 files changed, 92 insertions(+), 1 deletion(-)
Approvals:
Bmansurov: Looks good to me, approved
Phuedx: Looks good to me, approved
jenkins-bot: Verified
diff --git a/WikiGrok.php b/WikiGrok.php
index 0772714..8d58d3e 100644
--- a/WikiGrok.php
+++ b/WikiGrok.php
@@ -186,6 +186,11 @@
$wgWikiGrokRepoMode = false;
/**
+ * Wiki ID for the repo wiki
+ */
+$wgWikiGrokRepoWikiId = 'wikidatawiki';
+
+/**
* Controls whether the WikiGrok UI is enabled
* For WikiGrok UI to show up CentralAuth needs to be installed too.
*/
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 12dba33..9ebc90e 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -106,6 +106,8 @@
$campaigns = new QuestionPicker( self::getConfig() );
$data = $campaigns->getSlowQuestions( $parserOutput );
+ $data = self::filterRetiredClaims( $parserOutput->getProperty(
'wikibase_item' ), $data );
+
$store = new QuestionStore();
$store->store( $lu->getTitle(), $data );
$cache = new QuestionCache( self::getConfig() );
@@ -174,6 +176,39 @@
return $prop;
}
+ /**
+ * Remove retired claims from campaigns.
+ * @param string $item
+ * @param array $claims An array of claims in the following form:
+ * array(
+ * 'actor' => array(
+ * 'questions' => array( 'Q10798782' =>
'television actor' ),
+ * propertyId: 31,
+ * ...
+ * )
+ * )
+ * @returns array $claims
+ */
+ private static function filterRetiredClaims( $item, $claims ) {
+ $config = self::getConfig();
+ if ( $item && $claims ) {
+ $campaigns = array();
+ foreach ( $claims as $campaign => $data ) {
+ $campaigns[$campaign] = $data['propertyId'];
+ }
+ $responseStore = new ResponseStoreDB( $config->get(
'WikiGrokRepoWikiId' ));
+ $retiredClaims = $responseStore->getRetiredClaims(
$item, $campaigns );
+ foreach ( $retiredClaims as $campaign =>
$retiredQuestions ) {
+ foreach ( $retiredQuestions as $retiredQuestion
) {
+ if ( isset(
$claims[$campaign]['questions'][$retiredQuestion] ) ) {
+ unset(
$claims[$campaign]['questions'][$retiredQuestion] );
+ }
+ }
+ }
+ }
+ return $claims;
+ }
+
public static function getConfig() {
return ConfigFactory::getDefaultInstance()->makeConfig(
'wikigrok' );
}
diff --git a/includes/ResponseStore.php b/includes/ResponseStore.php
index 181fa51..5021a96 100644
--- a/includes/ResponseStore.php
+++ b/includes/ResponseStore.php
@@ -23,4 +23,15 @@
* @param Claim[] $claims Array of status => Claim[]
*/
abstract public function updateClaimStatus( array $claims );
+
+ /**
+ * Gets claims for a set of WikiGrok campaigns that are not 'new'.
+ *
+ * @param string $item WikiData Q ID
+ * @param array $campaigns In the following form:
+ * array( 'author' => '31', ... ) where 31 is the property ID
+ * @return array An array of claims in the following form:
+ * array( 'author' => array( 'Q123', 'Q456'), 'actor' => array(
'Q555', 'Q843' ) )
+ */
+ abstract public function getRetiredClaims( $item, array $campaigns );
}
diff --git a/includes/ResponseStoreDB.php b/includes/ResponseStoreDB.php
index 0635e6a..bd9a2ba 100644
--- a/includes/ResponseStoreDB.php
+++ b/includes/ResponseStoreDB.php
@@ -39,11 +39,20 @@
);
/**
+ * Constructor
+ *
+ * @param string|bool $wiki Wiki ID. Defaults to false
+ */
+ public function __construct( $wiki = false ) {
+ $this->wiki = $wiki;
+ }
+
+ /**
* @param int $type
* @return DatabaseBase
*/
protected function getDB( $type ) {
- return wfGetDB( $type );
+ return wfGetDB( $type, array(), $this->wiki );
}
/**
@@ -183,6 +192,37 @@
}
/**
+ * @inheritdoc
+ */
+ public function getRetiredClaims( $item, array $campaigns ) {
+ $retiredClaims = array();
+ $numericId = (int)preg_replace( '/^[Qq]/', '', $item );
+ if ( $numericId ) {
+ $dbw = $this->getDB( DB_SLAVE );
+ $res = $dbw->select( 'wikigrok_claims',
+ array(
+ 'wgc_campaign,
+ wgc_data'
+ ),
+ array(
+ 'wgc_item' => $numericId,
+ 'wgc_campaign' => array_keys(
$campaigns ),
+ 'wgc_status <> \'new\''
+ ),
+ __METHOD__,
+ array( 'GROUP BY' => 'wgc_hash' )
+ );
+ foreach ( $res as $row ) {
+ $claim = $this->rowToClaim( $row );
+ if ( 'P' . $claim->property ==
$campaigns[$claim->campaign] ) {
+ $retiredClaims[$claim->campaign][] =
'Q' . $claim->value;
+ }
+ }
+ }
+ return $retiredClaims;
+ }
+
+ /**
* Determines which existing claims need responses added
*
* @param DatabaseBase $dbw
--
To view, visit https://gerrit.wikimedia.org/r/201071
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I019a6118c58c8204a88c3e5e7ca97c428276af43
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/WikiGrok
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits