Преглед изворни кода

Linkback for tfdclerk script. Tweaks.

develop
Ben Kurtovic пре 9 година
родитељ
комит
1ae0652d2b
3 измењених фајлова са 43 додато и 13 уклоњено
  1. +1
    -0
      .gitignore
  2. +18
    -6
      release.py
  3. +24
    -7
      tfdclerk.js

+ 1
- 0
.gitignore Прегледај датотеку

@@ -1 +1,2 @@
*.pyc
.cookies

+ 18
- 6
release.py Прегледај датотеку

@@ -46,7 +46,7 @@ SCRIPT_SITE = "https://en.wikipedia.org"
SCRIPT_USER = "The Earwig"
SCRIPT_FILE = "tfdclerk.js"
COOKIE_FILE = ".cookies"
VERSION_TAG = "@TFDCLERK_VERSION@"
REPLACE_TAG = "@TFDCLERK_{tag}@"
EDIT_SUMMARY = "Updating script with latest version. ({version})"

SCRIPT_PAGE = "User:{user}/{file}".format(user=SCRIPT_USER, file=SCRIPT_FILE)
@@ -61,12 +61,17 @@ def _is_clean():

def _get_version():
"""
Return the current script version as a hex ID.
"""
return REPO.commit().hexsha[:10]

def _get_full_version():
"""
Return the current script version as a human-readable string.
"""
commit = REPO.commit()
date = time.gmtime(commit.committed_date)
date = time.gmtime(REPO.commit().committed_date)
datefmt = time.strftime("%H:%M, %-d %B %Y (UTC)", date)
return "{hash} ({date})".format(hash=commit.hexsha[:10], date=datefmt)
return "{hash} ({date})".format(hash=_get_version(), date=datefmt)

def _get_script():
"""
@@ -75,7 +80,14 @@ def _get_script():
with open(path.join(SCRIPT_ROOT, SCRIPT_FILE), "r") as fp:
text = fp.read().decode("utf8")

return text.replace(VERSION_TAG, _get_version())
replacements = {
"VERSION": _get_version(),
"VERSION_FULL": _get_full_version()
}

for tag, value in replacements.iteritems():
text = text.replace(REPLACE_TAG.format(tag=tag), value)
return text

def _get_cookiejar():
"""
@@ -123,7 +135,7 @@ def main():
script = _get_script()
site = _get_site()
page = site.get_page(SCRIPT_PAGE)
summary = EDIT_SUMMARY.format(version=REPO.commit().hexsha[:10])
summary = EDIT_SUMMARY.format(version=_get_version())

page.edit(script, summary, minor=False, bot=False)
print("Done!")


+ 24
- 7
tfdclerk.js Прегледај датотеку

@@ -1,6 +1,6 @@
// Templates for discussion clerk script by [[User:The Earwig]]

// Version: @TFDCLERK_VERSION@
// Version: @TFDCLERK_VERSION_FULL@
// Development and bug reports: https://github.com/earwig/tfdclerk

// To install, add:
@@ -51,9 +51,13 @@ if (is_tfd_page()) {
/* Main script starts here */

TFDClerk = {
sysop: $.inArray("sysop", mw.config.get("wgUserGroups")) >= 0,
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",
tfds: [],
_api: new mw.Api()

_api: new mw.Api(),
_sysop: $.inArray("sysop", mw.config.get("wgUserGroups")) >= 0
// TODO: access time?
};

@@ -130,12 +134,12 @@ TFD.prototype._error = function(msg, extra) {
}));

var contact = $("<a/>", {
href: "https://en.wikipedia.org/wiki/User_talk:The_Earwig",
title: "User talk:The Earwig",
href: TFDClerk.author_url,
title: TFDClerk.author_url.split("/").pop().replace(/_/g, " "),
text: "contact me"
}), file_bug = $("<a/>", {
href: "https://github.com/earwig/tfdclerk",
title: "earwig/tfdclerk",
href: TFDClerk.github_url,
title: TFDClerk.github_url.split("/").splice(-2).join("/"),
text: "file a bug report"
});
elem.append($("<br/>"))
@@ -202,11 +206,24 @@ TFD.prototype._add_option_box = function(verb, title, callback, options) {
id: "tfdclerk-" + verb + "-box-" + this.id,
addClass: "tfdclerk-" + verb + "-box"
})
.css("position", "relative")
.css("border", "1px solid #AAA")
.css("color", "#000")
.css("background-color", "#F9F9F9")
.css("margin", "0.5em 0")
.css("padding", "1em")
.append($("<div/>")
.css("position", "absolute")
.css("right", "1em")
.css("top", "0.5em")
.css("font-size", "75%")
.css("color", "#777")
.append($("<a/>", {
href: TFDClerk.script_url,
title: "tfdclerk.js",
text: "tfdclerk.js"
}))
.append($("<span/>", {text: " version @TFDCLERK_VERSION@"})))
.append($("<h5/>", {
text: title,
style: "margin: 0; padding: 0 0 0.25em 0;"


Loading…
Откажи
Сачувај