Skip to content

Commit 0f16a3f

Browse files
Neslihan Turanjenkins-bot
authored andcommitted
Revert "Implement new usage types for statement with qualifiers and references"
This reverts commit 7206433. Reason for revert: <T407744 seems like caused by this> This patch temporary fixes the CQR aspects not found error as well which will be patched asap. Bug: T401290 Bug: T407684 Bug: T407744 Change-Id: I3709641e75ed2476bec62881659b43509eb195ce
1 parent c002e66 commit 0f16a3f

File tree

17 files changed

+39
-437
lines changed

17 files changed

+39
-437
lines changed

client/includes/Changes/AffectedPagesFinder.php

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,9 @@ public function getChangedAspects( EntityChange $change ) {
141141
$aspects = array_merge( $aspects, $aliasAspects );
142142
}
143143

144-
// If a statement mainsnak changes, we need to tell any pages which have STATEMENT_USAGE or STATEMENT_WITH_QUAL_OR_REF_USAGE
145-
// This is regardless of whether it also includes a reference/qualifer change, in addition to the mainSnak change
146-
if ( $diffAspects->getStatementChangesExcludingQualOrRefOnly() !== [] ) {
147-
$statementAspects = $this->getChangedStatementAspects( //tells STATEMENT_USAGE and STATEMENT_WITH_QUAL_OR_REF_USAGE
148-
$diffAspects->getStatementChangesExcludingQualOrRefOnly()
149-
);
150-
$aspects = array_merge( $aspects, $statementAspects );
151-
}
152-
153-
// If it is a qualifer or ref only change (no mainsnak change), we don't need to tell those with STATEMENT_USAGE, but those with
154-
// STATEMENT_WITH_QUAL_OR_REF_USAGE
155-
if ( $diffAspects->getStatementChangesQualOrRefOnly() !== [] ) {
156-
$statementAspects = $this->getChangedStatementAspectsQualOrRefOnlyChange( //only tells STATEMENT_WITH_QUAL_OR_REF_USAGE
157-
$diffAspects->getStatementChangesQualOrRefOnly()
144+
if ( $diffAspects->getStatementChanges() !== [] ) {
145+
$statementAspects = $this->getChangedStatementAspects(
146+
$diffAspects->getStatementChanges()
158147
);
159148
$aspects = array_merge( $aspects, $statementAspects );
160149
}
@@ -175,39 +164,15 @@ public function getChangedAspects( EntityChange $change ) {
175164
* @param string[] $diff
176165
*
177166
* @return string[]
178-
*
179-
* If a statement changes, we need to tell any pages which have STATEMENT_USAGE or STATEMENT_WITH_QUAL_OR_REF_USAGE
180167
*/
181168
private function getChangedStatementAspects( array $diff ) {
182169
$aspects = [];
183170

184171
foreach ( $diff as $propertyId ) {
185172
$aspects[] = EntityUsage::makeAspectKey( EntityUsage::STATEMENT_USAGE, $propertyId );
186-
$aspects[] = EntityUsage::makeAspectKey( EntityUsage::STATEMENT_WITH_QUAL_OR_REF_USAGE, $propertyId );
187173
}
188174

189175
$aspects[] = EntityUsage::makeAspectKey( EntityUsage::STATEMENT_USAGE );
190-
$aspects[] = EntityUsage::makeAspectKey( EntityUsage::STATEMENT_WITH_QUAL_OR_REF_USAGE );
191-
192-
return $aspects;
193-
}
194-
195-
/**
196-
* @param string[] $diff
197-
*
198-
* @return string[]
199-
*
200-
* If any statement's qual/ref changes, we need to tell any pages which have STATEMENT_WITH_QUAL_OR_REF_USAGE,
201-
* but do not need to tell those with STATEMENT_USAGE
202-
*/
203-
private function getChangedStatementAspectsQualOrRefOnlyChange( array $diff ) {
204-
$aspects = [];
205-
206-
foreach ( $diff as $propertyId ) {
207-
$aspects[] = EntityUsage::makeAspectKey( EntityUsage::STATEMENT_WITH_QUAL_OR_REF_USAGE, $propertyId );
208-
}
209-
210-
$aspects[] = EntityUsage::makeAspectKey( EntityUsage::STATEMENT_WITH_QUAL_OR_REF_USAGE );
211176

212177
return $aspects;
213178
}

client/includes/DataAccess/Scribunto/WikibaseEntityLibrary.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function getUsageAccumulator(): UsageAccumulator {
161161
}
162162

163163
/**
164-
* Add a statement usage without qualifiers and/or references (called once specific statements are accessed).
164+
* Add a statement usage (called once specific statements are accessed).
165165
*
166166
* @param string $entityId The Entity from which the statements were accessed.
167167
* @param string $propertyId Property id of the statements accessed.
@@ -170,16 +170,6 @@ public function addStatementUsage( string $entityId, string $propertyId ): void
170170
$this->getImplementation()->addStatementUsage( $entityId, $propertyId );
171171
}
172172

173-
/**
174-
* Add a statement usage with qualifiers and/or references as well as mainsnak (called once specific statements are accessed).
175-
*
176-
* @param string $entityId The Entity from which the statements were accessed.
177-
* @param string $propertyId Property id of the statements accessed.
178-
*/
179-
public function addStatementWithQualOrRefUsage( string $entityId, string $propertyId ): void {
180-
$this->getImplementation()->addStatementWithQualOrRefUsage( $entityId, $propertyId );
181-
}
182-
183173
/**
184174
* Add a label usage (called once specific labels are accessed).
185175
*
@@ -242,7 +232,6 @@ public function register() {
242232
'formatStatements' => [ $this, 'formatStatements' ],
243233
'formatPropertyValues' => [ $this, 'formatPropertyValues' ],
244234
'addStatementUsage' => [ $this, 'addStatementUsage' ],
245-
'addStatementWithQualOrRefUsage' => [ $this, 'addStatementWithQualOrRefUsage' ],
246235
'addLabelUsage' => [ $this, 'addLabelUsage' ],
247236
'addDescriptionUsage' => [ $this, 'addDescriptionUsage' ],
248237
'addTitleOrSiteLinksUsage' => [ $this, 'addTitleOrSiteLinksUsage' ],

client/includes/DataAccess/Scribunto/WikibaseLibrary.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Wikibase\DataModel\Entity\EntityId;
2424
use Wikibase\DataModel\Entity\EntityIdParser;
2525
use Wikibase\DataModel\Entity\EntityIdParsingException;
26-
use Wikibase\DataModel\Entity\NumericPropertyId;
2726
use Wikibase\DataModel\Entity\PropertyId;
2827
use Wikibase\DataModel\Services\Lookup\EntityAccessLimitException;
2928
use Wikibase\DataModel\Services\Lookup\EntityRetrievingClosestReferencedEntityIdLookup;
@@ -353,7 +352,6 @@ public function register() {
353352
'entityExists' => [ $this, 'entityExists' ],
354353
'getBadges' => [ $this, 'getBadges' ],
355354
'getEntityStatements' => [ $this, 'getEntityStatements' ],
356-
'addStatementWithQualOrRefUsage' => [ $this, 'addStatementWithQualOrRefUsage' ],
357355
'getEntityUrl' => [ $this, 'getEntityUrl' ],
358356
'renderSnak' => [ $this, 'renderSnak' ],
359357
'formatValue' => [ $this, 'formatValue' ],
@@ -497,19 +495,6 @@ public function getEntityStatements( string $prefixedEntityId, string $propertyI
497495
return [ $statements ];
498496
}
499497

500-
/**
501-
* Add a statement usage (called once specific statements are accessed) when the qualifiers and/or references are also accessed.
502-
*
503-
* @param string $entityId The Entity from which the statements were accessed.
504-
* @param string $propertyId Property id of the statements accessed.
505-
*/
506-
public function addStatementWithQualOrRefUsage( string $entityId, string $propertyId ): void {
507-
$entityId = $this->entityIdParser->parse( $entityId );
508-
$propertyId = new NumericPropertyId( $propertyId );
509-
510-
$this->usageAccumulator->addStatementWithQualOrRefUsage( $entityId, $propertyId );
511-
}
512-
513498
/**
514499
* Wrapper for getEntityId in WikibaseLanguageIndependentLuaBindings
515500
*/

client/includes/DataAccess/Scribunto/WikibaseLuaEntityBindings.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,6 @@ public function addStatementUsage( string $entityId, string $propertyId ): void
102102
$this->usageAccumulator->addStatementUsage( $entityId, $propertyId );
103103
}
104104

105-
/**
106-
* Add a statement usage (called once specific statements are accessed) when the qualifiers and/or references are also accessed.
107-
*
108-
* @param string $entityId The Entity from which the statements were accessed.
109-
* @param string $propertyId Property id of the statements accessed.
110-
*/
111-
public function addStatementWithQualOrRefUsage( string $entityId, string $propertyId ): void {
112-
$entityId = $this->entityIdParser->parse( $entityId );
113-
$propertyId = new NumericPropertyId( $propertyId );
114-
115-
$this->usageAccumulator->addStatementWithQualOrRefUsage( $entityId, $propertyId );
116-
}
117-
118105
/**
119106
* Add a label usage (called once specific labels are accessed).
120107
*

client/includes/DataAccess/Scribunto/mw.wikibase.entity.lua

Lines changed: 4 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,14 @@ local function isValidPropertyId( propertyId )
4949
return type( propertyId ) == 'string' and propertyId:match( '^P[1-9]%d*$' )
5050
end
5151

52-
-- This should only ever change during the clone operation of getEntityStatements
53-
local qualOrRefUsageTrackingEnabled = true
54-
55-
-- Log access to claims of entity with qualifiers and/or references
56-
--
57-
-- @param {string} entityId
58-
-- @param {string} propertyId
59-
local function addStatementWithQualOrRefUsage( entityId, propertyId )
60-
if isValidPropertyId( propertyId ) and qualOrRefUsageTrackingEnabled == true then
61-
-- Only attempt to track the usage if we have a valid property id.
62-
php.addStatementWithQualOrRefUsage( entityId, propertyId )
63-
end
64-
end
65-
66-
-- Log access to claims of entity mainsnak only
52+
-- Log access to claims of entity
6753
--
6854
-- @param {string} entityId
6955
-- @param {string} propertyId
7056
local function addStatementUsage( entityId, propertyId )
7157
if isValidPropertyId( propertyId ) then
7258
-- Only attempt to track the usage if we have a valid property id.
73-
php.addStatementUsage( entityId, propertyId )
59+
php.addStatementUsage( entityId, propertyId ) --add an argument here??
7460
end
7561
end
7662

@@ -118,71 +104,11 @@ local function maskEntityTable( entity, tableName, usageFunc )
118104
setmetatable( entity[tableName], pseudoTableMetatable )
119105
end
120106

121-
-- Function to mask a statement's subtables in order to log access
122-
-- Code for logging based on: http://www.lua.org/pil/13.4.4.html
123-
--
124-
-- @param {table} statement
125-
-- @param {string} tableName
126-
-- @param {function} usageFunc
127-
-- @param {string} entityId
128-
-- @param {string} propertyId
129-
local function maskStatementTable( statement, tableName, usageFunc, entityId, propertyId )
130-
if statement[tableName] == nil then
131-
return
132-
end
133-
134-
local actualStatementTable = statement[tableName]
135-
statement[tableName] = {}
136-
137-
local function logNext( _, key )
138-
local k, v = next( actualStatementTable, key )
139-
if k ~= nil then
140-
usageFunc( entityId, propertyId )
141-
end
142-
return k, v
143-
end
144-
145-
local pseudoTableMetatable = {
146-
__index = function( _, key )
147-
-- note: we do not specify string here like in maskEntityTable, because
148-
-- sometimes the key is e.g. P1 e.g. for qualifier
149-
-- sometimes the key is a number e.g. for references
150-
usageFunc( entityId, propertyId )
151-
return actualStatementTable[key]
152-
end,
153-
154-
__newindex = function (table,key,value)
155-
if (table[key] == actualStatementTable[key]) then
156-
return
157-
--note: this seems to happen in getBestStatements but the values match so no update needed
158-
else
159-
error( 'Statement table cannot be modified', 2 )
160-
end
161-
end,
162-
163-
__pairs = function( _ )
164-
return logNext, {}, nil
165-
end,
166-
}
167-
168-
setmetatable( statement[tableName], pseudoTableMetatable )
169-
end
170-
171107
-- Function to mask an entity's subtables in order to log access and prevent modifications
172108
--
173109
-- @param {table} entity
174110
local function maskEntityTables( entity )
175-
-- within claim we need to mask subtables for quals and refs too so they can be tracked
176-
if entity.claims then
177-
for propertyId, statements in pairs(entity.claims) do -- for each property e.g. P1
178-
for _, statement in ipairs(statements) do
179-
maskStatementTable(statement, "qualifiers", addStatementWithQualOrRefUsage, entity.id, propertyId)
180-
maskStatementTable(statement, "references", addStatementWithQualOrRefUsage, entity.id, propertyId)
181-
end
182-
end
183-
end
184-
185-
maskEntityTable( entity, 'claims', addStatementUsage )
111+
maskEntityTable( entity, 'claims', addStatementUsage )
186112
maskEntityTable( entity, 'labels', php.addLabelUsage )
187113
maskEntityTable( entity, 'sitelinks', php.addTitleOrSiteLinksUsage )
188114
maskEntityTable( entity, 'descriptions', php.addDescriptionUsage )
@@ -340,15 +266,8 @@ local function getEntityStatements( entity, propertyLabelOrId, funcName )
340266
end
341267

342268
if propertyId and entity.claims[propertyId] then
343-
344-
qualOrRefUsageTrackingEnabled = false
345269
-- Create a deep copy of the table to prevent unexpected value changes (T270851).
346-
-- The clone operation is considered a read of qualifiers and references so we need to
347-
-- switch off tracking just during the clone operation
348-
local clone = mw.clone(entity.claims[propertyId])
349-
qualOrRefUsageTrackingEnabled = true
350-
351-
return clone
270+
return mw.clone(entity.claims[propertyId])
352271
end
353272

354273
return {}

client/includes/DataAccess/Scribunto/mw.wikibase.lua

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -177,92 +177,6 @@ function wikibase.setupInterface( settings )
177177
return getEntityObject( id )
178178
end
179179

180-
-- Is this a valid property id (Pnnn)?
181-
--
182-
-- @param {string} propertyId
183-
local function isValidPropertyId( propertyId )
184-
return type( propertyId ) == 'string' and propertyId:match( '^P[1-9]%d*$' )
185-
end
186-
187-
-- Log access to claims of entity with qualifiers and/or references
188-
--
189-
-- @param {string} entityId
190-
-- @param {string} propertyId
191-
local function addStatementWithQualOrRefUsage( entityId, propertyId )
192-
if isValidPropertyId( propertyId ) then
193-
-- Only attempt to track the usage if we have a valid property id.
194-
php.addStatementWithQualOrRefUsage( entityId, propertyId )
195-
end
196-
end
197-
198-
-- Function to mask a statement's subtables in order to log access
199-
-- Code for logging based on: http://www.lua.org/pil/13.4.4.html
200-
--
201-
-- @param {table} statement
202-
-- @param {string} tableName
203-
-- @param {function} usageFunc
204-
-- @param {string} entityId
205-
-- @param {string} propertyId
206-
local function maskStatementTable( statement, tableName, usageFunc, entityId, propertyId )
207-
if statement[tableName] == nil then
208-
return
209-
end
210-
211-
local actualStatementTable = statement[tableName]
212-
statement[tableName] = {}
213-
214-
local function logNext( _, key )
215-
local k, v = next( actualStatementTable, key )
216-
if k ~= nil then
217-
usageFunc( entityId, propertyId )
218-
end
219-
return k, v
220-
end
221-
222-
local pseudoTableMetatable = {
223-
__index = function( _, key )
224-
-- note: we do not specify string here like in maskEntityTable, because
225-
-- sometimes the key is e.g. P1 e.g. for qualifier
226-
-- sometimes the key is a number e.g. for references
227-
usageFunc( entityId, propertyId )
228-
return actualStatementTable[key]
229-
end,
230-
231-
__newindex = function (table,key,value)
232-
if (table[key] == actualStatementTable[key]) then
233-
return
234-
else
235-
error( 'Statement table cannot be modified', 2 )
236-
end
237-
end,
238-
239-
__pairs = function( _ )
240-
return logNext, {}, nil
241-
end,
242-
}
243-
244-
setmetatable( statement[tableName], pseudoTableMetatable )
245-
end
246-
247-
248-
-- Function to mask a statement's subtables in order to log access and prevent modifications
249-
--
250-
-- @param {table} statements
251-
local function maskStatementTables( statementsForPropertyId, entityId, propertyId )
252-
253-
-- TODO ----- This isn't quite working, WIP
254-
255-
256-
257-
-- within claim we need to mask subtables for quals and refs too so they can be tracked
258-
if statementsForPropertyId then
259-
for _, statement in ipairs(statementsForPropertyId) do
260-
maskStatementTable(statement, "qualifiers", addStatementWithQualOrRefUsage, entityId, propertyId)
261-
maskStatementTable(statement, "references", addStatementWithQualOrRefUsage, entityId, propertyId)
262-
end
263-
end
264-
end
265-
266180
-- getEntityObject is an alias for getEntity as these used to be different.
267181
wikibase.getEntityObject = wikibase.getEntity
268182

@@ -286,17 +200,12 @@ end
286200
incrementStatsKey( 'getEntityStatements' )
287201

288202
statements = php.getEntityStatements( entityId, propertyId, rank )
289-
290203
addToCache( statementCache, cacheKey, statements )
291204
end
292205

293206
if statements and statements[propertyId] then
294207
-- Use a clone here, so that users can't modify the cached statement
295-
local clonedStatementsForPropertyId = mw.clone( statements[propertyId] )
296-
-- Masking for tracking usages of qualifers/references must occur after
297-
-- cloning, as otherwise the cloning would appear as a usage or quals/refs
298-
maskStatementTables( clonedStatementsForPropertyId, entityId, propertyId )
299-
return clonedStatementsForPropertyId
208+
return mw.clone( statements[propertyId] )
300209
end
301210

302211
return {}

client/includes/Hooks/InfoActionHookHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,6 @@ private function formatAspects( array $aspects, IContextSource $context ) {
209209
// wikibase-pageinfo-entity-usage-D-with-modifier
210210
// wikibase-pageinfo-entity-usage-C
211211
// wikibase-pageinfo-entity-usage-C-with-modifier
212-
// wikibase-pageinfo-entity-usage-CQR
213-
// wikibase-pageinfo-entity-usage-CQR-with-modifier
214212
// wikibase-pageinfo-entity-usage-S
215213
// wikibase-pageinfo-entity-usage-T
216214
// wikibase-pageinfo-entity-usage-X

0 commit comments

Comments
 (0)