Add tracking for template data presence

This will give results whenever template data is requested e.g. by
VisualEditor or the TemplateWizard.

Bug: T259705
Change-Id: I2a9e864b94b6f8f49ca3adaa46502627ab6b3322
This commit is contained in:
WMDE-Fisch 2020-12-14 17:48:51 +01:00
parent 028aaba896
commit b8b1df894f
2 changed files with 22 additions and 3 deletions

View file

@ -218,7 +218,8 @@
"attributes": {
"EventLogging": {
"Schemas": {
"TemplateDataEditor": 20759032
"TemplateDataEditor": 20759032,
"TemplateDataApi": 20817949
}
},
"VisualEditor": {

View file

@ -147,6 +147,8 @@ class ApiTemplateData extends ApiBase {
}
}
$wikiPageFactory = $services->getWikiPageFactory();
// Now go through all the titles again, and attempt to extract parameter names from the
// wikitext for templates with no templatedata.
if ( $includeMissingTitles ) {
@ -155,8 +157,8 @@ class ApiTemplateData extends ApiBase {
// Ignore pages that already have templatedata or that don't exist.
continue;
}
$content = $services->getWikiPageFactory()
->newFromTitle( $pageInfo['title'] )
$content = $wikiPageFactory->newFromTitle( $pageInfo['title'] )
->getContent( RevisionRecord::FOR_PUBLIC );
$text = $content instanceof TextContent
? $content->getText()
@ -165,6 +167,22 @@ class ApiTemplateData extends ApiBase {
}
}
// TODO tracking will only be implemented temporarily to answer questions on
// template usage for the Technical Wishes topic area see T258917
if ( ExtensionRegistry::getInstance()->isLoaded( 'EventLogging' ) ) {
foreach ( $resp as $pageId => $pageInfo ) {
\EventLogging::logEvent(
'TemplateDataApi',
20817949,
[
'template_name' => $wikiPageFactory->newFromTitle( $pageInfo['title'] )
->getTitle()->getDBkey(),
'has_template_data' => !( isset( $pageInfo['notemplatedata'] ) ?: false ),
]
);
}
}
ApiResult::setArrayType( $resp, 'kvp', 'id' );
ApiResult::setIndexedTagName( $resp, 'page' );