MediaWiki:UserTags/code.min.js

/*__NOWYSIWYG__*/ if(typeof Object.freeze!=="function"){Object.freeze=function(a){"use strict";return a};Object.isFrozen=function{"use strict";return false}}if(typeof Object.seal!=="function"){Object.seal=function(a){"use strict";return a};Object.isSealed=function{"use strict";return false}}(function{function a(a){for(var b in a){delete a[b]}Object.seal(a)}"use strict";a(Object.prototype)});window.UserTagsJS=$.extend(true,window.UserTagsJS,{extensions:{}});(function(a,b,c){function d(a){var b=/^(\d{4})-?(\d\d)-?(\d\d)[T\s](\d\d):?(\d\d):?(\d\d)(?:\.?(\d+))?(?:Z|\+00(?::?00)?)$/.exec(a);if(!b)return null;return new Date(b[1],b[2]-1,b[3],b[4],b[5],b[6],("."+b[7])*1e3|0)}"use strict";b.i18n={_data:{en:{inactive:{u:"Inactive",order:1/0},nonuser:{u:"Never Edited",order:1e+101},newuser:{u:"New Editor",order:1e+101},notautoconfirmed:{u:"New Account",order:1e+101},patroller:{u:"Patroller",order:0},rollback:{u:"Rollback",order:0},"bot-global":{u:"Global Bot",order:0}},it:{inactive:{u:"Inattivo"}},nl:{inactive:{u:"Inactief"},rollback:{u:"Terugdraaien"}}},start:function(b,c,d,e){return{tags:a.extend({},this._data.en,this._data[e])}}};b.mwGroups={start:function(b,c,d){if(!a.isArray(b)){b=["bureaucrat","chatmoderator","patroller","rollback","sysop","bannedfromchat","bot","bot-global"]}var e={},f=/[A-Za-z0-9]+/,g=[];for(var h=0,i=b.length;h<i;++h){if(f.test(b[h])){g[g.length]="group-"+b[h]+"-member"}else{d.wrn("Bad MediaWiki group:",b[h]);continue}e[b[h]]=1}this._groups=e;return{ajax:[{type:"user",prop:["groups"]},{type:"usermessage",messages:g}]}},_processMessages:function(a){var b=a.length,c={},d=/^group-(.+?)-member$/,e;while(b--){if(a[b].missing!==void 0)continue;e=d.exec(a[b].name);if(!e)continue;c[e[1]]={u:a[b]["*"],weight:1e+100,order:0}}return c},generate:function(b,c){var d={tags:this._processMessages(c.query.allmessages)};b=b.query.users[0];var e=[];if(a.isArray(b.groups)){var f=b.groups.length;while(f--){if(this._groups[b.groups[f]]===1){e[e.length]=b.groups[f]}}}d.groups=e;return d}};b.isblocked={start:function(a,b){return{ajax:{list:"blocks",bkusers:b,bkprop:"expiry",bkdir:"older",bklimit:1}}},generate:function(a){a=a.query.blocks[0];if(a&&Date.now<d(a.expiry)){return["blocked"]}}};b.inactive={start:function(a,b,c){this._days=typeof a==="number"&&(a|0)!==0?a:30;this._logger=c;return{ajax:{type:"contributions",limit:1,dir:"older",prop:["timestamp"]},tags:{inactive:{}}}},generate:function(a){a=a.query.usercontribs[0];if(!a)return;var b=d(a.timestamp);if(!b){this._logger.err("Unparsable ISO8601 Strict Timestamp:",a.timestamp);return}var c=new Date;c=+c+c.getTimezoneOffset*6e4;c-=this._days*864e5;if(+b<c)return["inactive"]}};b.nonuser={start:function{return{ajax:{type:"contributions",limit:1,dir:"older",prop:["timestamp"]},tags:{nonuser:{}}}},generate:function(a){a=a.query.usercontribs[0];if(!a){return["nonuser"]}}};b.custom={start:function(b,c){var d=b[c];if(a.isArray(d))return d;return d?[d+""]:null}};b.metafilter={start:function(a){this._config=typeof a==="object"&&a||{}},filter:function(b){var c,d,e,f,g,h=[],i=Object.hasOwnProperty;for(f in b){c=this._config[f];if(!c)continue;if(!a.isArray(c))c=[c];d=c.length;a:while(d--){g=c[d];if(!a.isArray(g))g=[g];e=g.length;while(e--){if(!i.call(b,g[e]))continue a}h[h.length]=f;break}}return h}};b.userfilter={start:function(b,c){b=(typeof b==="object"&&b||{})[c];if(!b)return;this._filter=a.isArray(b)?b:[b+""]},filter:function{return this._filter}};b.newuser={start:function(b,d,e){if(c.util.isIPv4Address(d)||c.util.isIPv6Address(d))return;b=a.extend({edits:10,days:4},b);this._edits=b.edits|0;this._days=b.days|0;this._logger=e;var f="";this._deferred=a.Deferred;this._selfajax=a.ajax({url:c.util.wikiScript("api"),data:{action:"parse",format:"json",text:f,prop:"text",disablepp:1},dataType:"json"});return{ajax:{type:"contributions",limit:1,dir:"newer",prop:["timestamp"]},promise:this._deferred.promise,tags:{newuser:{}}}},generate:function(b){var c=b.query.usercontribs[0];if(!c)return;c=(Date.now-(d(c.timestamp)||0))/864e5;c=c>=this._days;var e=this._deferred,f=this._edits,g=this._logger;this._selfajax.done(function(b){var d=a(document.createElement("div")).append(b.parse.text["*"]).text.replace(/[^\d]/g,"");if(d){e.resolve(c&&+d>=f?{}:["newuser"])}else{g.wrn("Got a bad response from Special:Editcount:",b);e.reject}}).fail(function(a,b,c){g.err("AJAX fail:",a.status,b,c);e.reject})},generateFailed:function{this._selfajax.abort;this._deferred.reject}};b.autoconfirmed={start:function{return{ajax:{type:"user",prop:["groups"]},tags:{notautoconfirmed:{}}}},generate:function(b){b=b.query.users[0];if(!b||!b.groups)return;return a.inArray("autoconfirmed",b.groups)!==-1?[]:["notautoconfirmed"]}};b.stopblocked={filter:function(a){if(!a.blocked)return;var b=[];for(var c in a){if(c==="blocked")continue;b[b.length]=c}return b}}})(jQuery,window.UserTagsJS.extensions,mediaWiki);mediaWiki.gadgets=$.extend(true,mediaWiki.gadgets,{Lunarity:{}});if(!mediaWiki.gadgets.Lunarity.UserTags)(function(a,b,c,d){function f(a){this._component=a;try{Object.defineProperty(this,"_component",{value:a})}catch(b){}return this}function h{var a=[],b={},c,d,e,f,g,h;for(d=0,e=arguments.length;d=(+d.weight||0)){e=a.extend({},d,e)}else{e=a.extend({},e,d)}}b.tags[f]=e}}return b}function m(a){var b=a;while(b=b.lastChild){if(b.nodeType===3){if(/^\s*$/.test(b.data)){b.parentNode.removeChild(b);return m(a)}else{b.data=b.data.replace(/\s+$/,"");return}}}}"use strict";mediaWiki.gadgets.Lunarity.UserTags=true;var e={_console:window.console||{log:a.noop,warn:a.noop,info:a.noop,error:a.noop},_slice:[].slice,_log:function(a,b){b=this._slice.call(b);b[0]="USERTAGS"+(b[0]?"("+b[0]+"):":":");return a.apply(this._console,b)},log:function{return this._log(this._console.log,arguments)},inf:function{return this._log(this._console.info,arguments)},wrn:function{return this._log(this._console.warn,arguments)},err:function{return this._log(this._console.error,arguments)},group:function(a){return(a?this._groupCollapsed:this._group).call(this._console)}};a.extend(e,{_group:e._console.group||a.noop,_groupCollapsed:e._console.groupCollapsed||a.noop,groupEnd:a.proxy(e._console.groupEnd||a.noop,e._console)});Object.freeze(e);a.extend(f.prototype,{_log:function(a,b){b=e._slice.call(b);b.unshift(this._component);return a.apply(e,b)},inf:function{return this._log(e.inf,arguments)},log:function{return this._log(e.log,arguments)},wrn:function{return this._log(e.wrn,arguments)},err:function{return this._log(e.err,arguments)},group:function{return e.group.apply(e,arguments)},groupEnd:function{return e.groupEnd.apply(e,arguments)}});Object.freeze(f);Object.freeze(f.prototype);var g=c.config.get("skin");if({oasis:1,wikia:1}[g]===1){g="oasis"}else if({wowwiki:1,uncyclopedia:1,monobook:1,vector:1}[g]===1){g="monobook"}else{return e.err(0,"Unsupported skin:",g)}d=a.extend({extensions:{},modules:{},tags:{},debug:false},d);d.tags=a.isPlainObject(d.tags)&&d.tags||{};d.modules=a.isPlainObject(d.modules)&&d.modules||{};d.extensions=a.isPlainObject(d.extensions)&&d.extensions||{};(function(a,b){var c;for(var d in b){c=b[d];if(!c){delete b[d];continue}if(!a.isPlainObject(c)){c={u:c+""}}c.weight=1/0;b[d]=c}})(a,d.tags);if(a.isEmptyObject(d.modules)){d.modules={inactive:true,newuser:true,autoconfirmed:true,mwGroups:true,metafilter:{sysop:["bureaucrat"],chatmoderator:["sysop","bureaucrat"]}}}if(d.modules.stopblocked===void 0){d.modules.stopblocked=true}if(g==="monobook"&&d.modules.isblocked===void 0){d.modules.isblocked=true}d.modules.i18n=true;if(/(?:^\?|&)debugusertags=1(?:&|$)/i.test(window.location.search)){d.debug=true}var i={_requests:{},_collisions:{},_username:"",_specials:{},request:function(b){if(b.type)return this._processSpecial(b);var c=0;if(b.meta!==void 0)++c;if(b.list!==void 0)++c;if(b.prop!==void 0)++c;if(c===0){throw new TypeError("Unrecognised request type")}else if(c!==1){throw new TypeError("One request type at a time only")}var d=b.list+"";if(!b.list){d=b.meta?"#"+b.meta:"@"+b.prop}if(d.indexOf("|")!==-1){throw new TypeError("Sledge can only accept individual requests, not pipe-combined ones")}if(b.action&&b.action!=="query"){throw new TypeError("Cannot handle non-query requests, perform those manually")}b=a.extend({},b);var e=this._hashRequest(b);var f=this._collisions[e];if(typeof f==="object"){return f.deferred.promise}this._collisions[e]=b;var g=this._requests[d];if(!g)g=this._requests[d]=[];b.deferred=a.Deferred;g.push(b);return b.deferred.promise},requestBundle:function(b){var c=[];for(var d=0,e=b.length;d<e;++d){c[c.length]=this.request(b[d])}return a.when.apply(a,c)},hammer:function{var b,d,e,f,g,h=[],i=c.util.wikiScript("api");this._commitSpecial;for{b={};d=false;e=[];for(var j in this._requests){g=this._requests[j];if(g.length===0){delete this._requests[j];continue}f=g.shift;e.push(f.deferred);delete f.deferred;this._mergeIntoAjax(b,f);d=true}if(!d)break;b.format="json";b.action="query";f=a.ajax({url:i,data:b,dataType:"json"}).done(a.proxy(this._onAjaxDone,this,e)).fail(a.proxy(this._onAjaxFail,this,e));h.push(f)}this._collisions={};return a.when.apply(a,h)},setUsername:function(a){this._username=a},_hashRequest:function(b){return a.param(b).split("&").sort.join("&")},_mergeIntoAjax:function(a,b){var c,d={list:1,meta:1,prop:1};for(c in b){if(!a[c]){a[c]=b[c]}else{if(d[c]===1){a[c]+="|"+b[c]}else{throw new TypeError("Request Parameter Collision!")}}}return a},_onAjaxDone:function(b,c){if(c.errors||c.warnings){e.wrn("Sledge","Bad requests (errors/warnings in response):",c)}if(d.debug){e.log("Sledge","onAjaxDone:",c,arguments[3])}c=typeof c!=="object"||c===null?c:function h(a,b,c){var d=c.isArray(a)?[]:{},e;for(var f in a){if(!a.hasOwnProperty(f))continue;e=a[f];if(typeof e==="object"&&e!==null&&!b.isFrozen(e)){e=h(e,b,c)}d[f]=e}return b.freeze(d)}(c,Object,a);for(var f=0,g=b.length;f<g;++f){b[f].resolve(c)}},_onAjaxFail:function(a){e.err("Sledge","AJAX Failure:",arguments);for(var b=0,c=a.length;b<c;++b){a[b].reject}},_processSpecial:function(b){var c;switch(b.type){case"user":c=this._specials.user||{};c.prop=h(c.prop,b.prop);this._specials.user=c;break;case"contributions":if(b.dir==="older"||!b.dir){c=this._specials.contribold||{limit:1};this._specials.contribold=c}else if(b.dir==="newer"){c=this._specials.contribnew||{limit:1};this._specials.contribnew=c}else{throw new TypeError('contributions does not support direction "'+b.dir+'"')}c.limit=c.limit<b.limit?b.limit:c.limit;c.prop=h(c.prop,b.prop);break;case"usermessage":this._specials.usermessage=c=this._specials.usermessage||{};c.msgs=h(c.msgs,b.messages);break;default:throw new TypeError("Unrecognised special request type: "+b.type)}if(!c.deferred){c.deferred=a.Deferred}return c.deferred.promise},_commitSpecial:function{var b=this._specials,c=[];if(b.user)c[0]={data:{list:"users",ususers:this._username,usprop:b.user.prop.join("|")},dfd:b.user.deferred};if(b.usermessage)c[c.length]={data:{meta:"allmessages",amenableparser:1,amargs:this._username,ammessages:b.usermessage.msgs.join("|")},dfd:b.usermessage.deferred};var d;for(var e in{old:1,"new":1}){d=b["contrib"+e];if(d)c[c.length]={data:{list:"usercontribs",uclimit:d.limit,ucuser:this._username,ucdir:e+"er",ucprop:d.prop.join("|")},dfd:d.deferred}}this._specials={};d=b=null;var f=function{return this.resolve.apply(this,arguments)},g=function{return this.reject.apply(this,arguments)};for(var h=0,i=c.length;h<i;++h){this.request(c[h].data).done(a.proxy(f,c[h].dfd)).fail(a.proxy(g,c[h].dfd))}}};var k=function(a,b,c){this.name=a;this.module=b;this.logger=new f("M:"+a);this.config=c;this._started=false;return this};a.extend(k.prototype,{tryStart:function(a,b,c,d){try{var e=this._doStart(this.module,a,b,c,d||this.config);this._started=true;return e}catch(f){this.logger.err("Start failed:",f,f.stack)}},runFilter:function(a,b){if(!this._started)return;if(typeof this.module.filter==="function"){try{var c=this.module.filter(a);if(!c)return b;for(var d=0,e=c.length;d<e;++d){delete b[c[d]]}}catch(f){this.logger.err("filter crashed:",f,f.stack)}}return b},_doStart:function(b,c,d,e,f){var g=a.Deferred,h;if(typeof b.start!=="function"||!(h=b.start(f,e,this.logger,d))){return g.resolve({}).promise}if(a.isArray(h)){h={groups:h}}else if(typeof h.promise==="function"){h={promise:h}}else if(!a.isPlainObject(h)){this.logger.err("start produced a bogus return value. Expected an array, $.Deferred, an object or falsy:",h);return}if(h.groups&&!a.isArray(h.groups)){this.logger.err("start returned a groups property that is not an array:",h.groups);delete h.groups}if(h.tags&&!a.isPlainObject(h.tags)){this.logger.err("start returned a tags property that is not an object map:",h.tags);delete h.tags}if(h.promise){if(typeof h.promise.promise!=="function"){this.logger.err("start returned an invalid jQuery promise:",h.promise);delete h.promise}else if(h.promise.state==="rejected"){return g.reject.promise}}var i=function(b){if(a.isArray(b)){b={groups:b}}j(h,b)},k=function{i.apply(this,arguments);g.resolve(h)},l=function{g.reject},m=h.promise?function{i.apply(this,arguments);h.promise.done(k).fail(l)}:k;if(h.ajax){c[a.isArray(h.ajax)?"requestBundle":"request"](h.ajax).done(this._makeAjaxCallback(h.promise,"generate",m,l,function{this.logger.err("AJAX generate function missing!")})).fail(this._makeAjaxCallback(h.promise,"generateFailed",m,l,function{this.logger.inf("No generateFailed handler. Module skipped.")}))}else{m.call(this)}return g.promise},_makeAjaxCallback:function(a,b,c,d,e){var f=this;return function{if(!a||a.state!=="rejected"){if(typeof f.module[b]==="function"){try{return c.call(f,f.module[b].apply(f.module,arguments))}catch(g){f.logger.err(b+" crashed:",g,g.stack)}}else{e.call(f)}}return d.call(f)}}});var l=function p(a){this._modules=[];this._started=false;this._activeModules={};p.prototype._selectModules.call(this,a);return this};a.extend(l.prototype,{startAll:function(b,c,e){var f=this._modules,g,h=a.Deferred,i={groups:{},tags:{}},j={c:f.length},k=a.proxy(this._moduleDone,this,h,j,i),l=a.proxy(this._moduleResolve,this,h,j,i),m;if(d.debug)m=function(a){delete this._activeModules[a]};for(var n=0,o=f.length;n<o;++n){g=f[n].tryStart(b,c,e);if(g){g.done(k).fail(l);if(d.debug){this._activeModules[f[n].name]=1;g.always(a.proxy(m,this,f[n].name))}}else{--j.c}}if(!f.length){h.resolve(i)}this._started=true;return h.promise},filterAll:function(b){if(!this._started)throw new Error("modules are not started yet");var c=this._modules,d=Object.freeze(a.extend({},b));for(var e=0,f=c.length;e<f;++e){b=c[e].runFilter(d,b)}return b},addModule:function(a,b,c){if(this._started)throw new Error("modules are already started");this._modules.push(new k(a,b,c))},getActiveModules:function{var a=[];for(var b in this._activeModules){a[a.length]=b}return a},_moduleDone:function(a,b,c,d){return this._moduleResolve(a,b,j(c,d))},_moduleResolve:function(a,b,c){if(--b.c===0){a.resolve(c)}},_selectModules:function(a){var b,c;for(var d in a.modules){c=a.modules[d];b=a.extensions[d];if(!c)continue;if(typeof b!=="object"||b===null){e.wrn("ModuleManager",'"'+d+'" is not an installed module');continue}this._modules.push(new k(d,b,c))}}});var n={_username:"",_modules:null,_$masthead:null,_usergender:"u",_genderPromise:null,_userTags:null,_startup:function{var a=c.config.get("wgTitle"),b=c.config.get("wgNamespaceNumber")|0;if(g==="oasis"){if({"-1":1,2:1,3:1,500:1,1200:1}[b]!==1)return;if({500:1,2:1,3:1}[b]===1&&a.indexOf("/")!==-1){return}if(b===-1){a=null;b=c.config.get("wgCanonicalSpecialPageName");if(b==="Contributions"){a=window.decodeURIComponent(window.location.pathname);if(a===c.util.wikiScript){a=/(?:\?|&)target=([^&]*)/.exec(window.location.search);a=a&&a[1]}else{a=a.substr(a.lastIndexOf("/")+1);a=a!==c.config.get("wgPageName")&&a}}else if(b!=="Following"){return}if(!a){a=c.config.get("wgUserName")}}}else{if({2:1,3:1,1200:1}[b]!==1)return}this._username=a;return true},execute:function(b){if(!this._startup)return;e.inf(0,"Starting...");this._modules=new l(b);this._modules.addModule("OasisTagsModule",this.OasisTagsModule);if(b.debug){b.listActiveModules=a.proxy(this._modules.getActiveModules,this._modules)}this._userTags=b.tags;i.setUsername(this._username);this._modulesPromise=this._modules.startAll(i,c.config.get("wgContentLanguage"),this._username);this._genderPromise=i.request({type:"user",prop:["gender"]});i.hammer;a(a.proxy(this._onDomReady,this))},_onDomReady:function(a){if(d.debug){e.inf(0,"Entering DOM Ready")}var b=a(g==="oasis"?"#UserProfileMasthead > .masthead-info > hgroup":"#firstHeading");if(!b.length){return e.err(0,"No Masthead found. We shouldn't have got this far...")}this._$masthead=b;this.OasisTagsModule.onDOMReady(b);b[0].normalize;m(b[0]);var c=this;this._genderPromise.done(function(a){a=a.query.users[0];if(!a||typeof a.gender!=="string")return;c._usergender=a.gender.charAt(0)}).always(function{c._modulesPromise.done(a.proxy(c._onModulesDone,c))})},_onModulesDone:function(a){if(d.debug){e.inf(0,"Entering Finale")}this._writeTags(this.OasisTagsModule.getBlackTags);j(a,{tags:this._userTags});var b=this._canonicaliseGroups(a.groups);b=this._modules.filterAll(b);b=this._convertGroupsToTags(b,a.tags);b.sort(function(a,b){a=typeof a.order!=="number"&&1e+100||a.order;b=typeof b.order!=="number"&&1e+100||b.order;return a===b?0:a<b?-1:1});return this._writeTags(b)},_canonicaliseGroups:function(a){var b={};for(var c=0,d=a.length;c<d;++c){b[a[c]]=true}return b},_convertGroupsToTags:function(a,b){var c=[],d;for(var f in a){d=b[f];if(!d){e.wrn(0,'Group "'+f+'" does not have any tag data!');d={u:"¿"+f+"?",title:"No Tag Information. Broken module or bad configuration!"}}d.name=f;c[c.length]=d}return c},_getTagMessage:function(a){if(d.debug){e.log("getTagMessage",a,this._usergender)}var b=a[this._usergender];if(b)return b;b=a.u;if(b)return b;return a.name},_writeTags:function(d){var e=c.config.get("wgArticlePath"),f,g=this._$masthead,h=/^(?:[A-Za-z\.+\-]+:)?\/\//,i=/[^A-Za-z0-9\-_]/g;for(var j=0,k=d.length;j<k;++j){if(d[j].link){f=b.createElement("a");f.href=h.test(d[j].link)?d[j].link:e.replace("$1",c.util.wikiUrlencode(d[j].link))}else{f=b.createElement("span")}if(d[j].title)f.title=d[j].title;f.className="tag";if(d[j].name)f.className+=" "+d[j].name.replace(i,"")+"-user";g.append(a(f).text(this._getTagMessage(d[j])))}}};n.OasisTagsModule={_whitelist:{founder:1,blocked:1,chatmoderator:1,sysop:1,bureaucrat:1},start:function(a,b,c){this._logger=c;this._blackTags=[];this._blackGroups=[];this._scrapedTags={};if(g!=="oasis")return;return{ajax:{meta:"allmessages",amprefix:"user-identity-box-group-",amenableparser:"1",amargs:b}}},onDOMReady:function(b){if(g!=="oasis")return;var c=this;b.find(".tag").each(function{var b=a(this);c._scrapedTags[b.text]=1;b.remove})},generate:function(a){a=a.query.allmessages;var b=/^user-identity-box-group-(.*)$/,c=[],e={},f,g;for(var h=0,i=a.length;h<i;++h){f=b.exec(a[h].name);if(!f)continue;f=f[1];g=a[h]["*"];if(this._whitelist[f]===1){e[f]={u:g,weight:-1,order:0};if(this._scrapedTags[g]===1){c.push(f)}}else{this._blackGroups.push(f);if(this._scrapedTags[g]===1){this._blackTags.push({u:g})}}delete this._scrapedTags[g]}if(d.debug){for(g in this._scrapedTags){this._logger.wrn("Scraped tag was not claimed:",g)}}return{tags:e,groups:c}},generateFailed:function{var a=[];for(var b in this._scrapedTags)a[a.length]={u:b};this._blackTags=a},filter:function{return this._blackGroups},getBlackTags:function{return this._blackTags}};try{n.execute(d)}catch(o){return e.err(0,"Crash:",o,o.stack)}if(!d.debug){delete window.UserTagsJS}else{window.UserTagsJS=d}})(jQuery,document,mediaWiki,window.UserTagsJS)