Community Central
Community Central
mNo edit summary
mNo edit summary
Line 40: Line 40:
 
'u:dev:MediaWiki:AjaxBatchDelete/code.2.js',
 
'u:dev:MediaWiki:AjaxBatchDelete/code.2.js',
 
'u:dev:MediaWiki:AjaxBatchUndelete/code.js',
 
'u:dev:MediaWiki:AjaxBatchUndelete/code.js',
  +
'u:dev:MediaWiki:Discussions Delete All/code.js',
 
'u:dev:MediaWiki:MassEdit/code.js',
 
'u:dev:MediaWiki:MassEdit/code.js',
 
'u:dev:MediaWiki:MassBlock/code.js',
 
'u:dev:MediaWiki:MassBlock/code.js',

Revision as of 02:34, 22 September 2021

window.SeeMoreActivityButtonOld = true;
mw.loader.using('mediawiki.util').then(function() {
if (mw.config.get('wgCityId') === '177') {
    importArticle({
        type: 'style',
        article: 'u:dev:MediaWiki:WikiaCommunityCentralTheme.css'
    });
}
AjaxRCRefreshText = 'Auto-refresh';
AjaxRCRefreshHoverText = 'Automatically refresh the page';
ajaxPages = ["Special:RecentChanges"];
window.UserTagsJS = {
    modules: {
        inactive: 62,
        newuser: true,
        autoconfirmed: true,
        mwGroups: [
            'bureaucrat',
            'sysop',
            'assistant',
            'rollback',
            'global-discussions-moderator'
        ]
    },
    tags: {
        assistant: 'Assistant',
        threadmoderator: 'Discussion Moderator',
        'content-moderator': 'Content Moderator'
    },
    oasisPlaceBefore: ''
};
importArticles({
    type: 'script',
    articles: [
        'u:dev:MediaWiki:EditIntroButton/code.js',
        'u:dev:MediaWiki:AjaxRC/code.js',
        'u:dev:MediaWiki:PurgeButton/code.js',
        'u:dev:MediaWiki:UserTags/code.js',
        'u:dev:MediaWiki:Nuke/code.js',
        'u:dev:MediaWiki:AjaxBatchDelete/code.2.js',
        'u:dev:MediaWiki:AjaxBatchUndelete/code.js',
        'u:dev:MediaWiki:Discussions Delete All/code.js',
        'u:dev:MediaWiki:MassEdit/code.js',
        'u:dev:MediaWiki:MassBlock/code.js',
        'u:dev:MediaWiki:MassRename/code.js',
        'u:dev:MediaWiki:QQX/code.js',
        'u:dev:MediaWiki:Less/code.2.js',
        'u:dev:MediaWiki:MinimalTemplateClassification.js',
        'u:dev:MediaWiki:SeeMoreActivityButton/code.js',
        'u:dev:MediaWiki:WallGreeting.js'        
    ]
});
/* 
* Rollback
* @description Perform rollbacks without needing to be in the usergroup
* @author Ozank
*/
 
mw.loader.using('mediawiki.api', function() {
 
//Exit if normal rollback links are present
if ($('.mw-rollback-link').length) return;
 
var conf = mw.config.get([
'wgAction',
'wgCanonicalSpecialPageName',
'wgContentLanguage',
'wgPageName',
'wgUserLanguage',
'skin'
]),
i18n = {
en: {
rollback: "rollback",
description: ""Rollback" reverts edit(s) to this page of the last contributor in one click",
summary: "Reverted edits by [[Special:Contributions/$1|$1]] ([[User talk:$1|talk]]) to last revision by $2 ([[w:c:dev:Rollback|script]])",
summaryShort: "Reverted edits by [[Special:Contributions/$1|$1]] ([[User talk:$1|talk]]) to last revision by $2 ([[w:c:dev:Rollback|script]])",
editConflict: "Unable to rollback (edit conflict)",
contentFail: "Unable to rollback (failed to get page content)",
singleEditor: "Unable to rollback (no different editor found)",
revisionFail: "Unable to rollback (failed to get revisions)",
editFail: "Unable to rollback (failed to publish edit)",
success: "Rollback successful"
}
};
i18n = i18n[conf.wgUserLanguage] || i18n[conf.wgUserLanguage.split('-')[0]] || i18n[conf.wgContentLanguage] || i18n[conf.wgContentLanguage.split('-')[0]] || i18n.en;
 
conf.API = new mw.Api();
conf.token = mw.user.tokens.values.editToken;
 
//History
if (conf.wgAction == "history" && $('#pagehistory li').length > 1) 
$('#pagehistory li:first .mw-history-undo a').before('<span class="mw-custom-rollback-link"><a title="' + i18n.description + '" data-id="' + conf.wgPageName + '" data-user="' + $('.mw-userlink:first').text() + '">' + i18n.rollback + '</a></span> | ');
 
//Contributions
else if (conf.wgCanonicalSpecialPageName == "Contributions") {
$('#mw-content-text ul').find('li').each(function() {
if ($(this).find('.mw-uctop').length)
$(this).append(' <span class="mw-custom-rollback-link">[<a title="' + i18n.description + '" data-id="' + $(this).find('a:first').attr('title') + '" data-user="' + conf.wgPageName.split('/')[1] + '">' + i18n.rollback + '</a>]</span>');
});
}
 
//Diffs
else if ((mw.util.getParamValue('diff') || mw.util.getParamValue('oldid')) && $('#differences-nextlink').length === 0)
$('.mw-usertoollinks:last').after('&nbsp;&nbsp;&nbsp;&nbsp;<span class="mw-custom-rollback-link">[<a title="' + i18n.description + '" data-id="' + conf.wgPageName + '" data-user="' + $('#mw-diff-ntitle2 .mw-userlink').text() + '">' + i18n.rollback + '</a>]</span>');
else
return;
 
mw.util.addCSS('.mw-custom-rollback-link a { cursor: pointer; }');
 
$('.mw-custom-rollback-link a').click(function() {
getRevisionIdAndContent($(this).data('id'),$(this).data('user').replace(/_/g, " "));
$(this).parent().remove();
});
 
function getRevisionIdAndContent(title,target) {
conf.API.get({
action: 'query',
prop: 'revisions',
titles: title,
rvprop: 'user|ids',
rvlimit: 500,
cb: new Date().getTime()
})
.done(function(d) {
if (!d.error) {
var revisions;
 
for (var i in d.query.pages) {
revisions = d.query.pages[i].revisions;
}
 
//Don't rollback if the page has been edited since by somebody else than the intended person to rollback from
if (target != revisions[0].user) {
outputError(i18n.editConflict);
return;
}
 
var lastUser,
revId;
 
for (var j in revisions) {
if (revisions[j].user != target) {
lastUser = revisions[j].user; //remember last author
revId = revisions[j].revid; //get revision to revert to
break;
}
}
 
if (lastUser) {
conf.API.get({
action: 'query',
prop: 'revisions',
rvprop: 'content',
revids: revId,
cb: new Date().getTime()
})
.done(function(d) {
if (!d.error) {
var content = ""; //can be no content on page
for (var i in d.query.pages) {
if (d.query.pages[i].revisions)
content = d.query.pages[i].revisions[0]["*"];
}
performRollback(title,content,target,lastUser);
}
else
outputError(i18n.contentFail + ': ' + d.error.code);
})
.fail(function() {
outputError(i18n.contentFail);
});
}
else
outputError(i18n.singleEditor);
}
else
outputError(i18n.revisionFail + ': ' + d.error.code);
})
.fail(function() {
outputError(i18n.revisionFail);
});
}
 
function performRollback(page,text,user,user2) {
var summary = i18n.summary.replace(/\$1/g,user).replace(/\$2/g,user2);
 
conf.API.post({
action: 'edit',
title: page,
text: text,
summary: summary,
minor: true,
token: conf.token
})
.done(function(d) {
if (!d.error) {
new BannerNotification(i18n.success,'confirm').show();
}
else
outputError(i18n.editFail + ': ' + d.error.code);
})
.fail(function() {
outputError(i18n.editFail);
});
}
 
function outputError(text) {
switch (conf.skin) {
case 'oasis': 
case 'wikia':
new BannerNotification(text,'error').show();
break;
 
default:
alert(text);
break;
}
}
});
 
// Adds NavigationPopups
// [[wikipedia:User:Lupin/popups]]
popupRevertSummary = 'Revert to revision dated %s by %s, oldid %s using [[:wikipedia:Wikipedia:Popups|popups]]';
popupQueriedRevertSummary = 'Revert to revision $1 dated $2 by $3 using [[:wikipedia:Wikipedia:Popups|popups]]';
popupExtendedRevertSummary = 'Revert to revision dated %s by %s, oldid %s using [[:wikipedia:Wikipedia:Popups|popups]]';
popupQueriedRevertToPreviousSummary = 'Revert to the revision prior to revision $1 dated $2 by $3 using [[:wikipedia:Wikipedia:Popups|popups]]';
popupRevertToPreviousSummary = 'Revert to the revision prior to revision %s using [[:wikipedia:Wikipedia:Popups|popups]]';
popupRevertSummaryPrompt = true;
popupStructure = 'menus';
popupFixDabs = 'true';
popupFixDabsSummary = 'Disambiguate [[%s]] to [[%s]] using [[:wikipedia:Wikipedia:Tools/Navigation_popups|popups]]';
popupRmDabLinkSummary = 'Remove link to dab page [[%s]] using [[:wikipedia:en:Wikipedia:Tools/Navigation_popups|popups]]';
mw.loader.load("//en.wikipedia.org/w/index.php?title=User:Lupin/popups.js&action=raw&ctype=text/javascript&oldid=805750784");
importStylesheetURI('https://en.wikipedia.org/w/index.php?action=raw&ctype=text/css&title=MediaWiki:Gadget-navpop.css');
// END Adds NavigationPopups
 
// install [[User:Cacycle/wikEdDiff]] enhanced diff
importScriptURI('//en.wikipedia.org/w/index.php?title=User:Cacycle/wikEdDiff.js&action=raw&ctype=text/javascript');
// Add wgWikiName variable to mw.config
// By [[User:Colouratura]]
mw.config.values['wgWikiName' ] = function () {
    return window.location.toString().split( '.wikia.com' )[ 0 ].slice( 7 );
}();
//Add extra AccountNav options
/*
 */
;(function() {
    if (navLinks) return;
    var user = mw.util.wikiUrlencode(mw.config.get('wgUserName')),
        links = {
        watchlist: {
            text: 'My Watchlist',
            url: '/wiki/Special:Watchlist'        	
        },
        blogs: {
            text: 'My Blogs',
            url: '/wiki/User_blog:' + user
        }
    },
        html = '',
        navLinks = true;
    for (var i in links) {
        html += '<li><a href="' + links[i].url + '" class="wds-global-navigation__dropdown-link">' + links[i].text + '</a></li>';
    }
    document.querySelector('.global-navigation__bottom > .wds-dropdown > .wds-dropdown__content > ul.wds-list > li:nth-child(2)').insertAdjacentHTML('afterEnd', html);
})();
importArticles({
    type: 'script',
    articles: [
        'u:dev:MediaWiki:AjaxRC/code.js',
        'u:dev:MediaWiki:MassPatrol/code.js'
    ]
});
massProtectDelay = 500;
importArticles({
    type: "script",
    articles: [
        'u:dev:MediaWiki:MassProtect/code.js'
    ]
});
window.massEditConfig = {
    editSummary: "Your edit summary",
    editInterval: 1000
};
});

