MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
(Created page with "→Any JavaScript here will be loaded for all users on every page load.: →Display banner on archived pages: mw.hook('wikipage.content').add(function() { var cats = mw.config.get('wgCategories'); if (cats && cats.indexOf('Your Category Name') !== -1) { $('.mw-parser-output').prepend( '<div class="category-notice">This article is archived. It is either extremely out of date or no longer relevant. </div>' ); } });") |
No edit summary |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
/ | // Adds warning to archived pages | ||
mw.hook('wikipage.content').add(function () { | |||
mw.hook('wikipage.content').add(function() { | |||
var cats = mw.config.get('wgCategories'); | var cats = mw.config.get('wgCategories'); | ||
if (cats | if (!cats || cats.indexOf('Archive') === -1) return; | ||
$('.mw-parser-output').prepend( | |||
// Call the MediaWiki API to parse the template | |||
$.ajax({ | |||
} | url: mw.util.wikiScript('api'), | ||
data: { | |||
action: 'parse', | |||
text: '{{Archived}}', | |||
contentmodel: 'wikitext', | |||
format: 'json' | |||
}, | |||
dataType: 'json', | |||
success: function (data) { | |||
if (data.parse && data.parse.text) { | |||
var html = data.parse.text['*']; | |||
$('.mw-parser-output').prepend(html); | |||
$('.mw-parser-output').prepend('\n'); | |||
} | |||
} | |||
}); | |||
}); | }); | ||
Latest revision as of 22:28, 21 April 2026
// Adds warning to archived pages
mw.hook('wikipage.content').add(function () {
var cats = mw.config.get('wgCategories');
if (!cats || cats.indexOf('Archive') === -1) return;
// Call the MediaWiki API to parse the template
$.ajax({
url: mw.util.wikiScript('api'),
data: {
action: 'parse',
text: '{{Archived}}',
contentmodel: 'wikitext',
format: 'json'
},
dataType: 'json',
success: function (data) {
if (data.parse && data.parse.text) {
var html = data.parse.text['*'];
$('.mw-parser-output').prepend(html);
$('.mw-parser-output').prepend('\n');
}
}
});
});