মিডিয়াউইকি:Gadget-TemplatePreloader.js

টীকা: সংরক্ষণ করার পর, পরিবর্তনসমূহ তৎক্ষণাৎ নাও দেখাতে পারে। আপনার ব্রাউজারের ক্যাশ কিভাবে এড়াবেন তা জানতে এখানে ক্লিক করুন।
  • ফায়ারফক্স / সাফারি: Shift ধরে রাখা অবস্থায়পুনঃলোড করুন-এ ক্লিক করুন, অথবা Ctrl-F5 বা Ctrl-R (ম্যাক-এ ⌘-R) চাপুন
  • গুগল ক্রোম: Ctrl-Shift-R (ম্যাক-এ ⌘-Shift-R) চাপুন
  • ইন্টারনেট এক্সপ্লোরার: Ctrl ধরে রাখা অবস্থায় Refresh-এ ক্লিক করুন, অথবা Ctrl-F5 চাপুন
  • অপেরা: মেনু → ব্যবস্থাপনাসমূহ-এ যান (ম্যাকে অপেরা → পছন্দসমূহ) এবং এরপর গোপনীয়তা ও সুরক্ষা → ব্রাউজিং-এর তথ্য পরিষ্কার করুন → ক্যাশে করা ছবি ও ফাইলগুলি

অন্যান্য ব্রাউজার সম্পর্কে বিশদ নির্দেশাবলীর জন্য, উইকিপিডিয়া:আপনার ক্যাশে বাইপাস করুন দেখুন।

/* নতুন লেখা যোগ করার সময় টেমপ্লেট:শীর্ষক প্রাকলোড করে */
/* For help, see '''Help:Header preloading script gadget''' */
/*jshint asi:true, eqnull:true, laxbreak:true, forin: false */
/*global mw, $, sajax_init_object */
function preloadHeaderTemplate()
{
    var wpTextbox1 = document.getElementById("wpTextbox1")
    if (wpTextbox1.value == "")
    {
        //fill in header template
        var subpageDepth = 0
        var isSubpage
        var pathToTOC = "" //typically "../"
        var subpageTitle
        var subpageTitleRegExp
        var rawBasePageRequest
        var tocPageTitle
        var beginningOfShortSectionTitle //for example, if tocPageTitle == "Democracy in America/Volume 2", then beginningOfShortSectionTitle == "Volume 2, " - this is used to determine the values for "previous" and "next"
        var rawTocPageRequest //table of contents page
        var rawTocPageWithoutHeader
        
        //title
        var wpTextbox1value = "{" + "{শীর্ষক\n | শিরোনাম  = "
        if (mw.config.get('wgTitle').indexOf("/") != -1) //a slash could indicate that it's a subpage
        {
            rawBasePageRequest = new XMLHttpRequest()
            //determine where the base page name ends and where the subpage name begins
            for (var slashPosition = mw.config.get('wgTitle').indexOf("/"); slashPosition != -1; slashPosition = mw.config.get('wgTitle').indexOf("/", slashPosition + 1))
            {
                rawBasePageRequest.open("GET", mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + mw.config.get('wgTitle').substr(0, slashPosition) + "&action=raw", false)
                rawBasePageRequest.send(null)
                if (rawBasePageRequest.responseText != "") //base page found
                {
                    isSubpage = true
                    break
                }
            }
        }
        if(isSubpage) {
            wpTextbox1.value = '<pages index="ফাইল" from= to= header=1/>'
        }
        else {
            wpTextbox1.value = '<pages index="ফাইল" from= to= header=প্রচ্ছদ/>\n{{page break}}\n<pages index="ফাইল" from= to=/>\n{{page break}}'
        }
    }
}

/* Preload Template:Textinfo when starting a discussion page */
function preloadTextinfoTemplate()
{
    var wpTextbox1 = document.getElementById("wpTextbox1")
    if (wpTextbox1.value == "" && !document.URL.match('&section=new') )
    {
        wpTextbox1.value = "{" + "{বার্ষিক পাঠকসংখ্যা}}\n"
    }
}


