Index: trunk/tools/bookmarklets/bookmarklets.html |
— | — | @@ -1,4 +1,4 @@ |
2 | 2 | <h1>Handy bookmarklets</h1> |
3 | 3 | <ul> |
4 | | -<li><a href="javascript:function swapUrl(base) { var specials = "meta|commons|office|internal|collab|usability"; if (base[4] == 's') { base = base.replace( /^https:\/\/secure\.wikimedia\.org\/(.*?)\/(.*?)\/(.*)$/, "http://$2.$1.org/$3"); base = base.replace( "http://mediawiki.wikipedia", "http://www.mediawiki"); base = base.replace( new RegExp("^http:\/\/(" + specials + ")\.wikipedia"), "http://$1.wikimedia"); } else { base = base.replace( "http://www.mediawiki", "http://mediawiki.wikipedia"); base = base.replace( new RegExp("^http:\/\/(" + specials + ")\.wikimedia"), "http://$1.wikipedia"); base = base.replace( /^http:\/\/(.*?)\.(.*?)\.org\/(.*)$/, "https://secure.wikimedia.org/$2/$1/$3"); } return base; } document.location=swapUrl(document.location.toString());">secure-switch</a></li> |
| 4 | +<li><a href="javascript:function swapUrl(base) { /* Hardcore special cases... use "virtual" hostnames for some flipping. */ var specialCases = [ ["www.mediawiki.org", "mediawiki.wikipedia.org"], ["wikimediafoundation.org", "foundation.wikipedia.org"]]; /* Sites we need to swap in 'wikipedia' in place of 'wikimedia': */ var specialWikis = [ 'advisory', 'auditcom', 'board', 'chair', 'chapcom', 'collab', 'comcom', 'commons', 'exec', 'grants', 'incubator', 'internal', 'langcom', 'meta', 'office', 'otrs-wiki', 'quality', 'searchcom', 'spcom', 'species', 'usability', 'wikimania2005', 'wikimania2006', 'wikimania2007', 'wikimania2008', 'wikimania2009', 'wikimania2010', 'wikimaniateam', 'wikimania']; var specials = specialWikis.join('|'); if (base[4] == 's') { base = base.replace( /^https:\/\/secure\.wikimedia\.org\/(.*?)\/(.*?)\/(.*)$/, "http://$2.$1.org/$3"); for (var i = 0; i < specialCases.length; i++) { base = base.replace( "http://" + specialCases[i][1], "http://" + specialCases[i][0]); } base = base.replace( new RegExp("^http:\/\/(" + specials + ")\.wikipedia"), "http://$1.wikimedia"); } else { for (var i = 0; i < specialCases.length; i++) { base = base.replace( "http://" + specialCases[i][0], "http://" + specialCases[i][1]); } base = base.replace( new RegExp("^http:\/\/(" + specials + ")\.wikimedia"), "http://$1.wikipedia"); base = base.replace( /^http:\/\/(.*?)\.(.*?)\.org\/(.*)$/, "https://secure.wikimedia.org/$2/$1/$3"); } return base; } document.location=swapUrl(document.location.toString());">secure-switch</a></li> |
5 | 5 | </ul> |
Index: trunk/tools/bookmarklets/secure-switch.js |
— | — | @@ -1,20 +1,60 @@ |
2 | 2 | function swapUrl(base) { |
3 | | - var specials = "meta|commons|office|internal|collab|usability"; |
| 3 | + /* Hardcore special cases... use "virtual" hostnames for some flipping. */ |
| 4 | + var specialCases = [ |
| 5 | + ["www.mediawiki.org", "mediawiki.wikipedia.org"], |
| 6 | + ["wikimediafoundation.org", "foundation.wikipedia.org"]]; |
| 7 | + /* Sites we need to swap in 'wikipedia' in place of 'wikimedia': */ |
| 8 | + var specialWikis = [ |
| 9 | + 'advisory', |
| 10 | + 'auditcom', |
| 11 | + 'board', |
| 12 | + 'chair', |
| 13 | + 'chapcom', |
| 14 | + 'collab', |
| 15 | + 'comcom', |
| 16 | + 'commons', |
| 17 | + 'exec', |
| 18 | + 'grants', |
| 19 | + 'incubator', |
| 20 | + 'internal', |
| 21 | + 'langcom', |
| 22 | + 'meta', |
| 23 | + 'office', |
| 24 | + 'otrs-wiki', |
| 25 | + 'quality', |
| 26 | + 'searchcom', |
| 27 | + 'spcom', |
| 28 | + 'species', |
| 29 | + 'usability', |
| 30 | + 'wikimania2005', |
| 31 | + 'wikimania2006', |
| 32 | + 'wikimania2007', |
| 33 | + 'wikimania2008', |
| 34 | + 'wikimania2009', |
| 35 | + 'wikimania2010', |
| 36 | + 'wikimaniateam', |
| 37 | + 'wikimania']; |
| 38 | + var specials = specialWikis.join('|'); |
| 39 | + |
4 | 40 | if (base[4] == 's') { |
5 | 41 | base = base.replace( |
6 | 42 | /^https:\/\/secure\.wikimedia\.org\/(.*?)\/(.*?)\/(.*)$/, |
7 | 43 | "http://$2.$1.org/$3"); |
| 44 | + for (var i = 0; i < specialCases.length; i++) { |
| 45 | + base = base.replace( |
| 46 | + "http://" + specialCases[i][1], |
| 47 | + "http://" + specialCases[i][0]); |
| 48 | + } |
8 | 49 | base = base.replace( |
9 | | - "http://mediawiki.wikipedia", |
10 | | - "http://www.mediawiki"); |
11 | | - base = base.replace( |
12 | 50 | new RegExp("^http:\/\/(" + specials + ")\.wikipedia"), |
13 | 51 | "http://$1.wikimedia"); |
14 | 52 | } else { |
| 53 | + for (var i = 0; i < specialCases.length; i++) { |
| 54 | + base = base.replace( |
| 55 | + "http://" + specialCases[i][0], |
| 56 | + "http://" + specialCases[i][1]); |
| 57 | + } |
15 | 58 | base = base.replace( |
16 | | - "http://www.mediawiki", |
17 | | - "http://mediawiki.wikipedia"); |
18 | | - base = base.replace( |
19 | 59 | new RegExp("^http:\/\/(" + specials + ")\.wikimedia"), |
20 | 60 | "http://$1.wikipedia"); |
21 | 61 | base = base.replace( |