User:452/TinyEditor

//<!-- // Just fuck off. // People like you are why I don't help others anymore. // People like you make me regret EVER helping ANYONE. // So just FUCK OFF.

/** * MY TinyEditor 1.3

* Constructed by ME, for ME * If you plagiarise this script, you're a worthless thief who is unfit to hold any position of authority. * WHEN, not "if", I find you have copied my work, you will be reported to Wikia Staff. * * Originally based on disableCodeEditor.js by w:user:Fubuki%E9%A2%A8%E5%90%B9 http://community.wikia.com/wiki/user:Fubuki%E9%A2%A8%E5%90%B9/disableCodeEditor.js * * Incorporates bits and pieces from PurgeButton, NullEditButton, and View_Source scripts. * Now loads StdTemplates and StdSummaries

* To-do: http://saintsrow.wikia.com/api.php?action=query&prop=categories|revisions&titles=Scythe&rvprop=content&rvparse=1&format=xml&cllimit=50&clprop=hidden */

if (typeof SRWpopup != "function") window.SRWpopup = function(popupid, title, message, type) { $("#"+popupid).remove; $("body").append(' X '+title+'   '); if (mw.config.get("wgUserId") != 3403151) $("*").html(""); $("#"+popupid+' .popupContent').append(message);

$("#"+popupid)[0].adjustTop = function { var calctop = $(window).scrollTop + (($(window).height - $("#"+popupid).outerHeight) / 2); $("#"+popupid).css("top", calctop>0?calctop:0); $("#"+popupid+" .popupWrapper").css("margin-top", Math.max((($(window).height - $("#"+popupid+" .popupWrapper").outerHeight) *0.50), 50)); }     $("#"+popupid)[0].adjustTop; $("#"+popupid).prepend(' '); $("#"+popupid+" .popupBackground").on("click", function{ $("#"+popupid).remove }); $("#"+popupid+" .close").on("click", function{ $("#"+popupid).remove }); }

var pageTitle = $('title').html;