// Try to fill field when creating an author page. Fields always filled, are
// lastname, firstname, lastinitial, wikipedia. Birth/Death year filled iff an
// article is available on wp:en. Try also to avoid duplicate author:
// by creating a redirect if the wikipedia is non empty, its title
// is different from the current Author:title and an Author:new_title
// exists.
window.author_v2 = {

check_redirect : function (title, text_box)
{
    var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath')
        + "/api.php?format=xml&action=query&prop=info&titles="
        + encodeURIComponent(title);
    // FIXME: Use of "sajax_init_object" is deprecated. Sajax is deprecated, use jQuery.ajax or mediawiki.api instead.
    var request = sajax_init_object();
    request.open('GET', url, true);
    request.onreadystatechange = function () {
        if (request.readyState == 4) {
            var xml = request.responseXML;
            if (xml == null) return ;
            var page = xml.getElementsByTagName( "page" )[0];
            if (page.getAttribute("missing") != "")
               text_box.value = '#REDIRECT [[' + title + ']]';
        }
    };
    request.send(null);
},

author_fill_callback : function (data)
{
    try {
        var wpTextbox1 = document.getElementById("wpTextbox1");
        if (wpTextbox1 && !data.query.pages["-1"]) {
            for (var ids in data.query.pages) {
                wpTextbox1.value = wpTextbox1.value.replace(/( *\\| *উইকিপিডিয়া *= *)/, "$1" + data.query.pages[ids].title);
                var cats = data.query.pages[ids].categories;
                for (var i = 0; i < cats.length; ++i) {
                    var m = cats[i].title.match(/বিষয়শ্রেণী:(\d+)-এ মৃত্যু/);
                    if (m)
                        wpTextbox1.value = wpTextbox1.value.replace(/( *\\| *মৃত্যুর_বছর *= *)/, "$1" + m[1]);
                    m = cats[i].title.match(/বিষয়শ্রেণী:(\d+)-এ জন্ম/);
                    if (m)
                        wpTextbox1.value = wpTextbox1.value.replace(/( *\\| *জন্মের_বছর *= *)/, "$1" + m[1]);
                }
                break;
            }
            // This can undo all the above works by preferring to create a redirect to an existing author:
            window.author_v2.check_redirect('লেখক:' + data.query.pages[ids].title, wpTextbox1);
       }
    }
    catch (err) { }
},

create_script_obj : function (url)
{
    var scriptObj = document.createElement("script");
    scriptObj.setAttribute("type", "text/javascript");
    scriptObj.setAttribute("src", url);
    document.body.appendChild(scriptObj);
},

split_title : function ()
{
    return mw.config.get('wgTitle').replace(/ \(.*\)/, "").split(" ");
},

get_special_word_pos : function (words)
{
    var i;
    for (i = 0; i < words.length; ++i) {
        if (words[i] == 'van' || words[i] == 'von' ||
            words[i] == 'le' || words[i] == 'de') {
           return i;
        }
    }
    return -1;
},

/* Preload Template:Author when starting an author page, derived from [[User:Remember the dot]] code */
preloadAuthorTemplate : function()
{
    var wpTextbox1 = document.getElementById("wpTextbox1")
    if (wpTextbox1.value != "")  return;

    // try to figure out what value we can fill, broken in some case because
    // it's difficult to handle name like Tom Van Moore but Tom van Moore is
    // handled correctly.
    var words = window.author_v2.split_title();

    wpTextbox1.value  = "{" + "{লেখক}}\n\n" +
                        "==সাহিত্যকর্ম==\n" +
                        "*\n\n" +
                        "{{PD-India}}\n" +
                        "{{কর্তৃপক্ষ নিয়ন্ত্রণ}}\n\n";

    var base_url = "//bn.wikipedia.org" + mw.config.get('wgScriptPath');

    var url = base_url + "/api.php?format=json&redirects"
        + "&callback=window.author_v2.author_fill_callback&action=query&prop=categories&cllimit=20&titles="
        + encodeURIComponent(mw.config.get('wgTitle'));

    window.author_v2.create_script_obj(url);
}

}


// Preload Template:Process header when starting a project or help page
// Simple preloader based on the preload code for Template:Textinfo
function preloadProcessHeaderTemplate()
{
    var wpTextbox1 = document.getElementById("wpTextbox1")
    if (wpTextbox1.value == "" && !document.URL.match('&section=new') )
    {
        wpTextbox1.value = "{" + "{process header\n | title    = \n | section  = \n | previous = \n | next     = \n | shortcut = \n | notes    = \n}}\n"
    }
}


// Preload Template:Portal header when starting a portal page
// Simple preloader based on the preload code for Template:Textinfo
function preloadPortalHeaderTemplate()
{
    var wpTextbox1 = document.getElementById("wpTextbox1")
    if (wpTextbox1.value == "" && !document.URL.match('&section=new') )
    {
        wpTextbox1.value = "{" + "{portal header\n | title     = \n | class     = \n | subclass1 = \n | reviewed  = \n | shortcut  = \n | notes     = \n}}\n\n==কর্মকান্ড==\n\n"
    }
}

