A Wikipedia user script to automate common TfD operations
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

9 лет назад
9 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // @TFDCLERK_HEADER_START@
  2. /*
  3. Copyright (C) 2015 Ben Kurtovic <ben.kurtovic@gmail.com>
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights to
  7. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8. of the Software, and to permit persons to whom the Software is furnished to do
  9. so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. */
  20. // @TFDCLERK_HEADER_END@
  21. TFD.prototype._do_relist = function() {
  22. // TODO
  23. // rough mockup:
  24. // - post-submit ui updates
  25. // - date input box -> link to new discussion log page
  26. // - disable comments box
  27. // - add progress info area
  28. // - "Adding discussion to new date..."
  29. // - add discussion to new date, plus relist template
  30. // - " done ([[diff]])"
  31. // - "Removing discussion from old date..."
  32. // - replace contents of section with {{relisted}}
  33. // - " done ([[diff]])"
  34. // - "Updating discussion link on template(s):\n* [[Template:A]]..."
  35. // - update |link param of {{template for discussion}}
  36. // - " done ([[diff]])"
  37. // - replace gray buttons with progressive refresh button
  38. };
  39. TFD.prototype._get_relist_date = function() {
  40. return new Date(this.box.find(".tfdclerk-date").val()).toLogDateFormat();
  41. };
  42. TFD.prototype._on_date_change = function() {
  43. var date = this._get_relist_date();
  44. var title = "Wikipedia:Templates for discussion/Log/" + date;
  45. var info = this.box.find(".tfdclerk-discussion-info");
  46. info.empty();
  47. if (mw.config.get("wgTitle") == "Templates for discussion")
  48. var this_date = this.head.prevAll().filter("h3").first().find("a")
  49. .prop("title").split("/Log/")[1];
  50. else
  51. var this_date = mw.config.get("wgTitle").split("/Log/")[1];
  52. if (date == null || date == this_date) {
  53. this._block_submit("bad-date");
  54. info.append($("<span/>", {
  55. addClass: "tfdclerk-bad-date",
  56. text: date == this_date ? "Same as current date" : "Invalid date"
  57. }));
  58. return;
  59. }
  60. this._unblock_submit("bad-date");
  61. this._block_submit("checking-discussion");
  62. info.append(this._build_loading_node("span", "Checking discussion"));
  63. TFDClerk.api_get(this, {
  64. action: "query",
  65. indexpageids: "",
  66. titles: title
  67. }, function(data) {
  68. this._unblock_submit("checking-discussion");
  69. info.empty().append($("<span/>", {text: "Log: "})).append($("<a/>", {
  70. href: mw.util.getUrl(title),
  71. title: title,
  72. text: date,
  73. addClass: data.query.pageids[0] < 0 ? "new" : ""
  74. }));
  75. if (date == (new Date().toLogDateFormat()))
  76. info.append($("<span/>", {text: " (today)"}));
  77. });
  78. };
  79. TFD.prototype.relist = function() {
  80. var self = this;
  81. if (this._guard)
  82. return;
  83. this._guard = true;
  84. this._add_option_box("relist", "Relisting discussion", this._do_relist,
  85. function() {
  86. this._add_option_table([
  87. [
  88. $("<label/>", {
  89. for: "tfdclerk-date-" + this.id,
  90. text: "New date:"
  91. }),
  92. $("<input/>", {
  93. id: "tfdclerk-date-" + this.id,
  94. addClass: "tfdclerk-date",
  95. name: "date",
  96. type: "date",
  97. value: new Date().toDatePickerFormat(),
  98. change: function() { self._on_date_change(); }
  99. }).add($("<span/>", {
  100. addClass: "tfdclerk-discussion-info"
  101. }))
  102. ],
  103. [
  104. $("<label/>", {
  105. for: "tfdclerk-comments-" + this.id,
  106. text: "Comments:"
  107. }),
  108. $("<textarea/>", {
  109. id: "tfdclerk-comments-" + this.id,
  110. name: "comments",
  111. rows: 2,
  112. cols: 60,
  113. placeholder: "Optional. Do not sign."
  114. })
  115. ]
  116. ]);
  117. this._on_date_change();
  118. });
  119. };