User:Hoof Hearted/monobook.js: Difference between revisions

m
Protected "User:Hoof Hearted/monobook.js": Personal / biographical information: personal Javascript settings ([Edit=Registered only] (indefinite) [Move=Allow only administrators] (indefinite))
(remove sections relying on red-link templates found on Wikimedia Commons - will hopefully make HotCat slightly faster)
m (Protected "User:Hoof Hearted/monobook.js": Personal / biographical information: personal Javascript settings ([Edit=Registered only] (indefinite) [Move=Allow only administrators] (indefinite)))
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
window.hotcat_translations_from_commons = true;
window.hotcat_translations_from_commons = true;
 
/*
/*
  This imports the latest version of HotCat from Commons.
  This imports the latest version of HotCat from Commons.
  HotCat is a gadget to make changes to categories much easier.
  HotCat is a gadget to make changes to categories much easier.
  Full documentation can be found at http://commons.wikimedia.org/wiki/Help:Gadget-HotCat
  Full documentation can be found at https://commons.Wikimedia.org/wiki/Help:Gadget-HotCat
*/
*/
mw.loader.load( '//commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&action=raw&ctype=text/javascript' );
mw.loader.load( '//commons.Wikimedia.org/w/index.php?title=MediaWiki:Gadget-HotCat.js&action=raw&ctype=text/javascript' );
   
   
// See http://en.wikipedia.org/wiki/User:Cameltrader/Advisor.js/Description
// See https://en.Wikipedia.org/wiki/User:Cameltrader/Advisor.js/Description
// for details and installation instructions.
// for details and installation instructions.
//
//
Line 21: Line 21:
var ct = ct || {};
var ct = ct || {};
   
   
// == Helpers ==
// ==Helpers==
   
   
// === DOM manipulation ===
// ===DOM manipulation===
   
   
// Browsers offer means to highlight text between two given offsets (``start''
// Browsers offer means to highlight text between two given offsets (``start''
Line 129: Line 129:
// It is convenient to embed in a help popup.
// It is convenient to embed in a help popup.
ct.hlink = function (toWhat, text) {
ct.hlink = function (toWhat, text) {
var wgServer = window.wgServer || 'http://en.wikipedia.org';
var wgServer = window.wgServer || 'https://en.Wikipedia.org';
var wgArticlePath = window.wgArticlePath || '/wiki/$1';
var wgArticlePath = window.wgArticlePath || '/wiki/$1';
var url = (wgServer + wgArticlePath).replace('$1', toWhat);
var url = (wgServer + wgArticlePath).replace('$1', toWhat);
Line 135: Line 135:
};
};
   
   
// === Helpers a la functional programming ===
// ===Helpers a la functional programming===
// A higher-order function---produces a cached version of a one-arg function.
// A higher-order function---produces a cached version of a one-arg function.
ct.makeCached = function (f) {
ct.makeCached = function (f) {
Line 144: Line 144:
};
};
   
   
// === Regular expressions ===
// ===Regular expressions===
// Regular expressions can sometimes become inconveniently large.
// Regular expressions can sometimes become inconveniently large.
// In order to make complex ones easier to read, we introduce
// In order to make complex ones easier to read, we introduce
Line 177: Line 177:
+ 'January|February|March|April|June|July|August|September|'
+ 'January|February|March|April|June|July|August|September|'
+ 'October|November|December)',
+ 'October|November|December)',
'{year}':
'{year}':
'[12][0-9]{3}'
'[12][0-9]{3}'
};
};
Line 224: Line 224:
};
};
   
   
// == Advisor core ==
// ==Advisor core==
// This is the basic functionality of showing and fixing suggestions.
// This is the basic functionality of showing and fixing suggestions.
   
   
// === Global constants and variables ===
// ===Global constants and variables===
ct.DEFAULT_MAX_SUGGESTIONS = 8;
ct.DEFAULT_MAX_SUGGESTIONS = 8;
ct.maxSuggestions = ct.DEFAULT_MAX_SUGGESTIONS;
ct.maxSuggestions = ct.DEFAULT_MAX_SUGGESTIONS;
Line 246: Line 246:
                         // a scan, this variable tracks its id
                         // a scan, this variable tracks its id
   
   