// *************************************************
// Pagetitle rewrite
//
// Rewrites the page's title, used by Template:Title
// *************************************************
$(function() {
    var inter = setInterval(function() {
        if (!$('h1[itemprop=\"name\"]').length) return;

        clearInterval(inter);
        var newTitle = $("span.newPageTitle").find(':not(big, small, center, h1, h2, h3, h4, h5, h6, b, i, u, s, span, div)').remove().end().html();
        var edits = $("#user_masthead_since").text();
        $(".firstHeading,h1[itemprop=\"name\"],.resizable-container .page-header__title").html(mw.html.escape(newTitle));
        $("#user_masthead_head h2").html(mw.html.escape(newTitle + "<small id='user_masthead_since'>" + edits + "</small>"));
    });
});

$(function changeTitle(){
    if (!$('span.newPageTitle').length) {
        return;
    }
    var title = $('span.newPageTitle').find(':not(big, small, center, h1, h2, h3, h4, h5, h6, b, i, u, s, span, div)').remove().end().html();
    $('h1.page-header__title').html(mw.html.escape(title));
});

window.batchDeleteDelay = 1;

// Discussions Delete All
// Button from Special:Contribs that deletes all Discussions posts of user
// @author: Jr Mime
(function () {
    'use strict';

    var config = mw.config.get([
        'wgUserGroups',
        'wgVersion',
        'wgCanonicalSpecialPageName'
    ]);

    if (
        window.dda ||
        !['Contributions', 'UserProfileActivity'].includes(config.wgCanonicalSpecialPageName) ||
        !new RegExp([
            'threadmoderator',
            'sysop',
            'staff',
            'soap',
            'helper',
            'content-moderator',            
            'global-discussions-moderator',
            'wiki-representative'
        ].join('|')).test(config.wgUserGroups.join()) ||
        // DO NOT run for anonymous users. This will delete ALL posts and replies
        // of ALL anonymous users that ever posted in the wiki's Discussions,
        // which is probably not what the user wants to do.
        Number(mw.config.get('profileUserId')) === 0
    ) {
        return;
    }

    var dda = {
        preload: function (i18n) {
            mw.loader.using('mediawiki.util', function () {
                i18n.loadMessages('Discussions Delete All').then(dda.init);
            });
        },
        init: function (i18n) {    
            dda.i18n = i18n;

            var element = $('<a>', {
                href: '#',
                click: function () {
                    if (window.ddaDoNotConfirm || confirm(dda.i18n.msg('confirm').plain())) {
                        dda.deleteAll();
                    }
                },
                id: 'DeleteAllDiscussionsPostsByUser',
                text:  dda.i18n.msg('delete').plain(),
                title: dda.i18n.msg('title').plain()
            });
            var selector = $('.mw-contributions-user-tools > .mw-changeslist-links > span:last-child, .UserProfileActivityModeration__links > span:last-child');
            
            selector.after(element);
            element.wrap('<span></span>');
        },
        deleteAll: function () {
            fetch(mw.util.wikiScript('wikia') + '?controller=DiscussionContribution&method=deleteAll&userId=' + mw.config.get('profileUserId'), {
                method: 'POST',
                credentials: 'include'
            }).then(function () {
                alert(dda.i18n.msg('done').plain());
            });
        }
    };

    window.dda = dda;
    mw.hook('dev.i18n').add(dda.preload);
    importArticle({
        type: 'script',
        article: 'u:dev:MediaWiki:I18n-js/code.js'
    });
})();