MediaWiki:FileLogs.js

/** * Name:       FileLogs * Version:    v1.0 * Author:     KockaAdmiralac <1405223@gmail.com> * Description: Adds log excerpts to file pages of deleted *             or moved files. */ (function {   'use strict';    var config = mw.config.get([ 'wgArticleId', 'wgNamespaceNumber', 'wgPageName', 'wgServer', 'wgUserLanguage' ]);   if ( config.wgArticleId !== 0 || config.wgNamespaceNumber !== 6 || window.FileLogsLoaded ) {       return;    }    window.FileLogsLoaded = true;    var FileLogs = {        init: function {            new mw.Api.get({ action: 'query', list: 'logevents', letitle: config.wgPageName, meta: 'allmessages', ammessages: 'moveddeleted-notice', amlang: config.wgUserLanguage }).then($.proxy(FileLogs.callback, FileLogs));       },        callback: function(d) {            var q = d.query;            if (!(q.logevents instanceof Array) || q.logevents.length === 0) {                return;            }            this.$warning = $(' ', { 'class': 'mw-warning-with-logexcerpt' }).append( $(' ', {                   text: q.allmessages[0]['*']                }), $(' ').load(                   config.wgServer +                    mw.util.getUrl('Special:Log', { page: config.wgPageName }) +                   ' #mw-content-text > ul',                    $.proxy(FileLogs.loaded, FileLogs)                ) ).prependTo('#mw-content-text');           mw.hook('FileLogs.inserted').fire(this.$warning);        },        loaded: function {            var $div = this.$warning.find('> div');            $div.replaceWith($div.html);            mw.hook('FileLogs.loaded').fire(this.$warning);        }    };    mw.loader.using([ 'mediawiki.api', 'mediawiki.util' ]).then($.proxy(FileLogs.init, FileLogs)); });