// === int main() ===
// ===int main()===
// This is the entry point
// This is the entry point
ct.observe(window, 'load', function () {
ct.observe(window, 'load', function () {
Line 276: Line 276:
});
});
   
   
// === Internationalisation ===
// ===Internationalisation===
// ct._() is a gettext-style internationalisation helper
// ct._() is a gettext-style internationalisation helper
// (http://en.wikipedia.org/wiki/gettext)
// (https://en.Wikipedia.org/wiki/gettext)
// If no translation is found for the parameter, it is returned as is.
// If no translation is found for the parameter, it is returned as is.
// Additionally, subsequent parameters are substituted for $1, $2, and so on.
// Additionally, subsequent parameters are substituted for $1, $2, and so on.
Line 293: Line 293:
};
};
   
   
// === Editor compatibility layer ===
// ===Editor compatibility layer===
// Controlling access to wpTextbox1 helps abstract out compatibility
// Controlling access to wpTextbox1 helps abstract out compatibility
// with editors like wikEd (http://en.wikipedia.org/wiki/User:Cacycle/wikEd)
// with editors like wikEd (https://en.Wikipedia.org/wiki/User:Cacycle/wikEd)
   
   
ct.getWikiText = function () {
ct.getWikiText = function () {
Line 350: Line 350:
};
};
   
   
// === Interaction with the user ===
// ===Interaction with the user===
// ct.scan() analyses the text and handles how the proposals are reflected in the UI.
// ct.scan() analyses the text and handles how the proposals are reflected in the UI.
ct.scan = function (force) {
ct.scan = function (force) {
Line 560: Line 560:
// Cut off the leading ``, '' and add ``formatting: '' and ``using Advisor.js''
// Cut off the leading ``, '' and add ``formatting: '' and ``using Advisor.js''
s = ct._(
s = ct._(
'formatting: $1 (using [[User:Cameltrader#Advisor.js|Advisor.js]])',
'formatting: $1 (using [[wp:User:Cameltrader#Advisor.js|Advisor.js]])',
s.substring(2)
s.substring(2)
);
);
Line 600: Line 600:
};
};
   
   
// == Rules ==
// ==Rules==
   
   
// This chapter contains the ``rules'' that produce suggestions---this is where
// This chapter contains the ``rules'' that produce suggestions---this is where
Line 625: Line 625:
// and are grouped into categories.
// and are grouped into categories.
   
   
// === Linking rules ===
// ===Linking rules===
   
   
ct.rules.push(function (s) {
ct.rules.push(function (s) {
Line 787: Line 787:
});
});
   
   
// === Character formatting rules ===
// ===Character formatting rules===
   
   
ct.rules.push(function (s) {
ct.rules.push(function (s) {
Line 953: Line 953:
if (m[1] == 'nbsp') {
if (m[1] == 'nbsp') {
// Opera incorrectly replaces nbsp-s with regular spaces:
// Opera incorrectly replaces nbsp-s with regular spaces:
// http://en.wikipedia.org/w/index.php?title=User_talk%3ACameltrader&diff=179233698&oldid=175946199
// https://en.Wikipedia.org/w/index.php?title=User_talk%3ACameltrader&diff=179233698&oldid=175946199
continue;
continue;
}
}
Line 1,026: Line 1,026:
});
});
   
   
// === Template usage rules ===
// ===Template usage rules===
   
   
ct.rules.push(function (s) {
ct.rules.push(function (s) {
Line 1,069: Line 1,069:
   
   
   
   
// === Other rules ===
// ===Other rules===
   
   
ct.rules.push(function (s) {
ct.rules.push(function (s) {
Line 1,275: Line 1,275:
   
   
// Search box for Mediawiki
// Search box for Mediawiki
// (c) 2006 [[User:Zocky]], released under GPL
// (c) 2006 [[Wikipedia:User:Zocky]], released under GPL
//<pre><nowiki>
//<pre><nowiki>
   
   
importStylesheetURI('http://en.wikipedia.org/w/index.php?title=User:Zocky/SearchBox.css&action=raw&ctype=text/css');
importStylesheetURI('https://en.Wikipedia.org/w/index.php?title=User:Zocky/SearchBox.css&action=raw&ctype=text/css');
   
   
var sr$t;
var sr$t;