MediaWiki:Gadget-WantedPagesMainspace.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Gadget: WantedPagesMainspace
// Filters a transcluded Special:WantedPages list down to mainspace-only,
// with a simple blacklist of prefixes for admin/help/template/internal stuff.
mw.loader.using(['mediawiki.Title', 'mediawiki.util'], function () {
// Only run on the specific portal (adjust if you want Special:WantedPages instead)
if (mw.config.get('wgPageName') !== 'Portal:WantedPages') {
return;
}
var container = document.getElementById('wantedpages-mainonly');
if (!container) {
return;
}
// Prefixes we never want to show here
var bannedPrefixes = [
'Help:',
'Template:',
'The Deep Tech Wiki:',
'Wikipedia:',
'WP:',
'Wp:',
'Project:',
'Category:',
'File:',
'Module:',
'MediaWiki:',
'User:',
'User talk:',
'Talk:'
];
function isBannedPrefix(text) {
for (var i = 0; i < bannedPrefixes.length; i++) {
if (text.indexOf(bannedPrefixes[i]) === 0) {
return true;
}
}
return false;
}
// Optional: exact titles you never want (even if mainspace)
var bannedExactTitles = [
// 'Stats:EN/Sitemap',
// 'Red link example'
];
function isBannedExact(text) {
return bannedExactTitles.indexOf(text) !== -1;
}
// Collect all links produced by the transcluded Special:WantedPages
var links = container.querySelectorAll('a');
var mainspaceLinks = [];
links.forEach(function (link) {
var text = (link.textContent || '').trim();
if (!text) {
return;
}
// Quick blacklist checks on raw text
if (isBannedPrefix(text) || isBannedExact(text)) {
return;
}
// Use MediaWiki Title API to determine namespace
var titleObj = mw.Title.newFromText(text);
if (!titleObj) {
return;
}
// Namespace 0 is the main/article namespace
if (titleObj.getNamespaceId() !== 0) {
return;
}
// Passed all filters; keep a clone of the link
mainspaceLinks.push(link.cloneNode(true));
});
// Build a new clean <ul> with only accepted links
var ul = document.createElement('ul');
mainspaceLinks.forEach(function (l) {
var li = document.createElement('li');
li.appendChild(l);
ul.appendChild(li);
});
// Replace the original contents with the cleaned list
container.innerHTML = '';
container.appendChild(ul);
});