Difference between revisions of "MediaWiki:Common.js"

From The iPhone Wiki
Jump to: navigation, search
(Handle different location of /index.php on The Apple Wiki)
(Handle filesystem and key page namespaces)
Line 30: Line 30:
   
 
// The Apple Wiki migration sitenotice link
 
// The Apple Wiki migration sitenotice link
  +
(function() {
$("#siteNotice a[href='https://theapplewiki.com/']")
 
.attr("href", location.href
+
var url = location.href
 
.replace(location.origin, "https://theapplewiki.com")
 
.replace(location.origin, "https://theapplewiki.com")
.replace("https://theapplewiki.com/w/", "https://theapplewiki.com/"));
+
.replace("https://theapplewiki.com/w/", "https://theapplewiki.com/");
  +
var pageName = mw.config.get("wgPageName");
  +
var categories = mw.config.get("wgCategories");
  +
if (categories.indexOf("Filesystem") > 0) {
  +
url = url.replace(pageName, "Filesystem:" + pageName);
  +
} else if (categories.indexOf("All Key Pages") > 0) {
  +
url = url.replace(pageName, "Keys:" + pageName);
  +
}
  +
$("#siteNotice a[href='https://theapplewiki.com/']")
  +
.attr("href", url);
  +
})();

Revision as of 12:21, 5 October 2023

/**
 * The iPhone Wiki MediaWiki:Common.js
 *   - JavaScript to fix common issues on The iPhone Wiki
 * Copyright (c) 2013-2017 Cole Johnson <coleharrisjohnson@gmail.com>
 * Licensed under CC-BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0/>
 **/

// Removes the "/20##" part of the "Page" link on talk archives
function fixTalkArchiveNSLinks() {
    // Are we an archive?
    // Would work by checking $(".archive-page-notice").length
    var page = $(".firstHeading")[0].innerHTML;
    if (page.trim().match(/\/20[0-9]{2}$/) == null)
        return;
    
    var ns = $("#p-namespaces .new");
    if (ns.length == 0) {
        console.log("Can't find namespace selector link.");
        return;
    }
    
    ns[0].className = ns[0].className.replace("new", "");
    ns = ns.find("a")[0];
    ns.href = ns.href.replace(
        /w[\/\\]index.php\?title=(.*?)(\/20[0-9]{2}).*$/,
        "wiki/$1");
}

fixTalkArchiveNSLinks();

// The Apple Wiki migration sitenotice link
(function() {
    var url = location.href
        .replace(location.origin, "https://theapplewiki.com")
        .replace("https://theapplewiki.com/w/", "https://theapplewiki.com/");
    var pageName = mw.config.get("wgPageName");
    var categories = mw.config.get("wgCategories");
    if (categories.indexOf("Filesystem") > 0) {
        url = url.replace(pageName, "Filesystem:" + pageName);
    } else if (categories.indexOf("All Key Pages") > 0) {
        url = url.replace(pageName, "Keys:" + pageName);
    }
    $("#siteNotice a[href='https://theapplewiki.com/']")
        .attr("href", url);
})();