MediaWiki:Gadget-morebits.js: Difference between revisions

Content deleted Content added
Repo at dd76177: read discretionary sanctions information from a wiki page (#1479)
Repo at 8e7fd29: fix colon in title bug (#1504)
Line 4,921:
*/
removeLink: function(link_target) {
var mwTitle = mw.Title.newFromText(link_target);
// Remove a leading colon, to be handled later
var namespaceID = mwTitle.getNamespaceId();
if (link_target.indexOf(':') === 0) {
link_targetvar title = link_targetmwTitle.slicegetMainText(1);
}
var link_re_string = '', ns = '', title = link_target;
 
var idx = link_target.indexOf(':');
if (idx > 0) {
ns = link_target.slice(0, idx);
title = link_target.slice(idx + 1);
 
var link_regex_string = '';
link_re_string = Morebits.namespaceRegex(mw.config.get('wgNamespaceIds')[ns.toLowerCase().replace(/ /g, '_')]) + ':';
if (idxnamespaceID >!== 0) {
link_regex_string = Morebits.namespaceRegex(namespaceID) + ':';
}
link_re_stringlink_regex_string += Morebits.pageNameRegex(title);
 
// AllowFor formost annamespaces, optionalunlink leadingboth colon,[[User:Test]] e.g.and [[:User:Test]]
// FilesFor files and Categoriescategories, becomeonly linksunlink with[[:Category:Test]]. aDo leadingnot colon, e.g.unlink [[:FileCategory:Test.png]]
var colonisFileOrCategory = new RegExp(Morebits.namespaceRegex([6, 14])).testindexOf(nsnamespaceID) ? ':' :!== ':?'-1;
var colon = isFileOrCategory ? ':' : ':?';
 
var link_simple_resimple_link_regex = new RegExp('\\[\\[' + colon + '(' + link_re_stringlink_regex_string + ')\\]\\]', 'g');
var link_named_repiped_link_regex = new RegExp('\\[\\[' + colon + link_re_stringlink_regex_string + '\\|(.+?)\\]\\]', 'g');
this.text = this.text.replace(link_simple_resimple_link_regex, '$1').replace(link_named_repiped_link_regex, '$1');
return this;
},