Guest User

Untitled

a guest
Aug 12th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. $('#WikiHeader').append('<span class="wikia-button" onclick="name_of_function();">Text on the button</span>');
  2.  
  3. $.getJSON('/api.php?action=query&prop=revisions&titles=' + wgPageName + '&rvprop=content&indexpageids=1&format=json', function(result) {
  4.  
  5. result.query.pages[result.query.pageids[0]].revisions[0]['*']
  6. $('a.new')
  7.  
  8. var ref = 0;
  9. while(text.indexOf('[[', ref) != -1) {
  10. if(text.indexOf(']]', text.indexOf('[[', ref)) != -1) {
  11. var open = text.indexOf('[[', ref);
  12. var pipe = text.indexOf('|', open);
  13. var close = text.indexOf(']]', open);
  14. if(text.indexOf('<br/>', open) != -1 && text.indexOf('<br/>', open) < close) {ref = open + 1; continue;}
  15. if(pipe != -1 && pipe < close) { //is [[page|display]]
  16. if(pipe == close - 1) {
  17. var title = text.substring(open + 2, pipe);
  18. var display = title.substring(title.indexOf(':') + 1);
  19. }
  20. else {
  21. var title = text.substring(open + 2, pipe);
  22. var display = text.substring(pipe + 1, close);
  23. }
  24. }
  25. else { //is [[page]]
  26. var title = text.substring(open + 2, close);
  27. var display = title;
  28. }
  29. if(!title) {ref = open + 1; continue;} //skip [[]] and [[|<anything>]]
  30.  
  31. for(var i = 0; i < redlinks.length; i++) {
  32. if(title[0].toUpperCase() + title.substring(1) == redlinks[i].title.substring(0, ' (page does not exist)'.length)) {
  33. if(pipe == close - 1) {var show = title;}
  34. else {var show = display;}
  35. text = text.substring(0, open) + show + text.substring(close + 2);
  36. break;
  37. }
  38. }
  39. ref = open + 2;
  40. }
  41. else {break;}
  42. }
  43.  
  44. });
  45.  
  46. $.getJSON('action=query&prop=info&titles=' + wgPageName + '&intoken=edit&indexpageids=1&format=json', function(result) { var token = result.query.pages[result.query.pageids[0]].edittoken; });
  47. $.post('/api.php', {action: 'edit', title: wgPageName, text: text, summary: 'Fixing redlinks', token: token}, function() {window.location.reload();});
Advertisement
Add Comment
Please, Sign In to add comment