MediaWiki:Common.js: Difference between revisions

From Redbrick Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
mw.hook('wikipage.content').add(function () {
/* Display banner on archived pages */
mw.hook('wikipage.content').add(function() {
     var cats = mw.config.get('wgCategories');
     var cats = mw.config.get('wgCategories');
     if (cats && cats.indexOf('Archive') !== -1) {
     if (!cats || cats.indexOf('Archive') === -1) return;
         $('.mw-parser-output').prepend(
 
             '<div class="category-notice">{| class="" style="padding: 0.5em; border-color: #AAAAAA #AAAAAA #AAAAAA #f00; border-style: solid; border-width: 1px 1px 1px 10px; margin: 0 10%;"
    // Call the MediaWiki API to parse the template
|'''IMPORTANT:''' This article is archived. It is either extremely out of date or no longer relevant.  
    $.ajax({
|}
         url: mw.util.wikiScript('api'),
</div>'
        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);
            }
         }
     });
});
});

Revision as of 22:21, 21 April 2026

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);
            }
        }
    });
});