| @@ -17,13 +17,17 @@ sys.path.insert(0, ".") | |||||
| from mako.template import Template | from mako.template import Template | ||||
| from mako.lookup import TemplateLookup | from mako.lookup import TemplateLookup | ||||
| from toolserver.cookies import parse_cookies | |||||
| def main(environ, start_response): | def main(environ, start_response): | ||||
| lookup = TemplateLookup(directories=["{{pages_dir}}"], | lookup = TemplateLookup(directories=["{{pages_dir}}"], | ||||
| input_encoding="utf8") | input_encoding="utf8") | ||||
| template = Template(filename="{{src}}", module_directory="{{temp_dir}}", | template = Template(filename="{{src}}", module_directory="{{temp_dir}}", | ||||
| lookup=lookup, format_exceptions=True) | lookup=lookup, format_exceptions=True) | ||||
| headers = [("Content-Type", "text/html")] | headers = [("Content-Type", "text/html")] | ||||
| page = template.render(environ=environ, headers=headers).encode("utf8") | |||||
| cookies = parse_cookies(environ) | |||||
| page = template.render(environ=environ, headers=headers, | |||||
| cookies=cookies).encode("utf8") | |||||
| start_response("200 OK", headers) | start_response("200 OK", headers) | ||||
| return [page] | return [page] | ||||
| @@ -1,9 +1,7 @@ | |||||
| <%include file="/support/header.mako" args="environ=environ, title='Copyvio Detector', add_css=('copyvios.css',), add_js=('copyvios.js',)"/>\ | |||||
| <%include file="/support/header.mako" args="environ=environ, cookies=cookies, title='Copyvio Detector', add_css=('copyvios.css',), add_js=('copyvios.js',)"/>\ | |||||
| <%namespace module="toolserver.copyvios" import="main, highlight_delta"/>\ | <%namespace module="toolserver.copyvios" import="main, highlight_delta"/>\ | ||||
| <%namespace module="toolserver.cookies" import="parse_cookies"/>\ | |||||
| <%namespace module="toolserver.misc" import="urlstrip"/>\ | <%namespace module="toolserver.misc" import="urlstrip"/>\ | ||||
| <% query, bot, all_langs, all_projects, page, result = main(environ) %> | <% query, bot, all_langs, all_projects, page, result = main(environ) %> | ||||
| <% cookies = parse_cookies(environ) %> | |||||
| <h1>Copyvio Detector</h1> | <h1>Copyvio Detector</h1> | ||||
| <p>This tool attempts to detect <a href="//en.wikipedia.org/wiki/WP:COPYVIO">copyright violations</a> in articles. Simply give the title of the page you want to check and hit Submit. The tool will then search for its content elsewhere on the web and display a report if a similar webpage is found. If you also provide a URL, it will not query any search engines and instead display a report comparing the article to that particular webpage, like the <a href="//toolserver.org/~dcoetzee/duplicationdetector/">Duplication Detector</a>. Check out the <a href="//en.wikipedia.org/wiki/User:EarwigBot/Copyvios/FAQ">FAQ</a> for more information and technical details.</p> | <p>This tool attempts to detect <a href="//en.wikipedia.org/wiki/WP:COPYVIO">copyright violations</a> in articles. Simply give the title of the page you want to check and hit Submit. The tool will then search for its content elsewhere on the web and display a report if a similar webpage is found. If you also provide a URL, it will not query any search engines and instead display a report comparing the article to that particular webpage, like the <a href="//toolserver.org/~dcoetzee/duplicationdetector/">Duplication Detector</a>. Check out the <a href="//en.wikipedia.org/wiki/User:EarwigBot/Copyvios/FAQ">FAQ</a> for more information and technical details.</p> | ||||
| <form action="${environ['PATH_INFO']}" method="get"> | <form action="${environ['PATH_INFO']}" method="get"> | ||||
| @@ -129,4 +127,4 @@ | |||||
| </div> | </div> | ||||
| </div> | </div> | ||||
| % endif | % endif | ||||
| <%include file="/support/footer.mako" args="environ=environ"/> | |||||
| <%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/> | |||||
| @@ -1,4 +1,4 @@ | |||||
| <%include file="/support/header.mako" args="environ=environ, title='Debug'"/> | |||||
| <%include file="/support/header.mako" args="environ=environ, cookies=cookies, title='Debug'"/> | |||||
| <ul> | <ul> | ||||
| % for key, value in environ.items(): | % for key, value in environ.items(): | ||||
| % if key not in ["wsgi.input", "wsgi.errors", "PATH"]: | % if key not in ["wsgi.input", "wsgi.errors", "PATH"]: | ||||
| @@ -8,4 +8,4 @@ | |||||
| % endif | % endif | ||||
| % endfor | % endfor | ||||
| </ul> | </ul> | ||||
| <%include file="/support/footer.mako" args="environ=environ"/> | |||||
| <%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/> | |||||
| @@ -48,8 +48,8 @@ | |||||
| since ${since} (${uptime} uptime) on <tt>${host}</tt> | since ${since} (${uptime} uptime) on <tt>${host}</tt> | ||||
| % endif | % endif | ||||
| </%def>\ | </%def>\ | ||||
| <%include file="/support/header.mako" args="environ=environ, title='EarwigBot Status'"/> | |||||
| <%include file="/support/header.mako" args="environ=environ, cookies=cookies, title='EarwigBot Status'"/> | |||||
| <h1>EarwigBot Status</h1> | <h1>EarwigBot Status</h1> | ||||
| <p>EarwigBot ${get_status()}.</p> | <p>EarwigBot ${get_status()}.</p> | ||||
| <p>Additional information: <a href="http://status.toolserver.org/">status.toolserver.org</a></p> | <p>Additional information: <a href="http://status.toolserver.org/">status.toolserver.org</a></p> | ||||
| <%include file="/support/footer.mako" args="environ=environ"/> | |||||
| <%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/> | |||||
| @@ -16,7 +16,7 @@ | |||||
| pretty = path.split(root)[0] | pretty = path.split(root)[0] | ||||
| %>\ | %>\ | ||||
| <%def name="get_tools()"><% return tools %></%def>\ | <%def name="get_tools()"><% return tools %></%def>\ | ||||
| <%include file="/support/header.mako" args="environ=environ, title='Home', slug='home'"/> | |||||
| <%include file="/support/header.mako" args="environ=environ, cookies=cookies, title='Home', slug='home'"/> | |||||
| <h1>My Tools</h1> | <h1>My Tools</h1> | ||||
| % for tool in tools: | % for tool in tools: | ||||
| % if tool != "DIVIDER": | % if tool != "DIVIDER": | ||||
| @@ -29,4 +29,4 @@ | |||||
| % endif | % endif | ||||
| % endif | % endif | ||||
| % endfor | % endfor | ||||
| <%include file="/support/footer.mako" args="environ=environ"/> | |||||
| <%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/> | |||||
| @@ -1,7 +1,7 @@ | |||||
| <%include file="/support/header.mako" args="environ=environ, title='Settings'"/>\ | |||||
| <%include file="/support/header.mako" args="environ=environ, cookies=cookies, title='Settings'"/>\ | |||||
| <%namespace module="toolserver.settings" import="main"/>\ | <%namespace module="toolserver.settings" import="main"/>\ | ||||
| <%! from json import dumps, loads %> | <%! from json import dumps, loads %> | ||||
| <% bot, cookies, status, langs, projects = main(environ, headers) %> | |||||
| <% bot, status, langs, projects = main(environ, headers, cookies) %> | |||||
| % if status: | % if status: | ||||
| <div class="green-box"> | <div class="green-box"> | ||||
| <p>${status}</p> | <p>${status}</p> | ||||
| @@ -86,4 +86,4 @@ | |||||
| % else: | % else: | ||||
| <p>No cookies!</p> | <p>No cookies!</p> | ||||
| % endif | % endif | ||||
| <%include file="/support/footer.mako" args="environ=environ"/> | |||||
| <%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/> | |||||
| @@ -1,4 +1,4 @@ | |||||
| <%page args="environ"/>\ | |||||
| <%page args="environ, cookies"/>\ | |||||
| <%! | <%! | ||||
| from os import path | from os import path | ||||
| %>\ | %>\ | ||||
| @@ -18,7 +18,9 @@ | |||||
| <p>Copyright © 2009–2012 <a href="//en.wikipedia.org/wiki/User:The_Earwig">Ben Kurtovic</a> • \ | <p>Copyright © 2009–2012 <a href="//en.wikipedia.org/wiki/User:The_Earwig">Ben Kurtovic</a> • \ | ||||
| <a href="mailto:earwig@toolserver.org">Contact</a> • \ | <a href="mailto:earwig@toolserver.org">Contact</a> • \ | ||||
| <a href="https://github.com/earwig/toolserver">View Source</a> • \ | <a href="https://github.com/earwig/toolserver">View Source</a> • \ | ||||
| <a id="bg_image_link" href="">Background</a> • \ | |||||
| % if ("EarwigBackground" in cookies and cookies["EarwigBackground"].value in ["potd", "list"]) or "EarwigBackground" not in cookies: | |||||
| <a id="bg_image_link" href="">Background</a> • \ | |||||
| % endif | |||||
| <a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0 Strict</a> | <a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0 Strict</a> | ||||
| </p> | </p> | ||||
| </td> | </td> | ||||
| @@ -29,4 +31,4 @@ | |||||
| </table> | </table> | ||||
| </div> | </div> | ||||
| </body> | </body> | ||||
| </html> | |||||
| </html> | |||||
| @@ -1,4 +1,4 @@ | |||||
| <%page args="environ, title, slug=None, add_css=(), add_js=()"/>\ | |||||
| <%page args="environ, cookies, title, slug=None, add_css=(), add_js=()"/>\ | |||||
| <%namespace name="index" file="/index.mako" import="get_tools"/>\ | <%namespace name="index" file="/index.mako" import="get_tools"/>\ | ||||
| <%! | <%! | ||||
| from os import path | from os import path | ||||
| @@ -28,7 +28,17 @@ | |||||
| <script src="${root}/static/js/${filename}" type="text/javascript"></script> | <script src="${root}/static/js/${filename}" type="text/javascript"></script> | ||||
| % endfor | % endfor | ||||
| </head> | </head> | ||||
| <body onload="potd_set_background()"> | |||||
| % if "EarwigBackground" in cookies: | |||||
| % if cookies["EarwigBackground"].value == "list": | |||||
| <body onload="set_background_list()"> | |||||
| % elif cookies["EarwigBackground"].value == "plain": | |||||
| <body style="background-image: url('${root}/static/images/background.png');"> | |||||
| % else | |||||
| <body onload="set_background_potd()"> | |||||
| % endif | |||||
| % else | |||||
| <body onload="set_background_potd()"> | |||||
| % endif | |||||
| <div id="header"> | <div id="header"> | ||||
| <p id="heading"><a class="dark" href="${pretty}">earwig</a><span class="light">@</span><a class="mid" href="https://wiki.toolserver.org/">toolserver</a><span class="light">:</span><a class="dark" href="${this}">${slug}</a></p> | <p id="heading"><a class="dark" href="${pretty}">earwig</a><span class="light">@</span><a class="mid" href="https://wiki.toolserver.org/">toolserver</a><span class="light">:</span><a class="dark" href="${this}">${slug}</a></p> | ||||
| <p id="links"><span class="light">></span> | <p id="links"><span class="light">></span> | ||||
| @@ -1,4 +1,4 @@ | |||||
| <%include file="/support/header.mako" args="environ=environ, title='Contribution Surveyor'"/> | |||||
| <%include file="/support/header.mako" args="environ=environ, cookies=cookies, title='Contribution Surveyor'"/> | |||||
| <h1>Contribution Surveyor</h1> | <h1>Contribution Surveyor</h1> | ||||
| <p>This tool does not exist yet. Watch this space for updates.</p> | <p>This tool does not exist yet. Watch this space for updates.</p> | ||||
| <%include file="/support/footer.mako" args="environ=environ"/> | |||||
| <%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/> | |||||
| @@ -1,4 +1,4 @@ | |||||
| <%include file="/support/header.mako" args="environ=environ, title='SWMT Helper'"/> | |||||
| <%include file="/support/header.mako" args="environ=environ, cookies=cookies, title='SWMT Helper'"/> | |||||
| <h1>SWMT Helper</h1> | <h1>SWMT Helper</h1> | ||||
| <p>This tool does not exist yet. Watch this space for updates.</p> | <p>This tool does not exist yet. Watch this space for updates.</p> | ||||
| <%include file="/support/footer.mako" args="environ=environ"/> | |||||
| <%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/> | |||||
| @@ -1,4 +1,41 @@ | |||||
| function potd_set_background() { | |||||
| function set_background_potd() { | |||||
| if (cache_cookie()) return; | |||||
| var d = new Date(); | |||||
| var callback = "earwigpotd1"; | |||||
| var date = (d.getUTCFullYear()) + "-" + zero_pad(d.getUTCMonth() + 1, 2) + "-" + zero_pad(d.getUTCDate(), 2); | |||||
| var base = "//commons.wikimedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Template:Potd/"; | |||||
| var url = base + date + "&callback=" + callback; | |||||
| var script = document.createElement("script"); | |||||
| var head = document.getElementsByTagName("head")[0]; | |||||
| window[callback] = function(data) { | |||||
| head.removeChild(script); | |||||
| parse_potd_file_name(data); | |||||
| }; | |||||
| script.src = url; | |||||
| head.appendChild(script); | |||||
| } | |||||
| function set_background_list() { | |||||
| if (cache_cookie()) return; | |||||
| var base = "//commons.wikimedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=User:The+Earwig/POTD"; | |||||
| var url = base + "&callback=" + callback; | |||||
| var script = document.createElement("script"); | |||||
| var head = document.getElementsByTagName("head")[0]; | |||||
| window[callback] = function(data) { | |||||
| head.removeChild(script); | |||||
| parse_list_file_name(data); | |||||
| }; | |||||
| script.src = url; | |||||
| head.appendChild(script); | |||||
| } | |||||
| function cache_cookie() { | |||||
| var cookie = get_cookie("EarwigBackgroundCache"); | var cookie = get_cookie("EarwigBackgroundCache"); | ||||
| if (cookie) { | if (cookie) { | ||||
| try { | try { | ||||
| @@ -10,37 +47,50 @@ function potd_set_background() { | |||||
| var imgheight = data.imgheight; | var imgheight = data.imgheight; | ||||
| if (filename && url && descurl && imgwidth && imgheight) { | if (filename && url && descurl && imgwidth && imgheight) { | ||||
| set_background(filename, url, descurl, imgwidth, imgheight); | set_background(filename, url, descurl, imgwidth, imgheight); | ||||
| return; | |||||
| return true; | |||||
| } | } | ||||
| } | } | ||||
| catch (SyntaxError) {} | catch (SyntaxError) {} | ||||
| } | } | ||||
| return false; | |||||
| } | |||||
| var d = new Date(); | |||||
| var callback = "earwigpotd1"; | |||||
| var date = (d.getUTCFullYear()) + "-" + zero_pad(d.getUTCMonth() + 1, 2) + "-" + zero_pad(d.getUTCDate(), 2); | |||||
| var base = "//commons.wikimedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Template:Potd/"; | |||||
| var url = base + date + "&callback=" + callback; | |||||
| function parse_potd_file_name(data) { | |||||
| var content = ""; | |||||
| var res = data["query"]["pages"]; | |||||
| for (pageid in res) { | |||||
| content = res[pageid]["revisions"][0]["*"]; | |||||
| } | |||||
| var filename = /\{\{Potd filename\|(1=)?(.*?)\|.*?\}\}/.exec(content)[2]; | |||||
| var callback = "earwigpotd2"; | |||||
| var base = "//commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=url|size&format=json&titles=File:"; | |||||
| var url = base + escape(filename) + "&callback=" + callback; | |||||
| var script = document.createElement("script"); | var script = document.createElement("script"); | ||||
| var head = document.getElementsByTagName("head")[0]; | var head = document.getElementsByTagName("head")[0]; | ||||
| window[callback] = function(data) { | window[callback] = function(data) { | ||||
| head.removeChild(script); | head.removeChild(script); | ||||
| parse_file_name(data); | |||||
| parse_file_url(data, escape(filename.replace(/ /g, "_"))); | |||||
| }; | }; | ||||
| script.src = url; | script.src = url; | ||||
| head.appendChild(script); | head.appendChild(script); | ||||
| } | } | ||||
| function parse_file_name(data) { | |||||
| function parse_list_file_name(data) { | |||||
| var content = ""; | var content = ""; | ||||
| var res = data["query"]["pages"]; | var res = data["query"]["pages"]; | ||||
| for (pageid in res) { | for (pageid in res) { | ||||
| content = res[pageid]["revisions"][0]["*"]; | content = res[pageid]["revisions"][0]["*"]; | ||||
| } | } | ||||
| var filename = /\{\{Potd filename\|(1=)?(.*?)\|.*?\}\}/.exec(content)[2]; | |||||
| var filenames = []; | |||||
| while ((match = /\*\s*\[\[File:(.*?)\]\]/g.exec(content)) !== null) { | |||||
| filenames.push(match[1]); | |||||
| } | |||||
| var filename = filenames[Math.floor(Math.random() * filenames.length)]; | |||||
| var callback = "earwigpotd2"; | var callback = "earwigpotd2"; | ||||
| var base = "//commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=url|size&format=json&titles=File:"; | var base = "//commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=url|size&format=json&titles=File:"; | ||||
| @@ -116,19 +166,14 @@ function zero_pad(value, length) { | |||||
| function get_window_size() { | function get_window_size() { | ||||
| // See http://www.javascripter.net/faq/browserw.htm | // See http://www.javascripter.net/faq/browserw.htm | ||||
| var width = 1024, | |||||
| height = 768; | |||||
| if (document.body && document.body.offsetWidth && document.body.offsetHeight) { | if (document.body && document.body.offsetWidth && document.body.offsetHeight) { | ||||
| width = document.body.offsetWidth; | |||||
| height = document.body.offsetHeight; | |||||
| return [document.body.offsetWidth, document.body.offsetHeight]; | |||||
| } | } | ||||
| if (document.compatMode=="CSS1Compat" && document.documentElement && document.documentElement.offsetWidth && document.documentElement.offsetHeight) { | if (document.compatMode=="CSS1Compat" && document.documentElement && document.documentElement.offsetWidth && document.documentElement.offsetHeight) { | ||||
| width = document.documentElement.offsetWidth; | |||||
| height = document.documentElement.offsetHeight; | |||||
| return [document.documentElement.offsetWidth, document.documentElement.offsetHeight]; | |||||
| } | } | ||||
| if (window.innerWidth && window.innerHeight) { | if (window.innerWidth && window.innerHeight) { | ||||
| width = window.innerWidth; | |||||
| height = window.innerHeight; | |||||
| return [window.innerWidth, window.innerHeight]; | |||||
| } | } | ||||
| return [width, height]; | |||||
| return [1024, 768]; | |||||
| } | } | ||||
| @@ -38,7 +38,7 @@ class _CookieManager(SimpleCookie): | |||||
| return self._path | return self._path | ||||
| def parse_cookies(context, environ): | |||||
| def parse_cookies(environ): | |||||
| return _CookieManager(environ) | return _CookieManager(environ) | ||||
| def set_cookie(headers, cookies, key, value, days=0): | def set_cookie(headers, cookies, key, value, days=0): | ||||
| @@ -2,18 +2,17 @@ | |||||
| from markupsafe import escape | from markupsafe import escape | ||||
| from .cookies import parse_cookies, set_cookie, delete_cookie | |||||
| from .cookies import set_cookie, delete_cookie | |||||
| from .misc import get_bot, Query | from .misc import get_bot, Query | ||||
| from .sites import get_sites | from .sites import get_sites | ||||
| def main(context, environ, headers): | |||||
| def main(context, environ, headers, cookies): | |||||
| query = Query(environ, method="POST") | query = Query(environ, method="POST") | ||||
| cookies = parse_cookies(context, environ) | |||||
| if query.action == "set": | if query.action == "set": | ||||
| status = _do_set(query, cookies, headers) | |||||
| status = _do_set(query, headers, cookies) | |||||
| elif query.action == "delete": | elif query.action == "delete": | ||||
| status = _do_delete(query, cookies, headers) | |||||
| status = _do_delete(query, headers, cookies) | |||||
| else: | else: | ||||
| status = None | status = None | ||||
| @@ -21,7 +20,7 @@ def main(context, environ, headers): | |||||
| langs, projects = get_sites(bot) | langs, projects = get_sites(bot) | ||||
| return bot, cookies, status, langs, projects | return bot, cookies, status, langs, projects | ||||
| def _do_set(query, cookies, headers): | |||||
| def _do_set(query, headers, cookies): | |||||
| changes = set() | changes = set() | ||||
| if query.lang: | if query.lang: | ||||
| key = "EarwigDefaultLang" | key = "EarwigDefaultLang" | ||||
| @@ -38,7 +37,7 @@ def _do_set(query, cookies, headers): | |||||
| return "Updated {0}.".format(changes) | return "Updated {0}.".format(changes) | ||||
| return None | return None | ||||
| def _do_delete(query, cookies, headers): | |||||
| def _do_delete(query, headers, cookies): | |||||
| if query.cookie in cookies: | if query.cookie in cookies: | ||||
| delete_cookie(headers, cookies, query.cookie.encode("utf8")) | delete_cookie(headers, cookies, query.cookie.encode("utf8")) | ||||
| template = "Deleted cookie <b><tt>{0}</tt></b>." | template = "Deleted cookie <b><tt>{0}</tt></b>." | ||||