MediaWiki:Gadget-GlossaryGraph.js: Difference between revisions
Jump to navigation
Jump to search
AdminIsidore (talk | contribs) No edit summary |
AdminIsidore (talk | contribs) No edit summary |
||
| Line 10: | Line 10: | ||
} | } | ||
// Extract term | // Extract term (e.g., "Dictum" from "Lingua:Dictum") | ||
var term = pageTitle.split(':').pop(); | var term = pageTitle.split(':').pop(); | ||
// Query SMW for pages with Glossary-Definition | // Query SMW for pages with Glossary-Definition | ||
var smwQuery = encodeURIComponent('[[Glossary-Definition::+ | var smwQuery = encodeURIComponent('[[Category:Glossary Entries]][[Glossary-Definition::+*]]|?Glossary-Term|limit=50'); | ||
new mw.Api().get({ | new mw.Api().get({ | ||
action: 'ask', | action: 'ask', | ||
| Line 24: | Line 24: | ||
for (var page in results) { | for (var page in results) { | ||
if (results.hasOwnProperty(page) && page !== pageTitle) { | if (results.hasOwnProperty(page) && page !== pageTitle) { | ||
links.push({ title: page }); | var definition = results[page].printouts['Glossary-Definition'] || []; | ||
// Check if definition contains the term (case-insensitive) | |||
if (definition.some(function(def) { | |||
return def.toLowerCase().indexOf(term.toLowerCase()) !== -1; | |||
})) { | |||
links.push({ title: page }); | |||
} | |||
} | } | ||
} | } | ||
| Line 94: | Line 100: | ||
}).fail(function(error) { | }).fail(function(error) { | ||
$container.text('Error: API request failed'); | $container.text('Error: API request failed'); | ||
console.error('SMW API error:', error); | |||
}); | }); | ||
}); | }); | ||
}); | }); | ||
}); | }); | ||