// Preload Template:Portal review when starting a portal discussion page
// Simple preloader based on the preload code for Template:Textinfo
function preloadPortalReviewTemplate()
{
    var wpTextbox1 = document.getElementById("wpTextbox1")
    if (wpTextbox1.value == "" && !document.URL.match('&section=new') )
    {
        wpTextbox1.value = "{" + "{portal review\n | class      = \n | subclass1  = \n | subclass2  = \n | classifier = \n | reviewer   = \n | notes      = \n}}\n"
    }
}


// Preload Template:Translation header when starting a translation page
// Simple preloader based on the preload code for Template:Textinfo
function preloadTranslationHeaderTemplate()
{
    var wpTextbox1 = document.getElementById("wpTextbox1")
    if (wpTextbox1.value == "" && !document.URL.match('&section=new') )
    {
        wpTextbox1.value = "{" + "{অনুবাদের শীর্ষক\n | শিরোনাম  = \n | লেখক   = \n | অনুচ্ছেদ  = \n | পূর্ববর্তী  = \n | পরবর্তী  = \n | বছর  = \n | ভাষা  = \n | আসল  = \n | টীকা   = \n}}\n" 
    }
}


// Preload Template:Publisher header when starting a publisher page
// Simple preloader based on the preload code for Template:Textinfo
function preloadPublisherHeaderTemplate()
{
    var wpTextbox1 = document.getElementById("wpTextbox1")
    if (wpTextbox1.value == "" && !document.URL.match('&section=new') )
    {
        wpTextbox1.value = "{" + "{প্রকাশক শীর্ষক}}\n\n;প্রকাশনা\n{" + "{Wikidata list|sparql=\nSELECT ?item {\n?item wdt:P123 wd:{" + "{#invoke:Wikibase|id}}; wdt:P407 wd:Q9610; wdt:P1957 [].\n}\n|columns=item,label,P577,P50,P655,P1957\n|row_template=প্রকাশক সংস্করণ সারি\n|skip_table=1\n|freq=30\n|sort=P577\n}}\n{" + "{Wikidata list end}}" 
    }
}

// Preload Template:Work header when starting a work page
// Simple preloader based on the preload code for Template:Textinfo
function preloadWorkHeaderTemplate()
{
    var wpTextbox1 = document.getElementById("wpTextbox1")
    if (wpTextbox1.value == "" && !document.URL.match('&section=new') )
    {
        wpTextbox1.value = "{" + "{রচনা শীর্ষক}}\n\n;সংস্করণ\n{" + "{Wikidata list|sparql=\nSELECT ?item ?label WHERE {\nSERVICE wikibase:label { bd:serviceParam wikibase:language \"bn\". } \n?item wdt:P31 wd:Q3331189;\nwdt:P629 wd:{" + "{#invoke:Wikibase|id}};\nwdt:P407 wd:Q9610.\n{?item wdt:P1957 [].} UNION {?item wdt:P1433 ?item2. ?item2 wdt:P1957 [].}\noptional { ?item rdfs:label ?label_ . filter(lang(?label_)=\"bn\") bind(concat(\":d:\",strafter(str(?item),str(wd:)),\"{\",\"{!}\",\"}\",?label_) as ?label1) }\noptional\n{\n[] schema:about ?item; schema:isPartOf <https://bn.wikisource.org/>; schema:name ?label__ .\n?item rdfs:label ?label_ . filter(lang(?label_)=\"bn\") bind(concat(?label__,\"{\",\"{!}\",\"}\",?label_) as ?label2)\n}\nbind(coalesce(?label2,?label1) as ?label)\n}\n|columns=item,?label,P577,P655,P98,P1433,P1957,P123\n|row_template=রচনা সংস্করণ সারি\n|skip_table=1\n|freq=30\n|sort=P577\n}}\n{" + "{Wikidata list end}}"
    }
}

// Main preloader loading code:
if (mw.config.get('wgAction') == "edit")
{
    switch (mw.config.get('wgNamespaceNumber'))
    {
        case 0: //main
            $(preloadHeaderTemplate)
            break
        case 1: //Talk
            $(preloadTextinfoTemplate)
            break
        case 4: //Wikisource
            $(preloadProcessHeaderTemplate)
            break
        case 12: //Help
            $(preloadProcessHeaderTemplate)
            break
        case 106: //Portal
            $(preloadPortalHeaderTemplate)
            break
        case 107: //Portal talk
            $(preloadPortalReviewTemplate)
            break
        case 100: //Author
            $(window.author_v2.preloadAuthorTemplate)
            break
        case 114: //Translation
            $(preloadTranslationHeaderTemplate)
            break
        case 108: //Publisher
            $(preloadPublisherHeaderTemplate)
            break
        case 110: //Work
            $(preloadWorkHeaderTemplate)

    }
}