MediaWiki:Common.js: Difference between revisions

From Melvor Idle
(Add Purge link to page tools)
(Amend purge link such that it only appears for current revisions of articles which the user can edit)
Line 767: Line 767:


function isUserLoggedIn() {
function isUserLoggedIn() {
  if (mw.config.get('wgUserName') === null) {
if (mw.config.get('wgUserName') === null) {
    return false;
return false;
  } else {
} else {
    return true;
return true;
  }
}
}
}


function addToPageTools() {
function addToPageTools() {
if (isUserLoggedIn()) {
if (isUserLoggedIn()) {
$.when(mw.loader.using(['mediawiki.util']), $.ready).then( function() {
var canEdit = mw.config.get('wgIsProbablyEditable') ?? false;
mw.util.addPortletLink(
var isArticle = mw.config.get('wgIsArticle') ?? false;
'p-cactions',
var isCurRevision = (mw.config.get('wgRevisionId') ?? 0) >= (mw.config.get('wgCurRevisionId') ?? 0);
mw.util.getUrl() + '?action=purge',
if (canEdit && isArticle && isCurRevision) {
'Purge',
$.when(mw.loader.using(['mediawiki.util']), $.ready).then( function() {
't-purgecache',
mw.util.addPortletLink(
'Purge the cache for this page',
'p-cactions',
null,
mw.util.getUrl() + '?action=purge',
null
'Purge',
);
't-purgecache',
});
'Purge the cache for this page',
null,
null
);
});
}
}
}
}
}
Line 800: Line 805:


function showAndroidAppDownloadLink() {
function showAndroidAppDownloadLink() {
    var shouldShowDownload = /Android/i.test(window.navigator.userAgent) && window.navigator.userAgent.indexOf('gonative melvorwiki') === -1;
var shouldShowDownload = /Android/i.test(window.navigator.userAgent) && window.navigator.userAgent.indexOf('gonative melvorwiki') === -1;
    if (shouldShowDownload) {
if (shouldShowDownload) {
    $('.android-app-download').removeClass('d-none');
$('.android-app-download').removeClass('d-none');
    } else {
} else {
    $('.android-app-download').addClass('d-none');
$('.android-app-download').addClass('d-none');
    }
}
}
}