MediaWiki:Gadget-APC.js/loader.js

Fonte: Wikinotícias

Nota: Depois de publicar, deve limpar o cachê do seu navegador para ver as alterações.

  • Firefox e Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Internet Explorer e Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
/**
 * @author: Helder (https://github.com/he7d3r)
 * @license: CC BY-SA 3.0 <https://creativecommons.org/licenses/by-sa/3.0/>
 */

window.APC=window.APC||{},window.APC.coreVersion="0.57",window.APC.rules=window.APC.rules||[],function(e,a,t){"use strict";a.messages.set({"apc-summary-text":" +correções [[WN:Recursos/APC|semiautomáticas]] (v$1/$2/$3)","apc-button-rules-all":"Todas","apc-button-rules-custom":"","apc-button-bug":"Informar um erro","apc-new-bug-title":"[BUG] (v$1/$2/$3) [[$4]]","apc-group":"APC","apc-button-enabled-rule":"$1","apc-button-disabled-rule":"$1 ($2)","apc-disabled-rule":"desativada temporariamente","apc-rules-heading":"Correções","apc-default-rule-name":"Rule","apc-find-and-replace-title":"Localizar:\n$1\n\nSubstituir por:\n$2","apc-experimental":"Em fase experimental","apc-version-info":"","apc-expand-all-text":"Expandir tudo","apc-expand-all-desc":"Expandir todos os itens","apc-collapse-all-text":"Recolher tudo","apc-collapse-all-desc":"Recolher todos os itens","apc-format-text":"Formatar com APC","apc-format-desc":"Formata o código wiki da página de acordo com as regras estabelecidas no código do script","apc-invalid-value":"Invalid value: $1.","apc-no-templates":"where=templates is not available yet","apc-where":'where=$1 on rule "$2"',"apc-dialog-title":"Lista de regras","apc-button-cancel":"Cancelar","apc-button-apply-selected-rules":"Aplicar itens selecionados","apc-dialog-text":"Veja a lista de correções."});var n,l=!1,i=!1,o="",s=!1,r=!1,c={"%%title%%":a.config.get("wgPageName").replace(/_/g," "),"%%fullpagename%%":a.config.get("wgPageName").replace(/_/g," "),"%%pagename%%":a.config.get("wgTitle")},p=function(e){return c[e]},u=function(e){return a.util.escapeRegExp(c[e])},d=function(){var t=[];return e.each(c,function(e){t.push(a.util.escapeRegExp(e))}),RegExp("("+t.join("|")+")","g")},g=function(t,n){var l,i,o,s,r,c,p=a.msg("apc-default-rule-name"),u=e("<ul></ul>").toggle(n||!1);for(l=0,i=t.length;i>l;l+=1)o=t[l],r=o.name||p,c=r.replace(/[ _\-]+/g,"-").replace(/[^\-a-z0-9]+/gi,""),s=e("<li></li>").attr("title",a.msg("apc-find-and-replace-title",o.find,o.replace)).append(e("<input>",{type:"checkbox",name:"corrections",id:"correction-"+c,value:c,checked:"checked"}),e("<label>",{"for":"correction-"+c,text:r})),o.enabled===!1&&s.addClass("apc-disabled").attr("title",a.msg("apc-experimental")),Array.isArray(o.sub)&&o.sub.length&&s.append(g(o.sub)).addClass("apc-list-toggle"),s.appendTo(u);return u},f=function(){var n,l,i,o,s,r;s=e("#apc-search-and-replace-rules"),s.length||(s=e("#mw-content-text")),n="<p>"+a.msg("apc-version-info",t.coreVersion,t.siteRulesVersion,t.userRulesVersion)+"</p>",r=function(){var t=e(this).val()===a.msg("apc-expand-all-text");s.find("ul:not(.apc-main-list)").toggle(t).end().find("li.apc-list-toggle").toggleClass("apc-expanded",t)},l=e('<input type="button" value="'+a.msg("apc-expand-all-text")+'" title="'+a.msg("apc-expand-all-desc")+'"/>').click(r),i=e('<input type="button" value="'+a.msg("apc-collapse-all-text")+'" title="'+a.msg("apc-collapse-all-desc")+'"/>').click(r),o=g(t.rules,!0).on("change","input",function(a){var t=e(a.target),n=t.parent();n.hasClass("apc-list-toggle")&&n.find("ul:first").find("input").prop("checked",t.is(":checked"))}).on("click","li",function(a){a.stopPropagation(),e(a.target).hasClass("apc-list-toggle")&&e(this).toggleClass("apc-expanded").children().filter("ul").toggle()}).addClass("apc-main-list").find(".apc-disabled input").prop("checked",!1).end(),s.empty().append(n).append(l).append(i).append(o)},m=function(){var t={};t[a.msg("apc-button-apply-selected-rules")]=function(){alert("Ops! Este recurso ainda não foi implementado.")},t[a.msg("apc-button-cancel")]=function(){e(this).dialog("close")},e('<div id="apc-dialog-rules"><div id="apc-search-and-replace-rules"></div></div>').prepend(a.msg("apc-dialog-text")).dialog({width:550,height:350,modal:!0,resizable:!0,draggable:!0,closeOnEscape:!0,dialogClass:"apc-dialog",title:a.msg("apc-dialog-title"),close:function(){e(this).dialog("destroy").remove()},buttons:t}),f()},b=function(){var n,l=e("#wpTextbox1"),i=a.msg("apc-summary-text",t.coreVersion,t.siteRulesVersion,t.userRulesVersion),s=e("#wpSummary"),r=function(e){return function(){var a=t.$target.textSelection("getContents");o=a,t.processRules([t.rules[e]]),t.$target.textSelection("setContents",o),o!==a&&(t.addTag(),s.val(s.val()+i))}},c={"APC-rules-all":{label:a.msg("apc-button-rules-all"),action:{type:"callback",execute:function(){var e=t.$target.textSelection("getContents");o=e,t.processRules(t.rules),t.$target.textSelection("setContents",o),o!==e&&(t.addTag(),s.val(s.val()+i))}}}},p={label:a.msg("apc-button-bug"),type:"button",icon:"//upload.wikimedia.org/wikipedia/commons/thumb/3/3b/OOjs_UI_icon_speechBubble-ltr.svg/20px-OOjs_UI_icon_speechBubble-ltr.svg.png",action:{type:"callback",execute:function(){var n=a.util.getUrl("Wikinotícias Discussão:Recursos/APC")+"?"+e.param({action:"edit",section:"new",preloadtitle:a.msg("apc-new-bug-title",t.coreVersion,t.siteRulesVersion,t.userRulesVersion,a.config.get("wgPageName").replace(/_/g," ")),preload:"WP:Scripts/APC/Bug"});window.open(n)}}};if(t.alreadyOnToolbar&&l.wikiEditor("removeFromToolbar",{section:"advanced",group:"APC"}),l.wikiEditor("addToToolbar",{section:"advanced",groups:{APC:{label:a.msg("apc-group"),tools:{"apc-report-a-bug":p}}}}),t.alreadyOnToolbar=!0,t.rules.length){for(n=0;t.rules.length>n;n+=1)c["APC-rules-"+n]={label:t.rules[n].enabled===!1?a.msg("apc-button-disabled-rule",t.rules[n].name):a.msg("apc-button-enabled-rule",t.rules[n].name,a.msg("apc-disabled-rule")),action:{type:"callback",execute:r(n)}};c["APC-rules-custom"]={label:a.msg("apc-button-rules-custom"),action:{type:"callback",execute:function(){a.loader.using("jquery.ui",m)}}},l.wikiEditor("addToToolbar",{section:"advanced",group:"APC",tools:{"apc-rules-heading":{label:a.msg("apc-rules-heading"),type:"select",list:c}}})}},v=function(){e.inArray(a.config.get("wgAction"),["edit","submit"])!==-1?(t.$target=e("#wpTextbox1"),a.loader.using(["user.options","mediawiki.util","jquery.textSelection"],function(){a.user.options.get("usebetatoolbar")==1?a.loader.using("ext.wikiEditor",function(){l=!0,b()}):e(a.util.addPortletLink("p-tb","#",a.msg("apc-format-text"),"#ca-APC",a.msg("apc-format-desc"))).click(function(e){e.preventDefault();var a=t.$target.textSelection("getContents");o=a,t.processRules(t.rules),t.$target.textSelection("setContents",o),o!==a&&t.addTag()})})):(i=!0,f())};t.processRules=function(e){var l,i,c,g,f;for(n||(n=d()),l=0,i=e.length;i>l;l+=1)if(c=e[l],c.enabled!==!1&&(!c.ifhas||typeof c.ifhas=="string"&&o.indexOf(c.ifhas)!==-1||s&&typeof c.ifhas=="function"&&c.ifhas(o)||typeof c.ifhas=="object"&&c.ifhas.test(o))&&(!c.ifnot||typeof c.ifnot=="string"&&o.indexOf(c.ifnot)===-1||s&&typeof c.ifnot=="function"&&!c.ifnot(o)||typeof c.ifnot=="object"&&!c.ifnot.test(o)))if(c.where===void 0||c.where==="anywhere"){if(c.find!==void 0&&c.find!==""&&c.replace!==void 0){if(typeof c.find=="string"?c.find=c.find.replace(n,p):c.find instanceof RegExp&&c.find.source.indexOf("%%")!==-1&&(c.find=RegExp(c.find.source.replace(n,u),(c.find.global?"g":"")+(c.find.ignoreCase?"i":"")+(c.find.multiline?"m":""))),g=c.num===void 0||1>c.num?1:c.num>100?100:c.num,f=o,typeof c.replace=="function")while(g>0)o=o.replace(c.find,c.replace).replace(n,p),g-=1;else{c.replace=c.replace.replace(n,p);while(g>0)o=o.replace(c.find,c.replace),g-=1}f!==o&&a.log(c.find,c.replace)}Array.isArray(c.sub)&&c.sub.length&&t.processRules(c.sub)}else r&&c.where==="templates"?a.log(a.msg("apc-invalid-value",a.msg("apc-no-templates"))):a.log(a.msg("apc-invalid-value",a.msg("apc-where",c.where,c.name||a.msg("apc-default-rule-name"))))},t.addRules=function(a){Array.isArray(a)||(a=[a]),e.merge(t.rules,a),l&&b(),i&&f()},t.removeAllRules=function(){t.rules=[],l&&b(),i&&f()},t.addTag=function(){var a=t.tag;if(a&&!(e("#wpChangeTags").length>0)){var n=e("<input>").attr({id:"wpChangeTags",type:"hidden",name:"wpChangeTags",value:a});e("#editform").prepend(n)}},e(v)}(jQuery,mediaWiki,APC);