Page MenuHomePhabricator

TypeError: info.templatedata is undefined
Closed, ResolvedPublicBUG REPORT

Description

What is the problem?

When trying to select some templates from the Category browser, the final details panel does not appear and instead I get this error in the browser console:

TypeError: info.templatedata is undefined

So far, I have only seen this on testwiki.

Steps to reproduce problem
  1. https://test.wikipedia.org/w/index.php?title=Irma%C3%A7,_Kangal&action=edit
  2. Open the templates dialog and switch to the Categories tab
  3. Search for the category Wikipedia pages with incorrect protection templates
  4. Attempt to select the templates -, Anime voice, Blist
Environment

Wiki(s): https://test.wikipedia.org TemplateData 0.2.0 (a1b7acc) 12:47, 9 June 2025.

Screenshots

cannot_select_template.png (556×715 px, 46 KB)

Event Timeline

hm, info doesn't have templatedata for some of these templates, but most (all?) of the required info is available in categories — I can't replicate this locally on the same commit/latest commit...

we could check to see if info.templatedata is defined at modules/ext.templateData.templateDiscovery/categories/Column.js#97 and instead use info.categories.title in its place if not?


{
    "categories": {
        "pageid": 45415,
        "ns": 10,
        "title": "Template:Anime voice",
        "categories": [
            {
                "ns": 14,
                "title": "Category:Wikipedia pages with incorrect protection templates",
                "sortkey": "2a443a42320454463a2e32010f01dc0e",
                "sortkeyprefix": "",
                "hidden": false
            }
        ]
    }
}

I think it might be when a template is redirected but also is categorised, e.g. Template:CN:

#REDIRECT [[Template:Citation needed]]
[[Category:Template shortcuts]]

I think the fix might be in DataStore.getItemData(), where we look for the returned data with if ( responses[ 0 ].pages[ pageId ] !== undefined ) …

It should actually be looking instead for the *first* (well, and only) returned page (and also then returning the ID of that page, which will be different in the case of redirects).

I think it might be when a template is redirected but also is categorised

Yup! I can replicate that (thanks Sam :D) — I can fix this now

I think it might be when a template is redirected but also is categorised, e.g. Template:CN:

#REDIRECT [[Template:Citation needed]]
[[Category:Template shortcuts]]

I think the fix might be in DataStore.getItemData(), where we look for the returned data with if ( responses[ 0 ].pages[ pageId ] !== undefined ) …

It should actually be looking instead for the *first* (well, and only) returned page (and also then returning the ID of that page, which will be different in the case of redirects).

finally swum back around to this task — I think I'm following what you mean

diff --git a/modules/ext.templateData.templateDiscovery/categories/DataStore.js b/modules/ext.templateData.templateDiscovery/categories/DataStore.js
index 6739763..e3612a1 100644
--- a/modules/ext.templateData.templateDiscovery/categories/DataStore.js
+++ b/modules/ext.templateData.templateDiscovery/categories/DataStore.js
@@ -84,6 +84,10 @@ DataStore.prototype.getItemData = function ( pageId ) {
                } )
        ] ).then( ( responses ) => {
                const out = {};
+               const gotPageId = Object.keys( responses[ 0 ].pages )[ 0 ];
+               if ( parseInt( gotPageId ) !== pageId ) {
+                       pageId = parseInt( gotPageId );
+               }
                if ( responses[ 0 ].pages[ pageId ] !== undefined ) {
                        out.templatedata = responses[ 0 ].pages[ pageId ];
                        // Set the pageId for easier access later.

which works fine, but does now show the title of page where the redirect is pointing.. (is that okay?)

Change #1164461 had a related patch set uploaded (by Samtar; author: Samtar):

[mediawiki/extensions/TemplateData@master] ext.templateData.templateDiscovery: Use first page result when getting item data

https://gerrit.wikimedia.org/r/1164461

Change #1164461 merged by jenkins-bot:

[mediawiki/extensions/TemplateData@master] ext.templateData.templateDiscovery: Use first page result when getting item data

https://gerrit.wikimedia.org/r/1164461

I haven't been able to reproduce this yet on either testwiki or enwiki prod.