MediaWiki:Gadget-contentFeatured.js

Origem: Wikipédia, a enciclopédia livre.

Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.

  • Firefox / 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 / Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5
  • Opera: Pressione Ctrl-F5.
/**
 * Content featured (alpha version)
 * Creates and closes nominations to content featured in ptwikipdia
 *
 * @author [[pt:User:!Silent]]
 * @date 24/nov/2013
 * @update 13/aug/2020
 * @source https://github.com/Nevallem/mw-gadget-contentFeatured
*/
/* jshint laxbreak: true */
/* global $, jQuery, mw */

!function(){"use strict";mw.messages.set({"cf-verifying":"Verificando...","cf-summarySufix":"usando um [[MediaWiki:Gadget-contentFeatured.js|gadget]]","cf-alertTitle":"Aviso","cf-button-cancel":"Cancelar","cf-button-OK":"OK","cf-button-next":"Prosseguir","cf-button-yes":"Sim","cf-button-no":"Não","cf-button-create":"Criar","cf-status-titlePrefix":"Status","cf-status-done":"FEITO","cf-status-finished":"Finalizado","cf-status-getContentPage":'Obtendo o conteúdo da página "$1"',"cf-status-error":"ERRO","cf-status-unknownError":"desconhecido","cf-status-create-title":"criando a candidatura","cf-status-create-creatingPoll":"Criando a página da votação","cf-status-create-page":'Adicionando a predefinição "\{\{Candidato a destaque/bom}}" na página "$1"',"cf-status-create-list":'Adicionando a votação em "Wikipédia:Escolha do artigo em destaque/Lista"',"cf-status-close-title":"encerrando a votação","cf-status-close-discussion":'Removendo a predefinição "\{\{candidato a destaque/bom}}" da discussão da página',"cf-status-close-poll":'Alterando a predefinição "\{\{EAD não concluída}}" pela "\{\{Resultado EAD}}" em "$1"',"cf-status-close-list":"Removendo a página da lista de candidaturas","cf-status-close-normal-addToRepoveList":"Adicionando a página à lista de candidaturas reprovadas","cf-create-new":"Criar nova candidatura","cf-create-pageName":"Nome da página","cf-create-argumentation":"Argumentação","cf-create-notExist":"A página não existe","cf-create-autorevRequires":'Você precisa ser um <a href="/wiki/WP:AREV">autorrevisor</a> para apresentar uma nova candidatura.',"cf-create-abort":"Deseja realmente cancelar?","cf-create-editFail":"Houve um problema entre as edições","cf-create-success":"A candidatura foi criada com sucesso","cf-create-wait":"A candidatura da página foi recusada a menos de trinta dias","cf-create-alreadyExists":"A candidatura para esta página já existe e está em andamento","cf-create-archiving":"Arquivando a votação anterior","cf-create-alreadyFeatured":"A página já está destacada.","cf-create-alreadyGood":'O artigo já é "bom".',"cf-create-type":"Tipo da candidatura","cf-create-type-0":"Destaque","cf-create-type-1":"Bom","cf-create-summary-poll":'Criação de uma nova candidatura para [[WP:artigo $1|artigo $1]] da página "[[$2]]"',"cf-create-summary-page":'Adicionando a predefinição "\{\{Candidato a destaque}}"',"cf-create-summary-list":'Adicionando a página "[[$1]]"',"cf-create-summary-archive":"Arquivando a votação","cf-close-title":"Encerrar a votação","cf-close-cantClose":"Ainda não é possível fechar esta votação.","cf-close-end":"Finalizar","cf-close-alreadyClosed":"A votação já foi encerrada.","cf-close-button":"encerrar votação","cf-close-action":"Escolha uma ação","cf-close-stop":"Interromper","cf-close-stopJustification":"Justificativa","cf-close-summary-discussion":'Removendo a predefinição "\{\{Candidato a destaque/bom}}"',"cf-close-summary-poll":"Finalizando votação","cf-close-summary-list":'Retirando a página "[[$1]]" da lista',"cf-close-summary-addToRepoveList":'Adicionando a página "$1" à lista'});var e,a=new mw.Api;function t(){this.summarySufix=", "+this.message("cf-summarySufix"),this.localStorage="undefined"!=typeof localStorage&&localStorage}t.prototype={message:function(){return mw.message.apply(this,arguments).plain()},refresh:function(e){e?location.href=e:location.reload()},dialog:function(e,a){var t=$('<div class="cf-dialog ui-widget"></div>').append(e.content);$(".cf-dialog").length&&!a&&$(".cf-dialog").each(function(){$(this).dialog("close")}),e.modal||(e.modal=!0),$.extend(e,{open:function(){$(".ui-dialog-titlebar-close").hide()},close:function(){t.dialog("destroy").remove()}}),t.dialog(e)},alert:function(a,t,o){var s,c={};c[e.message("cf-button-OK")]=function(){$(this).dialog("close")},s={title:e.message("cf-alertTitle"),content:a,dialogClass:"cf-alert",width:"auto",height:"auto",buttons:c},$.isPlainObject(t)&&$.extend(s,t),e.dialog(s,o)},editPage:function(t,o){var s=$.Deferred(),c=function(c){e.status.log(t),"function"==typeof o.text&&(o.text=o.text(c)),void 0!==o.getText&&delete o.getText,o.watchlist="preferences",o.summary=o.summary+e.summarySufix,o.minor=!0,o.done={success:o.done,apiError:function(a){e.status.log("error","object"==typeof a?a.code:a)},unknownError:function(a){e.status.log("error",e.message("cf-status-unknownError"))}},a.editPage(o).done(function(){s.resolve()})};return"string"==typeof o.getText||$.isFunction(o.text)?(e.status.log(e.message("cf-status-getContentPage",o.getText||o.title||mw.config.get("wgPageName").replace(/_/g," "))),a.getCurrentPageText(o.getText||o.title).done(function(e){c(e)})):c(),s.promise()},getEndPoll:function(e,a,t){var o=/\d+ até [aà]s (.+\d+)/.exec(e.replace(/<section.+>\b/g,""));return a=a||!1,o=[(o=("string"==typeof o?o:o&&o[1]||e).replace(/(\'|de\b)/g,"").replace(/\s{2,}/g," ").replace(/(\d+?)[\:h](\d+)(min)? UTC/,"$1:$2").split(" "))[1],{janeiro:"jan",fevereiro:"feb","março":"mar",abril:"apr",maio:"may",junho:"jun",julho:"jul",agosto:"aug",September:"sep",October:"oct",November:"nov",December:"dec"}[o[2]],o[3],o[0]].join(" ")+" UTC",o=new Date(o).getTime()-(a?1296e6:0),t?(o=new Date(o)).toGMTString().split(" ")[4].replace(/(\d+):(\d+)\:\d+/,"$1h$2min")+" "+[o.getDate()+(1===o.getDate()?"º":""),mw.config.get("wgMonthNames")[o.getMonth()+1],o.getFullYear()].join(" de ")+" UTC":o},run:function(a,t){var o="cf-"+a+"-";$.when.apply(this,Array.prototype.slice.call(arguments,2)).then(function(){e.status.log(e.message("cf-status-finished")),e.localStorage&&(e.localStorage[o+"success"]=!0),$(window).off("beforeunload"),e.refresh(mw.util.getUrl("Wikipédia:Escolha do artigo em destaque/"+t))},function(){e.alert(e.message(o+"editFail"))})}},(e=new t).status={},e.status.log=function(a,t){var o="",s="error"===a;-1!==$("#cf-status").html().lastIndexOf("...")&&(o+="<b>"+(s?e.message("cf-status-error")+" ("+t+")":e.message("cf-status-done"))+o+"</b><br />"),s||(o+=a+(a!==e.message("cf-status-finished")?"...":".")),$("#cf-status").append(o)},e.status.open=function(a){var t={},o=function(){$(".cf-dialog").eq(0).dialog("close"),$(window).off("beforeunload")};t[e.message("cf-button-cancel")]=function(){if(-1!==$(this).html().lastIndexOf(e.message("cf-status-error")))return o();t.alertButtons={},t.alertButtons[e.message("cf-button-yes")]=function(){$(this).dialog("close"),o()},t.alertButtons[e.message("cf-button-no")]=function(){$(this).dialog("close")},e.alert(e.message("cf-create-abort"),{modal:!1,buttons:t.alertButtons},!0)},e.dialog({title:e.message("cf-status-titlePrefix")+": "+a,content:'<div id="cf-status"><div>',width:"700px",buttons:t})},e.create={},e.create.isInvalid=function(a){$("#cf-create-page").addClass("cf-missing").val(""),$("#cf-create-page-status").addClass("cf-create-page-invalid").html(a),delete e.create.pageName},e.create.alreadyExists=function(a){var t=(new Date).getTime(),o=e.getEndPoll(a),s=/\{\{Resultado EAD\|.+\|tipo=(\d)/.exec(a),c=-1!==a.indexOf("\{\{Candidatura interrompida|")||-1!==a.indexOf("\{\{Resultado EAD|data=");s?"1"===s[1]?e.create.isInvalid(e.message("cf-create-alreadyFeatured")):"2"===s[1]&&e.create.isInvalid(e.message("cf-create-alreadyGood")):!c&&o>t?e.create.isInvalid(e.message("cf-create-alreadyExists")):c&&(-1!==a.indexOf("=== \{\{Voto artigo destacado}} ===")&&o+2592e6>t||-1===a.indexOf("=== \{\{Voto artigo destacado}} ===")&&e.getEndPoll(a,!0)+2592e6>t)?e.create.isInvalid(e.message("cf-create-wait")):($("#cf-create-page").removeClass("cf-missing"),$("#cf-create-page-status").addClass("cf-create-page-OK").html("OK"))},e.create.createButtonClick=function(){var a=$('input[name="cf-create-type"]');$(".cf-create-field").each(function(){""===$(this).val()?$(this).addClass("cf-missing").on("keypress",function(){""!==$(this).val()&&$(this).removeClass("cf-missing")}):$(this).removeClass("cf-missing")}),a.eq(0).prop("checked")||a.eq(1).prop("checked")||($("#cf-create-type").addClass("cf-missing"),a.each(function(){$(this).on("change",function(){""!==$(this).val()&&$("#cf-create-type").removeClass("cf-missing")})})),$("#cf-create *").hasClass("cf-missing")||(e.create.type="0"===$('input[name="cf-create-type"]:checked').val()?"destaque":"bom",e.create.argumentation=$("#cf-create-argumentation").val(),e.create.pageName=$("#cf-create-page").val(),e.create.run())},e.create.verifyPage=function(t){t.removeClass("cf-missing"),$("#cf-create-page-status").show().removeClass("cf-create-page-invalid cf-create-page-OK").html(e.message("cf-verifying")),e.create.verifyingStatus="processing",a.getCurrentPageText(t.val()).done(function(o){e.create.pageName=t.val(),e.create.verifyingStatus="done",void 0!==o?a.getCurrentPageText("Wikipédia:Escolha do artigo em destaque/"+t.val()).done(function(a){void 0!==a?(e.create.pollExist=!0,e.create.alreadyExists(a)):(e.create.pollExist=!1,t.removeClass("cf-missing"),$("#cf-create-page-status").addClass("cf-create-page-OK").html("OK"))}):e.create.isInvalid(e.message("cf-create-notExist"))})},e.create.archive=function(t){var o;return t||(t=1,e.create.apiDeferred=$.Deferred()),o="Wikipédia:Escolha do artigo em destaque/"+e.create.pageName+"/"+t++,a.getCurrentPageText(o).done(function(s){void 0===s?a.post({action:"move",from:o.replace(/\/\d*$/,""),to:o,reason:e.message("cf-create-summary-archive")+e.summarySufix,token:mw.user.tokens.get("csrfToken")}).done(function(){e.create.apiDeferred.resolve()}).fail(function(a){e.status.log("error",a)}):e.create.archive(t)}),e.create.apiDeferred.promise()},e.create.prompt=function(){var a={};a[e.message("cf-button-create")]=function(){"done"!==e.create.verifyingStatus||e.create.pageName&&e.create.pageName!==$("#cf-create-page").val()||e.create.createButtonClick($(this))},a[e.message("cf-button-cancel")]=function(){$(this).dialog("close")},e.dialog({title:e.message("cf-create-new"),width:"675px",height:"auto",content:'<div id="cf-create"><label for="cf-create-page" class="cf-box">'+e.message("cf-create-pageName")+': <input type="text" id="cf-create-page" class="cf-create-field" /> <span id="cf-create-page-status"></span></label><div id="cf-create-type" class="cf-box">'+e.message("cf-create-type")+': <label><input type="radio" name="cf-create-type" value="0" />'+e.message("cf-create-type-0")+'</label><label><input type="radio" name="cf-create-type" value="1" />'+e.message("cf-create-type-1")+'</label></div><label for="cf-create-argumentation" class="cf-box">'+e.message("cf-create-argumentation")+': <textarea style="height:200px; width:100%" id="cf-create-argumentation" class="cf-create-field"></textarea></label></div>',buttons:a}),$("#cf-create-page").val($('#cf-create-open input[type="text"]').val().split("/")[1]||"").blur(function(){-1===$.inArray($(this).val(),["",e.create.pageName])?e.create.verifyPage($(this)):""===$(this).val()&&$("#cf-create-page-status").hide()}).trigger("blur")},e.create.doEdits=function(){var a=e.create.pageName;e.run("create",a,e.editPage(e.message("cf-status-create-creatingPoll"),{title:"Wikipédia:Escolha do artigo em destaque/"+a,getText:"Predefinição:EAD/Nova_votação",text:function(a){return"bom"===e.create.type&&(a=a.replace(/(=== \{\{Voto artigo destacado}} ===(.|\n)*)(?=\=== \{\{Voto artigo bom}} ===)/,"")),a.replace(/\* Indicação para: [^\n]+/,"* Indicação para: artigo "+e.create.type+"\n\n"+e.create.argumentation.trim()).replace(/<\/?includeonly>/g,"")},summary:e.message("cf-create-summary-poll",e.create.type,a)}),e.editPage(e.message("cf-status-create-page",a),{title:a,prependtext:"\{\{Candidato a "+e.create.type+"}}\n",summary:e.message("cf-create-summary-page")}),e.editPage(e.message("cf-status-create-list"),{title:"Wikipédia:Escolha do artigo em destaque/Lista",text:function(e){return e.replace(/(!data-sort.+AB[.\n]+)([^\}]+)/,"$1\{\{#invoke:ECD|link|"+a+"}}\n$2")},summary:e.message("cf-create-summary-list",a)}))},e.create.run=function(){$(window).on("beforeunload",function(){return!0}),e.status.open(e.message("cf-status-create-title")),e.create.pollExist?(e.status.log(e.message("cf-create-archiving")),e.create.archive().done(function(){e.create.doEdits()})):e.create.doEdits()},e.close={},e.close.prompt=function(){var a,t={};-1===mw.config.get("wgCategories").join(",").search(/(rep|ap)rovadas/)?(t[e.message("cf-button-next")]=function(){"none"!==(a=$("#cf-close-stopPoll-justification")).css("display")&&""===a.val()&&a.addClass("cf-missing").on("keypress",function(){""!==$(this).val()&&$(this).removeClass("cf-missing")}),"stop"===$('input [nmae="cf-close-action"]').val()?e.close.edits.stop():e.close.end.prompt()},t[e.message("cf-button-cancel")]=function(){$(this).dialog("close")},e.dialog({title:e.message("cf-close-title"),width:"500px",height:"auto",content:'<div id="cf-close">'+e.message("cf-close-action")+':<label class="cf-box"><input type="radio" name="cf-close-action" value="end" /> '+e.message("cf-close-end")+'</label><label class="cf-box"><input type="radio" name="cf-close-action" value="stop" /> '+e.message("cf-close-stop")+'</label><textarea id="cf-close-stopPoll-justification" placeholder="'+e.message("cf-close-stopJustification")+'"></textarea></div>',buttons:t}),$('input[name="cf-close-action"]').on("change",function(){"stop"===$(this).val()?"none"===(a=$("#cf-close-stopPoll-justification")).css("display")?a.show("slow"):a.hide("slow").val(""):a instanceof jQuery&&a.hide("slow").val("")})):e.alert(e.message("cf-close-alreadyClosed"))},e.close.edits={},e.close.edits.featured=function(){},e.close.edits.good=function(){},e.close.edits.normal=function(a){var t,o=e.close.pageName,s=new Date,c={featured:"destacado",good:"bom",normal:"normal"},i=" (";for(t in a)if(a[t]){if("0"===a[t]?i+="nenhum":i+=a[t],i+=" voto"+(a[t]>1?"s":"")+" para artigo "+c[t],"normal"===t)break;i+="good"===t?" e ":", "}i+=") em "+(new Date).toLocaleString().replace(/.+, (.+)\s\d.+/,"$1")+" (UTC)",e.editPage(e.message("cf-status-close-poll","Wikipédia:Escolha do artigo em destaque/"+o),{text:function(a){return a.replace(/\{\{EAD não concluída.+/,"\{\{Resultado EAD|data="+e.getEndPoll(a,e.getEndPoll(a)<(new Date).getTime()&&"good"===t,!0)+"}}").replace(/<!-- \{\{Resultado EAD\/2}}.+/,"\{\{Resultado EAD/2}}")},summary:e.message("cf-close-summary-poll")}).done(function(){e.editPage(e.message("cf-status-close-discussion"),{title:"Talk:"+o,text:function(e){return e.replace(/\{\{Candidato a destaque\}\}/,"")},summary:e.message("cf-close-summary-discussion")}).done(function(){e.editPage(e.message("cf-status-close-list"),{title:"Wikipédia:Escolha do artigo em destaque/Lista",text:function(e){return e.replace(new RegExp("\{\{.+/Link."+o+"\\|.+\n"),"")},summary:e.message("cf-close-summary-list",o)}).done(function(){e.editPage(e.message("cf-status-close-normal-addToRepoveList"),{title:"Wikipédia:Escolha do artigo em destaque/Candidaturas reprovadas "+s.getFullYear(),text:function(e){return e.replace(/(==.+==)\n/,"$1\n* [[Wikipédia:Escolha do artigo em destaque/"+o+"|]]"+i+"\n")},summary:e.message("cf-close-summary-addToRepoveList",o)}).done(function(){e.status.log(e.message("cf-status-finished")),e.localStorage&&(e.localStorage["cf-close-success"]=!0),$(window).off("beforeunload"),e.refresh(mw.util.getUrl("Wikipédia:Escolha do artigo em destaque/"+o))})})})})},e.close.edits.stop=function(){},e.close.end={},e.close.end.getVotes=function(a){var t,o,s={featured:/(=== \{\{Voto artigo destacado}} ===(.|\n)*)(?=\=== \{\{Voto artigo bom}} ===)/,good:/(=== \{\{Voto artigo bom}} ===(.|\n)*)(?=\=== \{\{Voto artigo normal}} ===)/,normal:/(=== \{\{Voto artigo normal}} ===(.|\n)*)(?=\== Comentários e sugestões ==)/};for(t in"bom"===e.close.type&&delete s.featured,s)s[t]&&(o=s[t].exec(a)[0],s[t]=-1!==o.search(/\n#/)?o.split(/\n#[^:\n]/).length-1:"0");return s},e.close.end.getResult=function(a,t){return"bom"===e.close.type?a.good>=(t?5:7)&&a.good/(a.good+a.normal)>=.75?"good":"normal":a.featured+a.good<7?"normal":a.featured/(a.featured+a.good+a.normal)>=.75?"featured":(a.featured+a.good)/(a.featured+a.good+a.normal)>=.75?"good":"normal"},e.close.end.prompt=function(){var t,o,s,c,i,n={};n[e.message("cf-button-cancel")]=function(){$(this).dialog("close")},e.alert(e.message("cf-verifying"),{width:"250px",buttons:n}),a.getCurrentPageText().done(function(a){if(e.close.type=/\* Indicação para: artigo (.+)/.exec(a)[1],c=e.close.end.getVotes(a),s=e.getEndPoll(a),i=(new Date).getTime(),"bom"===e.close.type&&s>i){if(t=e.getEndPoll(a,!0),o=t<i&&s>i&&(c.good>=5||0===c.normal),t>i||!o)return void e.alert(e.message("cf-close-cantClose"))}else if(s>i)return void e.alert(e.message("cf-close-cantClose"));e.close.pageName=mw.config.get("wgPageName").split("/")[1],e.status.open(e.message("cf-status-close-title")),e.close.edits[e.close.end.getResult(c,o)](c)})},e.init=function(){var a=mw.config.get("wgPageName");e.localStorage&&e.localStorage["cf-create-success"]&&(mw.notify(e.message("cf-create-success")),delete e.localStorage["cf-create-success"]),"Wikipédia:Escolha_do_artigo_em_destaque"===a?$('#cf-create-open input[type="submit"]').click(function(a){a.preventDefault(),-1!==$.inArray("autoreviewer",mw.config.get("wgUserGroups"))||-1!==$.inArray("eliminator",mw.config.get("wgUserGroups"))||-1!==$.inArray("sysop",mw.config.get("wgUserGroups"))?e.create.prompt():e.alert(e.message("cf-create-autorevRequires"))}):-1!==a.search(/Wikipédia:Escolha_do_artigo_em_destaque\/.+/)&&($("h2").eq(1).append('<span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a id="cf-close-run">'+e.message("cf-close-button")+'</a><span class="mw-editsection-bracket">]</span></span>'),$("#cf-close-run").click(e.alert.on(e,"Recurso ainda não disponível.")))},e.init()}();