Advertisement
Guest User

How do I make this different?

a guest
Sep 22nd, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. /* promote admins via chat */
  2. /*
  3. type "!sysop" to trigger
  4. */
  5.  
  6. if (("|" + mw.config.get("wgUserGroups").join("|") + "|").search(/\|bureaucrat\|/) > -1) {
  7. // define object
  8. AjaxSysop = {};
  9.  
  10. // functions
  11. AjaxSysop.fn = {};
  12. AjaxSysop.fn.getToken = function(user, n) {
  13. if (n > 0) {
  14. $.getJSON("/api.php?action=query&format=json&list=users&ustoken=userrights&ususers=" + encodeURIComponent(user), function(data) {
  15. var token = data.query.users[0].userrightstoken;
  16. console.log("Token: " + token);
  17. AjaxSysop.fn.makeAdmin(user, token);
  18. }).fail(function() {
  19. return AjaxSysop.fn.getToken(user, n-1);
  20. });
  21. } else {
  22. // errors in all attempts to get the token
  23. AjaxSysop.fn.error();
  24. }
  25. }
  26. AjaxSysop.fn.makeAdmin = function(user, token) {
  27. var reason = $("#sysop-promote-reason").val().length > 0 ? $("#sysop-promote-reason").val() : "Promoting user via [[Special:Chat]]";
  28. function loop(n) {
  29. $.ajax({
  30. type: "POST",
  31. url: "/api.php?action=userrights&user=" + encodeURIComponent(user) + "&token=" + encodeURIComponent(token) + "&add=sysop&reason=" + encodeURIComponent(reason)
  32. }).done(function() {
  33. // success! close interface
  34. AjaxSysop.fn.close();
  35. $(".Chat:first ul").append('<li class="inline-alert">The promotion was succesfully performed, or the user is already an admin.</li>');
  36. }).fail(function() {
  37. if (n > 0) {
  38. return loop(n-1);
  39. } else {
  40. // error in all attempts to save the group
  41. AjaxSysop.fn.error();
  42. }
  43. });
  44. }
  45. loop(5);
  46. }
  47.  
  48. // close interface
  49. AjaxSysop.fn.close = function() {
  50. $("section#sysop-promote")
  51. .hide()
  52. .find('input[type="text"]').val("")
  53. }
  54.  
  55. // error
  56. AjaxSysop.fn.error = function() {
  57. alert("There was an error promoting the given user. Please try again later or promote manually.");
  58. }
  59.  
  60. // html
  61. $("body").append(
  62. '<section id="sysop-promote">\n' +
  63. '\t<div>\n' +
  64. '\t\t<h2>Promote an admin</h2>\n' +
  65. '\t\t<p>\n' +
  66. '\t\t\tUser to promote: <input type="text" id="sysop-promote-user" /><br />\n' +
  67. '\t\t\tPromotion reason: <input type="text" placeholder="Promoting user via [[Special:Chat]]" id="sysop-promote-reason" /><br />\n' +
  68. '\t\t\t<input type="button" class="wikia-button" value="Promote" id="sysop-promote-bt-ok" />&nbsp;' +
  69. '\t\t\t<input type="button" class="wikia-button" value="Cancel" id="sysop-promote-bt-cancel" />\n' +
  70. '\t\t</p>\n' +
  71. '\t</div>\n' +
  72. '</section>\n'
  73. );
  74.  
  75. // css
  76. mw.util.addCSS(
  77. 'section#sysop-promote {' +
  78. '\tdisplay: none;\n' +
  79. '\twidth: 100%;\n' +
  80. '\theight: 100%;\n' +
  81. '\tposition: fixed;\n' +
  82. '\ttop: 0;\n' +
  83. '\tleft: 0;\n' +
  84. '\tbackground: rgba(0,0,0,0.35);\n' +
  85. '}\n' +
  86. 'section#sysop-promote > div {' +
  87. '\twidth: 300px;\n' +
  88. '\theight: 100px;\n' +
  89. '\tposition: fixed;\n' +
  90. '\ttop: ' + (($(window).height() - 122) / 2) + 'px;\n' +
  91. '\tleft: ' + (($(window).width() - 322) / 2) + 'px;\n' +
  92. '\tpadding: 10px;\n' +
  93. '\tbackground: white;\n' +
  94. '\tborder: 1px solid black;\n' +
  95. '\ttext-align: left;\n' +
  96. '\tcolor: #333333;\n' +
  97. '}\n' +
  98. 'section#sysop-promote inpit[type="text"] {' +
  99. '\twidth: 100px;\n' +
  100. '\theight: 20px;\n' +
  101. '\tline-height: 20px;\n' +
  102. '\tfont-size: 16px;\n' +
  103. '}'
  104. );
  105.  
  106. // ok function
  107. $("#sysop-promote-bt-ok").click(function() {
  108. if ($("#sysop-promote-user").val().length > 0) {
  109. AjaxSysop.fn.getToken($("#sysop-promote-user").val(), 5);
  110. }
  111. });
  112.  
  113. // cancel function
  114. $("#sysop-promote-bt-cancel").click(function() {
  115. AjaxSysop.fn.close();
  116. });
  117.  
  118. // trigger when message is "!sysop"
  119. $('textarea[name="message"]').keydown(function() {
  120. if ($(this).val() == "!sysop") {
  121. $(this).val("");
  122. $("section#sysop-promote").show();
  123. }
  124. });
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement