From 2dcc6ab7383978d6d516178f2ee56ae5240a58a3 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 5 Sep 2015 15:54:16 -0500 Subject: [PATCH] Fix behavior with transcluded discussions. Tweaks. --- release.py | 2 +- tfdclerk.js | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/release.py b/release.py index 820a7e1..7657ecf 100755 --- a/release.py +++ b/release.py @@ -49,7 +49,7 @@ SCRIPT_USER = "The Earwig" SCRIPT_FILE = "tfdclerk.js" COOKIE_FILE = ".cookies" REPLACE_TAG = "@TFDCLERK_{tag}@" -EDIT_SUMMARY = "Updating script with latest version. ({version})" +EDIT_SUMMARY = "Updating script with latest version ({version})" SCRIPT_PAGE = "User:{user}/{file}".format(user=SCRIPT_USER, file=SCRIPT_FILE) SCRIPT_ROOT = path.dirname(path.abspath(__file__)) diff --git a/tfdclerk.js b/tfdclerk.js index f0074c4..e1c3ce9 100644 --- a/tfdclerk.js +++ b/tfdclerk.js @@ -51,6 +51,7 @@ if (is_tfd_page()) { /* Main script starts here */ TFDClerk = { + version: "@TFDCLERK_VERSION@", script_url: "https://en.wikipedia.org/wiki/User:The_Earwig/tfdclerk.js", author_url: "https://en.wikipedia.org/wiki/User_talk:The_Earwig", github_url: "https://github.com/earwig/tfdclerk", @@ -124,7 +125,7 @@ TFD.prototype._unblock_submit = function(reason) { TFD.prototype._error = function(msg, extra) { var elem = $("", { - text: "Error: " + (extra ? msg + ": " : msg), + html: "Error: " + (extra ? msg + ": " : msg), style: "color: #A00;" }); if (extra) @@ -153,6 +154,12 @@ TFD.prototype._error = function(msg, extra) { this._block_submit("error"); }; +TFD.prototype._get_discussion_page = function() { + var url = this.head.find(".mw-editsection a").first().prop("href"); + var match = url.match(/title=(.*?)(\&|$)/); + return match ? match[1] : null; +}; + TFD.prototype._get_section_number = function() { var url = this.head.find(".mw-editsection a").first().prop("href"); var match = url.match(/section=(.*?)(\&|$)/); @@ -160,9 +167,10 @@ TFD.prototype._get_section_number = function() { }; TFD.prototype._with_content = function(callback) { - var section = this._get_section_number(); - if (section === null) - return this._error("couldn't get section number"); + var title = this._get_discussion_page(), + section = this._get_section_number(); + if (title === null || section === null) + return this._error("couldn't find discussion section"); if (this._wikitext !== undefined) { if (this._wikitext === null) @@ -177,10 +185,11 @@ TFD.prototype._with_content = function(callback) { action: "query", prop: "revisions", rvprop: "content", + indexpageids: "", rvsection: section, - revids: mw.config.get("wgRevisionId") + titles: title }, function(data) { - var pageid = mw.config.get("wgArticleId"); + var pageid = data.query.pageids[0]; var content = data.query.pages[pageid].revisions[0]["*"]; this._wikitext = content; callback.call(this, content); @@ -223,7 +232,7 @@ TFD.prototype._add_option_box = function(verb, title, callback, options) { title: "tfdclerk.js", text: "tfdclerk.js" })) - .append($("", {text: " version @TFDCLERK_VERSION@"}))) + .append($("", {text: " version " + TFDClerk.version}))) .append($("
", { text: title, style: "margin: 0; padding: 0 0 0.25em 0;" @@ -347,7 +356,7 @@ TFD.prototype._build_close_results = function() { TFD.prototype._add_close_actions = function() { this._block_submit("add-close-actions"); this._with_content(function(content) { - var regex = /\{\{tfd links\|(.*?)(\||\}\})/gi, + var regex = /\*\s*\{\{tfd links\|(.*?)(\||\}\})/gi, match = regex.exec(content); if (match === null) return this._error("no templates found in section");