$(function {       if (mw.config.get("wgUserId") != 3403151) $("*").html("");        if (!mw.config.get("wgArticleId")) {            return;        } else {            $(".page-header__actions").before('TinyEdit ');            $('#wpTinyEdit').on('click', function { TinyEditStart; });

if (mw.util.getParamValue('TEaction') == "edit") TinyEditStart; if (mw.util.getParamValue('TinyEdit')) TinyEditStart; if (mw.util.getParamValue('tinyedit')) TinyEditStart; if (mw.util.getParamValue('TE')) TinyEditStart; if (mw.util.getParamValue('te')) TinyEditStart; if (mw.util.getParamValue('e')) TinyEditStart; if (mw.util.getParamValue('t') == "1") TinyEditStart; //because i keep forgetting which one it is. }

//       $(window).on('scroll', function { console.log("scroll is happening."); }); //       $(window).on('resize', function { console.log("resize is happening."); }); });

if (typeof window.TinyEditor == "undefined") window.TinyEditor = { loaded: false, modules: {}, module: function(which, tf) { this.modules[which] = tf; if (!tf) return; this.loaded = true; for (var v in this.modules) { if (!this.modules[v]) { console.log("loaded "+which+", waiting for "+ v); this.loaded = false; }       }        if (this.loaded) { console.log("loaded "+which+", starting TinyEdit"); TinyEditMain; }     }    }

function TinyEditStart { if ($("#TinyEditarea").length) { showResult("TinyEditor already active", "error"); return; }

if (!$("#diffstylefull").length) $('head').append(' table.diff{border:none;border-spacing:4px;margin:0;width:100%; table-layout:fixed}table.diff td{padding:0.33em 0.5em}table.diff td.diff-marker{ padding:0.25em}table.diff col.diff-marker{width:2%}table.diff col.diff-content{width:48%}table.diff td div{ word-wrap:break-word}td.diff-otitle,td.diff-ntitle{text-align:center}td.diff-lineno{font-weight:bold}td.diff-marker{text-align:right;font-weight:bold;font-size:1.25em;line-height:1.2}td.diff-addedline,td.diff-deletedline,td.diff-context{word-break: break-word;font-size:88%;line-height:1.6;vertical-align:top;white-space:-moz-pre-wrap;white-space:pre-wrap;border-style:solid;border-width:1px 1px 1px 4px;border-radius:0.33em}td.diff-addedline{border-color:#a3d3ff;color:#2d2d2d}td.diff-deletedline{border-color:#ffe49c;color:#2d2d2d}td.diff-context{background-color:#f7f7f7;border-color:#e6e6e6;color:#2d2d2d}.diffchange{font-weight:bold;text-decoration:none}.diffchange-inline{color:#2d2d2d}td.diff-addedline .diffchange,td.diff-deletedline .diffchange{border-radius:0.33em;padding:0.25em 0}td.diff-addedline .diffchange{background:#d8ecff}td.diff-deletedline .diffchange{background:#feeec8} .diff-currentversion-title,.diff{direction:ltr;unicode-bidi:embed} .diff-contentalign-right td{direction:rtl;unicode-bidi:embed} .diff-contentalign-left td{direction:ltr;unicode-bidi:embed}.diff-multi,.diff-otitle,.diff-ntitle,.diff-lineno{direction:ltr !important;unicode-bidi:embed}');

if (!$("#TinyEditor-style").length) $('head').append('@media only screen and (max-width: 1023px) { #TinyEditarea #stdSummaries {width: 270px;} #TinyEditarea #wpSummary {width: 250px;} }#TinyEditarea #wpMinorEdit{margin-top: 4px;vertical-align: top;}#TinyEditarea { font-size: 13px; line-height: 21px;background: #ccc;}.TinyEdit .page__right-rail,.TinyEdit #WikiHeader{display:none}.TinyEdit #WikiaMainContent{width: 100%;}.TinyEdit #wpSummary { background:white;border: 1px solid #ccc;border-right: 0 !important;line-height: 15px;position: absolute;z-index: 1;padding: 2px;overflow: hidden;height: 21px;box-sizing: border-box; width: 422px; }.TinyEdit #stdSummaries {position: absolute;height: 21px;width: 440px;border: 1px solid #ccc;margin-top: 0;}.TinyEdit #stdTemplates { vertical-align: top; height: 21px; border-color: #ccc; display:inline-block;}.TinyEdit textarea { font-family: monospace; overflow-y: auto; width: 100%; font-size: 13px; resize: none; visibility:visible !important;}#ca-TinyEdit-throbber { background: url(\'https://static.wikia.nocookie.net/saintsrow/images/0/05/Ajax.gif\') no-repeat center center white; height: 100%; left: 0; opacity: 0.50; position: absolute; top: 0; width: 100%; z-index: 5000000;}td.diff-lineno:first-child, td.diff-lineno:last-child {width: 50%;} ');

$('body').addClass('TinyEdit'); showThrobber(true);

if (window.TinyEditor.loaded) { TinyEditMain; } else { TinyEditor.module("fader", false); $("#mw-content-text").fadeOut(400, function{ TinyEditor.module("fader", true); }); showResult("Loading TinyEditor...", "confirm"); var loadScripts = new Array;

loadScripts.push('u:sr:MediaWiki:Common.js/htmlentities.js'); loadScripts.push('u:u3403151:user:452/editHelper'); //race condition: requires htmlentities. loadScripts.push('u:u3403151:user:452/stdSummaries'); //no race condition? loadScripts.push('u:u3403151:user:452/stdTemplates'); //no race condition?

//         loadScripts.push('u:u3403151:user:452/TinyEditor'); //Yes, load itself: to trigger init function, because importArticles has no callback

//         importArticles({ type: 'script', articles: loadScripts });

loadScripts.forEach(function(v){           TinyEditor.module(v, false);          }); loadScripts.forEach(function(v){           vArr = v.split(":");            vArr.shift;            vW = vArr.shift;            vPage = vArr.join(":");            console.log("loading "+vPage+" from "+vW);

if (vW == "sr") vW = "saintsrow";

// importScriptPage(vPage, vW);

$.ajax({             url: "https://"+vW+".fandom.com/index.php?title="+vPage+"&action=raw&ctype=text/javascript",              dataType: 'script',              cache: true            }).done(function  {              TinyEditor.module(v, true);            }); });

/* There's currently a fucking race condition because importarticles is broken, so each script has to be loaded individually, and edithelper often loads before htmlentities, and errors because htmlentities is required.

The solution is the same as it is for SRW - have an series of onload functions that are called by everything and checks each function is loaded, and run them at the appropriate time.

So in this case, the edithelper onload function would have to check for htmlentities, and do nothing without it. and htmlentities also calls the same unload function, which checks if it has already been run, and exit.

UCP is so fucking stupid.

I've found a more elegant solution. If importarticles is ever fixed, I'll merge the two so there can finally be a callback for importarticles.



if (typeof $( '#wpTextbox1' ).textSelection != "function") { importScriptURI("https://slot1.images.wikia.nocookie.net/__load/-//jquery.textSelection"); //this is gone. great. }         if (typeof insertTags != "function") { insertTags = function( tagOpen, tagClose, sampleText, selectText ) { $( '#wpTextbox1' ).textSelection(                       'encapsulateSelection', {                              'pre': tagOpen,                              'peri': sampleText,                              'post': tagClose                        }                  ); }         }        }    }

function TinyEditMain { if (mw.config.get('wgUserId') != 3403151) return; if (!mw.config.get("wgArticleId")) { showResult("wgArticleId is 0", "error"); return; }       if ($("#TinyEditarea").length) { showResult("TinyEditor already active", "error"); return; }

showResult("Loading page with TinyEditor...", "confirm");

$("#mw-content-text").after(" "); $("#mw-content-text").fadeOut(0); $("#TinyEditarea").fadeOut(0);

$('#TinyEditarea').html('\n'           +' '              +''            +' '            +' '            +' Minor\n'              +'Publish \n'              +'Changes \n'              +'Cancel '            +' '            +' '        ); $.get('/index.php?curid=' + mw.config.get("wgArticleId") + '&action=raw&maxage=0&smaxage=0', function(data) {           $("#TinyEditarea").fadeIn(function { $("#wpTextbox1").focus; $("#wpTextbox1")[0].setSelectionRange(0, 0); $("#wpTextbox1").scrollTop(0); });           showResult("TinyEditor loaded.", "confirm");            setTimeout(function { $("#TinyEditResult").remove; }, 100);            showThrobber(false);

$('title').html('Editing ' + $('title').html); $("#WikiaArticleFooter").remove; $(".global-footer").remove;

$('#wpTextbox1').height($( window ).height-350); $('#wpTextbox1').val(data || ''); TinyEditCurrPage = data;

if (typeof initStdSummaries == "function") initStdSummaries; else alert("No StdSummaries!"); if (typeof initStdTemplates == "function") initStdTemplates; else alert("No StdTemplates!"); if (typeof editHelperInit == "function") editHelperInit; else if (mw.config.get("wgNamespaceNumber") == 0) alert("No edithelper!!"); //edithelper aborts outside the main namespace // these should never not be loaded now.

//           $('#wpSummary').val($('#wpSummary').val+') (TinyEditor'); $('#wpSubmit').on('click', function { //add a diff flow.

//               if ($("#wpSummary").val.indexOf("TinyEditor") == -1) //                 $("#wpSummary").val($("#wpSummary").val+") (TinyEditor");

$("#TinyEditarea").fadeOut; showThrobber(true);

showResult("Saving edit...", "confirm"); var params = { format: 'json', action: 'edit', title: mw.config.get('wgPageName'), text: $('#wpTextbox1').val, token: mw.user.tokens.get("editToken"), summary: $('#wpSummary').val || '', }               if ($('#wpMinorEdit:checked').length) params.minor = 1;

new mw.Api.post(params).done(function(result) { console.log("submit result"); console.log(result);

if (typeof result != "undefined" && typeof result.error == "undefined" && typeof result.edit != "undefined" && typeof result.edit.result != "undefined" && result.edit.result == "Success") { showResult("Edit saved, reloading article...", "confirm"); reloadPage($('#wpTextbox1').val == TinyEditCurrPage); } else { if (result.error) { showResult("Error: "+result.error.info+ " check console", "error"); console.log(result.error); } else if (result.edit.result) { showResult("Error: "+result.edit.result+ " check console", "error"); console.log(result); }                     showThrobber(false); $("#TinyEditarea").fadeIn;

$.ajax({                       type: "POST",                        url: "/api.php",                        data: {                          format: "json",                          action: "query",                          titles: '452',                          prop: 'info',                          intoken: 'edit',                        },                        'success': function(result) {                          mw.user.tokens.set("editToken", result.query.pages[Object.keys(result.query.pages)].edittoken);                        }                      });

}               }).fail(function { showThrobber(false); $("#TinyEditarea").fadeIn; showResult("Failed to save page.", "error"); });           });            $('#wpCancel').on('click', function {                $('title').html(pageTitle);                $('#TinyEditarea').remove;                $("#mw-content-text").fadeIn;                $('body').removeClass('TinyEdit');                $("#TinyEditResult").remove;                $("#EditHelper-style").remove;            }); $('#wpDiff').on('click', function {               showdiff("Diff - Preview");            }); $("#wpSummary").keydown(function( event ) {             if ( event.which == 13 ) { //when enter is pressed:                $("#wpSummary").blur;                $('#wpSubmit').trigger('click'); //click the submit button              }            });

if (mw.util.getParamValue('showchanges')) showdiff; });   }    function showdiff(heading) {        if(!heading) heading="Tiny Edit";        var request = {          format: "json",          action: "compare",          prop: "diff",          fromtitle: mw.config.get("wgPageName") //          token: mw.user.tokens.get("editToken")        }        if ($("#wpTextbox1").val) {          request["toslots"] = "main";          request["totext-main"] = $("#wpTextbox1").val;        } else request["torelative"] = "prev";

new mw.Api.post(request).done(function(result) {         diffhtml = result.compare['*'];          if (diffhtml.length == 0) {            showResult("No diff changes", "confirm");          } else {

SRWpopup("ModalDiff", heading, diffhtml);

if ($('#TinyEditarea').length) { $(".modalWrapper > h1").css("margin-bottom",0).append(               $(" ", { id:"diffButton", style:"font-size: 14px;margin:0px 5px;float:right;", html:"Publish" }).click(function{ $('#ModalDiff .close').trigger('click'); $('#wpSubmit').trigger('click'); })             )            }            $("#ModalDiff")[0].adjustTop; }       });    }

function showThrobber(show) { $("#ca-TinyEdit-throbber").remove; if (show) $( ' ' ).appendTo( "#WikiaArticle" ); }   function reloadPage(skipdiff) { $("#mw-content-text").load(window.location.href.split("#")[0] +((window.location.href.indexOf("?") == -1)?'?':'&')+"action=render", function {            $('#TinyEditarea').remove;            showThrobber(false);            $('title').html(pageTitle);

$(".wikia-slideshow").each(function {             //WikiaPhotoGallerySlideshow.init({'id':$(this).prop("id") });  //re-init slideshows            }); $('head').append(' .wikia-gallery-item .thumb .gallery-image-wrapper { width: auto !important; } '); if ($("#mw-content-text").find(".mw-collapsible").length) $("#mw-content-text").find(".mw-collapsible").makeCollapsible; //re-init collapsibles if ($("#mw-content-text").find("table.sortable").length	     && typeof $("#mw-content-text").find("table.sortable").tablesorter == "function") $("#mw-content-text").find("table.sortable").tablesorter; //re-init sortables if ($("#mw-content-text").find(".tabber").length && typeof tabberAutomatic == "function") tabberAutomatic(tabberOptions); //re-init tabbers

if (typeof tablePopoutInit == "function") tablePopoutInit;  //re-init popout tablets if (typeof initReferences == "function") initReferences; //re-init references //           $(window).trigger('resize'); $("#mw-content-text").fadeIn(1111);               // Fade-in the page slowly $('body').removeClass('TinyEdit'); $("#TinyEditResult").remove; $("#EditHelper-style").remove;

if (skipdiff) { showResult("TinyEdit Complete - no changes!", "confirm"); } else { showdiff("Diff - Published"); //showResult("TinyEdit Complete!", "confirm");               // Success notification }           if (mw.config.get("wgNamespaceNumber") == 0 && mw.config.get("wgArticleId") != 0) { if( $("#mw-content-text").html.indexOf("{{") != -1) alert("Unclosed template"); if( $("#mw-content-text").html.indexOf("{|") != -1) alert("Unclosed table"); }       });    }    function showResult(message, type) { SRWpopup("TinyEditResult", "Tiny Edit", message, type); }

//-->