משתמש:Mikimik/js/displayLocalInfoInline.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
/* display local information below a page headline */
/* written by [[he:User:Mikimik]]  */

function initDisplayLocalInfoInline()
{
    function historyBox ( action, item, responseText )
    {
        if ( action == "name" ) return "hist";
        if ( action == "url" ) return wgScript + "?title=" + encodeTextToWikiURL(wgPageName) + "&limit=50&action=history";
        if ( action == "pageurl" ) return wgScript + "?title=" + encodeTextToWikiURL(wgPageName) + "&action=history";
        if ( action == "boxready" || action == "toggleready" ) return item;
        if ( action == "waiting" || action == "error" ) return item.appendChild ( document.createTextNode(action == "waiting" ? "." : "ERROR") );

        var histpage = document.createElement("div");
        histpage.innerHTML = responseText;
        histpage = localInfo_FindID ( histpage, "bodyContent" );
        if ( !histpage ) return item.appendChild ( document.createTextNode("ERROR") );
        while ( item.hasChildNodes() ) item.removeChild ( item.firstChild );

        var x = histpage.firstChild;
        while ( x && !/\bmw-history-legend\b/.test(x.className || "") ) x = x.nextSibling;    // find the history legend
        do {
            x = x.nextSibling
            item.appendChild ( x.cloneNode(true) );                                           // copy elements after the history legend
        }
        while ( x.id != "mw-history-compare" );                                               // and up to the history compare form

        if ( typeof(initPartolStatusInEditList) === "function" ) initPartolStatusInEditList( null, "history", item );
        if ( typeof(hideHideRevLinks) == "function" ) hideHideRevLinks();  // hide "hide revision" checkboxes for sysops - from [[w:he:MediaWiki:FixHistPage.js]]
        if ( typeof(bulletedListsToNumberedLists) == "function" ) bulletedListsToNumberedLists ( item );
        if ( typeof(addSizes) == "function" ) addSizes();                  // show byte size difference in history - from [[w:he:MediaWiki:Gadget-DiffBytes.js]]
    }

    function deletedEditsBox ( action, item, responseText )
    {
        if ( action == "name" ) return "deleted";
        if ( action == "url" || action == "pageurl" ) return "/wiki/Special:Undelete/" + encodeTextToWikiURL(wgPageName);
        if ( action == "boxready" || action == "toggleready" ) return item;
        if ( action == "waiting" || action == "error" ) return item.appendChild ( document.createTextNode(action == "waiting" ? "." : "ERROR") );

        var undelete = document.createElement("div");
        undelete.innerHTML = responseText;
        undelete = localInfo_FindID ( undelete, "undelete" );
        if ( !undelete ) return item.appendChild ( document.createTextNode("ERROR") );
        while ( item.hasChildNodes() ) item.removeChild ( item.firstChild );

        item.appendChild ( undelete );
        for ( var x = undelete.firstChild ; x ; x = x.nextSibling )
        {
            if ( x.nodeName == "H2" && x != undelete.firstChild )
            {
                undelete.insertBefore ( document.createElement("hr"), x );
                x.previousSibling.style.height = "4px";
            }
            if ( x.nodeName != "UL" ) localInfo_HideElement ( x );
        }
        var revdelundel = undelete.getElementsByClassName("mw-revdelundel-link");
        for ( var i = 0 ; i < revdelundel.length ; i++ )
            for ( var x = revdelundel[i] ; x ; x = x.previousSibling ) localInfo_HideElement ( x );

        if ( document.getElementsByClassName("mw-warning-with-logexcerpt")[0] )
        {
            var logexcerpt = document.getElementsByClassName("mw-warning-with-logexcerpt")[0];
            var hidelogexcerpt = true;
            for ( var x = logexcerpt.firstChild ; x ; x = x.nextSibling )
                if ( x.nodeName != "UL" ) localInfo_HideElement ( x );
                 else for ( var t = x.firstChild ; t ; t = t.nextSibling )
                         if ( !t.className || /\bmw-logline-delete\b/.test(t.className) ) localInfo_HideElement ( t );
                          else hidelogexcerpt = false;
            if ( hidelogexcerpt ) logexcerpt.style.display = "none";
        }
        if ( !document.getElementById("pagehistory") && document.getElementById("contentSub2") ) document.getElementById("contentSub2").style.display = "none";
        if ( wgAction == "delete" && !wgArticleId && typeof(getUserWarningLinks) == "function" && userDeleteWarnings )
        {
            var lines = undelete.getElementsByTagName("LI");
            for ( var i = 0 ; i < lines.length ; i++ )
                if ( !/\bmw-logline-delete\b/.test(lines[i].className) && lines[i].getElementsByClassName("mw-userlink")[0] )
                {
                    var contributor = lines[i].getElementsByClassName("mw-userlink")[0];
                    contributor.parentNode.insertBefore ( getUserWarningLinks(contributor.firstChild.nodeValue,userDeleteWarnings), contributor.nextSibling );
                }
        }

        if ( !document.getElementById("pagehistory") ) item.style.display = "block";
    }

    function whatLinksHereBox ( action, item, responseText )
    {
        if ( action == "name" ) return "link";
        if ( action == "url" || action == "pageurl" ) return "/wiki/Special:Whatlinkshere/" + encodeTextToWikiURL(wgPageName);
        if ( action == "boxready" || action == "toggleready" ) return item;
        if ( action == "waiting" || action == "error" ) return item.appendChild ( document.createTextNode(action == "waiting" ? "." : "ERROR") );

        var whatlinks = document.createElement("div");
        whatlinks.innerHTML = responseText;
        whatlinks = localInfo_FindID ( whatlinks, "bodyContent" );
        if ( !whatlinks ) return item.appendChild ( document.createTextNode("ERROR") );
        whatlinks.id = item.id + "Div";
        while ( item.hasChildNodes() ) item.removeChild ( item.firstChild );
        item.appendChild ( whatlinks );

        localInfo_HideElement ( localInfo_FindID(whatlinks,"contentSub") );
        localInfo_HideElement ( whatlinks.getElementsByTagName("FORM")[0] );
        localInfo_HideElement ( whatlinks.getElementsByTagName("FIELDSET")[1] );
        if ( typeof(bulletedListsToNumberedLists) == "function" ) bulletedListsToNumberedLists ( whatlinks );
    }

    function contributionsBox ( action, item, responseText )
    {
        if ( action == "name" ) return "cont";
        if ( action == "url" || action == "pageurl" ) return "/wiki/Special:Contributions/" + encodeTextToWikiURL(wgTitle);
        if ( action == "boxready" || action == "toggleready" ) return item;
        if ( action == "waiting" || action == "error" ) return item.appendChild ( document.createTextNode(action == "waiting" ? "." : "ERROR") );

        var cont = document.createElement("div");
        cont.innerHTML = responseText;
        cont = localInfo_FindID ( cont, "bodyContent" );
        if ( !cont ) return item.appendChild ( document.createTextNode("ERROR") );
        cont.id = item.id + "Div";
        while ( item.hasChildNodes() ) item.removeChild ( item.firstChild );
        item.appendChild ( cont );

        localInfo_HideElement ( localInfo_FindID(cont,"contentSub") );
        localInfo_HideElement ( cont.getElementsByTagName("FORM")[0] );
        localInfo_HideElement ( cont.getElementsByClassName("mw-contributions-footer")[0] );

        if ( typeof(initPartolStatusInEditList) === "function" ) initPartolStatusInEditList( null, "contributions", item );
        if ( typeof(markLastChangeContributions) == "function" ) markLastChangeContributions ( cont );
        if ( typeof(bulletedListsToNumberedLists) == "function" ) bulletedListsToNumberedLists ( cont );
    }

    function contributionsBox_Alt ( action, item, responseText )
    {
        if ( action == "url" || action == "pageurl" ) return "/wiki/Special:Contributions/" + window.location.pathname.replace(/\/wiki\/[^:/]+:[^:/]+\//,"");
        return contributionsBox ( action, item, responseText );
    }

    function deletedContributionsBox ( action, item, responseText )
    {
        if ( action == "name" ) return "del";
        if ( action == "url" || action == "pageurl" ) return "/wiki/Special:DeletedContributions/" + encodeTextToWikiURL(wgTitle);
        if ( action == "boxready" || action == "toggleready" ) return item;
        if ( action == "waiting" || action == "error" ) return item.appendChild ( document.createTextNode(action == "waiting" ? "." : "ERROR") );

        var cont = document.createElement("div");
        cont.innerHTML = responseText;
        cont = localInfo_FindID ( cont, "bodyContent" );
        if ( !cont ) return item.appendChild ( document.createTextNode("ERROR") );
        cont.id = item.id + "Div";
        while ( item.hasChildNodes() ) item.removeChild ( item.firstChild );
        item.appendChild ( cont );

        localInfo_HideElement ( localInfo_FindID(cont,"contentSub") );
        localInfo_HideElement ( cont.getElementsByTagName("FORM")[0] );
//        localInfo_HideElement ( cont.getElementsByClassName("mw-contributions-footer")[0] );
        if ( typeof(bulletedListsToNumberedLists) == "function" ) bulletedListsToNumberedLists ( cont );
    }

    function deletedContributionsBox_Alt ( action, item, responseText )
    {
        if ( action == "url" || action == "pageurl" ) return "/wiki/Special:DeletedContributions/" + window.location.pathname.replace(/\/wiki\/[^:/]+:[^:/]+\//,"");
        return deletedContributionsBox ( action, item, responseText );
    }

    function autoFixInfoBox ( action, item, responseText )
    {
        if ( action == "name" ) return "fix";
        if ( action == "url" ) return "/w/index.php?title=" + encodeTextToWikiURL(wgPageName) + "&action=raw&cacheFixDummy=" + wgCurRevisionId;
        if ( action == "pageurl" ) return "#";
        if ( action == "boxready" ) item.style.cssText = "height:1.5em; background-color:#F9F9F9; border:1px solid #AAAAAA; padding:5px; overflow:auto; display:block;";
        if ( action == "boxready" || action == "toggleready" ) return item;
        if ( action == "waiting" || action == "error" ) return item.appendChild ( document.createTextNode(action == "waiting" ? "." : "ERROR") );

        var fixtext = autoStandardizePage(responseText);
        if ( typeof(externalLinkAutoPlace) == "function" ) fixtext += " / " + externalLinkAutoPlace(responseText);
        while ( item.hasChildNodes() ) item.removeChild ( item.firstChild );
        item.appendChild ( document.createTextNode(fixtext || "---") );
    }

    function externalLinksInfoLink ( action, item )
    {
        if ( action == "name" ) return "wikiLinks";
        if ( action == "pageurl" ) return "#";

        item.onclick = function() {
            var span = document.createElement("span");
            span.appendChild ( document.createTextNode(item.firstChild.nodeValue) );
            item.parentNode.replaceChild ( span, item );

            createRemotePagesInfoFrames ( document.getElementById("bodyContent") );
            return false;
        };
    }

    function localInfo_FindID ( item, id )
    {
        if ( item.id == id ) return item;
        for ( var i = 0, x = null ; item.childNodes[i] ; i++ ) if ( x = localInfo_FindID(item.childNodes[i],id) ) return x;
        return null;
    }

    function localInfo_HideElement ( item )
    {
        if ( item )
        {
            if ( item.style ) item.style.display = "none";
             else item.nodeValue = "";
            if ( item.id ) item.id += "-localInfoInline";
        }
    }

    function toggleInfoBox ( id )
    {
        document.getElementById(id).style.display = document.getElementById(id).style.display == "none" ? "block" : "none";
    }

    function createInfoBox ( func )
    {
        var box = document.createElement ("div");
        box.id = func("name") + "LocalInfoBox";
        box.style.cssText = "height:250px; background-color:#F9F9F9; border:1px solid #AAAAAA; padding:5px; overflow:auto; display:none;";
        liPoint.parentNode.insertBefore ( box, liPoint.nextSibling );

        func ( "boxready", box );

        var ajaxObj = sajax_init_object();
        ajaxObj.open ( "GET", func("url"), true );
        ajaxObj.onreadystatechange =
            function()
            {
             try {
                if ( this.readyState != 4 ) func("waiting", box);
                 else if ( this.status != 200 ) func("error", box);
                       else func("done", box, this.responseText);
              }
             catch ( e )
              {
                box.appendChild ( document.createTextNode("displayInline ERROR: " + e.message) );
              }
            };
        ajaxObj.send ( null );
    }

    function createToggleLink ( func )
    {
        var aNode = document.createElement("a");
        aNode.id = func("name") + "LocalInfoToggle";
        aNode.href = func("pageurl");
        aNode.onclick = function() {
                            toggleInfoBox ( func("name") + "LocalInfoBox" );
                            return false;
                        };
        aNode.appendChild ( document.createTextNode(func("name")) );

        var sNode = document.createElement("span");
        sNode.appendChild ( document.createTextNode("[\u200F") );
        sNode.appendChild ( aNode );
        sNode.appendChild ( document.createTextNode("\u200E]") );
        sNode.style.cssText = "margin-" + ( wgUserLanguage == "he" ? "left" : "right" ) + ": 0.5em;";

        liHolder.insertBefore ( sNode, wgUserLanguage == "he" ? null : liHolder.firstChild );

        func ( "toggleready", aNode );
    }

    function displayInline ( func )
    {
        createInfoBox ( func );
        createToggleLink ( func );
    }

 try {
    var liHolder = document.createElement("span");
    liHolder.id = "localInfoTogglesHolder";
    var liPoint = document.getElementById("wikiPreview");
    if ( !liPoint || !liPoint.hasChildNodes() ) liPoint = document.getElementById("wikiDiff");
     else
    {
        liPoint.appendChild ( document.createElement("br") );
        liPoint.lastChild.style.clear = "both";
    }
    if ( liPoint && liPoint.hasChildNodes() )
    {
        liHolder.style.cssText = "font-size:115%;";
        liPoint.appendChild ( liHolder );
    }
     else
    {
        liHolder.style.cssText = "margin-" + ( wgUserLanguage == "he" ? "right" : "left" ) + ":5em; font-size:60%;";
        document.getElementById("firstHeading").appendChild ( liHolder );
        liPoint = document.getElementById("siteSub");
    }

    if ( wgCanonicalSpecialPageName == "Contributions" && /\bsysop\b/.test(wgUserGroups.join(" ")) ) displayInline ( deletedContributionsBox_Alt );
    if ( wgCanonicalSpecialPageName == "DeletedContributions" ) displayInline ( contributionsBox_Alt );
    if ( document.getElementById("t-contributions") )
    {
        if ( /\bsysop\b/.test(wgUserGroups.join(" ")) ) displayInline ( deletedContributionsBox );
        displayInline ( contributionsBox );
    }
    if ( wgNamespaceNumber >= 0 && typeof(createRemotePagesInfoFrames) == "function" ) createToggleLink ( externalLinksInfoLink );
//    if ( wgContentLanguage == "he" && wgArticleId && ( wgNamespaceNumber == 0 || wgNamespaceNumber == 10 ) && wgAction == "view" && !getParamValue("oldid") && !document.getElementsByClassName("redirectText")[0] )
//        displayInline ( autoFixInfoBox );
    if ( wgNamespaceNumber >= 0 ) displayInline ( whatLinksHereBox );
    if ( document.getElementById("contentSub2") && document.getElementById("contentSub2").getElementsByTagName("A")[0] )
    {
        var num = document.getElementById("contentSub2").getElementsByTagName("A")[0].firstChild.nodeValue.replace(/[^0-9]/g,"");
        if ( !num || num < 500 ) displayInline ( deletedEditsBox );
    }
     else if ( wgAction == "delete" && !wgArticleId ) displayInline ( deletedEditsBox );
    if ( wgArticleId && wgAction != "history" ) displayInline ( historyBox );
  }
 catch ( e )
  {
    return;
  }
}

if ( wgPageName != wgMainPageTitle.replace(/ /g,"_") ) addOnloadHook ( initDisplayLocalInfoInline );