-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwiki.formulapage.js
executable file
·39 lines (36 loc) · 1.56 KB
/
wiki.formulapage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(function($){
JOBAD.modules.register({
info:{
'identifier': 'wiki.formulapage',
'title': 'Formula page redirects for MediaWiki',
'author': 'Janelle Williams',
'description': 'Simple link to proof page from MediaWiki',
},
contextMenuEntries: function(target){
var math = target.closest('math');
if (! math.is('math')) { return false;}
var tex = math.find('annotation[encoding="application/x-tex"]').text();
tex = tex.replace(/\{{4}([^\{\}]+)\}{4}/g,"{$1}");
tex = tex.replace(/\{{3}([^\{\}]+)\}{3}/g,"{$1}");
tex = tex.replace(/\{{2}([^\{\}]+)\}{2}/g,"{$1}");
tex = tex.replace(/\[/g,"obrk").replace(/\]/g,"cbrk").replace(/\{/g,"obrc").replace(/\}/g,"cbrc").replace('#','wmpnd','g').replace('<','wmlangle','g').replace('>','wmrangle','g').replace('_','wmuscore','g').replace('|','wmvbar','g');
tex = encodeURIComponent(tex);//.replace(/\(/g, "%28").replace(/\\\\/g,"\\").replace(/\)/g,"%29").replace(/\*/g,"%@A").replace(/\\/g,"%5C");
var req = new XMLHttpRequest();
req.open('GET', '/index.php?title='+tex, false);
req.send(null);
$page_exists = (req.status == 200);
if (! $page_exists) {
return[
["New formula page", function(element){
window.location.href = "/index.php?title=" + tex+"&action=edit&boilerplate=Template%3ADRMF";
}]];
}
else {
return[
["Formula page", function(element){
window.location.href = "/index.php?title=" + tex;
}]];
}
}
});
})(JOBAD.refs.$);