Browse Source

Support other backgrounds.

pull/24/head
Ben Kurtovic 12 years ago
parent
commit
833bdc6415
13 changed files with 108 additions and 50 deletions
  1. +5
    -1
      build.py
  2. +2
    -4
      pages/copyvios.mako
  3. +2
    -2
      pages/debug.mako
  4. +2
    -2
      pages/earwigbot.mako
  5. +2
    -2
      pages/index.mako
  6. +3
    -3
      pages/settings.mako
  7. +5
    -3
      pages/support/footer.mako
  8. +12
    -2
      pages/support/header.mako
  9. +2
    -2
      pages/surveyor.mako
  10. +2
    -2
      pages/swmt.mako
  11. +64
    -19
      static/js/potd.js
  12. +1
    -1
      toolserver/cookies.py
  13. +6
    -7
      toolserver/settings.py

+ 5
- 1
build.py View File

@@ -17,13 +17,17 @@ sys.path.insert(0, ".")
from mako.template import Template
from mako.lookup import TemplateLookup

from toolserver.cookies import parse_cookies

def main(environ, start_response):
lookup = TemplateLookup(directories=["{{pages_dir}}"],
input_encoding="utf8")
template = Template(filename="{{src}}", module_directory="{{temp_dir}}",
lookup=lookup, format_exceptions=True)
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)
return [page]



+ 2
- 4
pages/copyvios.mako View File

@@ -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.cookies" import="parse_cookies"/>\
<%namespace module="toolserver.misc" import="urlstrip"/>\
<% query, bot, all_langs, all_projects, page, result = main(environ) %>
<% cookies = parse_cookies(environ) %>
<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>
<form action="${environ['PATH_INFO']}" method="get">
@@ -129,4 +127,4 @@
</div>
</div>
% endif
<%include file="/support/footer.mako" args="environ=environ"/>
<%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/>

+ 2
- 2
pages/debug.mako View File

@@ -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>
% for key, value in environ.items():
% if key not in ["wsgi.input", "wsgi.errors", "PATH"]:
@@ -8,4 +8,4 @@
% endif
% endfor
</ul>
<%include file="/support/footer.mako" args="environ=environ"/>
<%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/>

+ 2
- 2
pages/earwigbot.mako View File

@@ -48,8 +48,8 @@
since ${since} (${uptime} uptime) on <tt>${host}</tt>
% endif
</%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>
<p>EarwigBot ${get_status()}.</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"/>

+ 2
- 2
pages/index.mako View File

@@ -16,7 +16,7 @@
pretty = path.split(root)[0]
%>\
<%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>
% for tool in tools:
% if tool != "DIVIDER":
@@ -29,4 +29,4 @@
% endif
% endif
% endfor
<%include file="/support/footer.mako" args="environ=environ"/>
<%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/>

+ 3
- 3
pages/settings.mako View File

@@ -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"/>\
<%! from json import dumps, loads %>
<% bot, cookies, status, langs, projects = main(environ, headers) %>
<% bot, status, langs, projects = main(environ, headers, cookies) %>
% if status:
<div class="green-box">
<p>${status}</p>
@@ -86,4 +86,4 @@
% else:
<p>No cookies!</p>
% endif
<%include file="/support/footer.mako" args="environ=environ"/>
<%include file="/support/footer.mako" args="environ=environ, cookies=cookies"/>

+ 5
- 3
pages/support/footer.mako View File

@@ -1,4 +1,4 @@
<%page args="environ"/>\
<%page args="environ, cookies"/>\
<%!
from os import path
%>\
@@ -18,7 +18,9 @@
<p>Copyright &copy; 2009&ndash;2012 <a href="//en.wikipedia.org/wiki/User:The_Earwig">Ben Kurtovic</a> &bull; \
<a href="mailto:earwig@toolserver.org">Contact</a> &bull; \
<a href="https://github.com/earwig/toolserver">View Source</a> &bull; \
<a id="bg_image_link" href="">Background</a> &bull; \
% if ("EarwigBackground" in cookies and cookies["EarwigBackground"].value in ["potd", "list"]) or "EarwigBackground" not in cookies:
<a id="bg_image_link" href="">Background</a> &bull; \
% endif
<a href="http://validator.w3.org/check?uri=referer">Valid XHTML 1.0 Strict</a>
</p>
</td>
@@ -29,4 +31,4 @@
</table>
</div>
</body>
</html>
</html>

+ 12
- 2
pages/support/header.mako View File

@@ -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"/>\
<%!
from os import path
@@ -28,7 +28,17 @@
<script src="${root}/static/js/${filename}" type="text/javascript"></script>
% endfor
</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">
<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">&gt;</span>


+ 2
- 2
pages/surveyor.mako View File

@@ -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>
<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"/>

+ 2
- 2
pages/swmt.mako View File

@@ -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>
<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"/>

+ 64
- 19
static/js/potd.js View File

@@ -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");
if (cookie) {
try {
@@ -10,37 +47,50 @@ function potd_set_background() {
var imgheight = data.imgheight;
if (filename && url && descurl && imgwidth && imgheight) {
set_background(filename, url, descurl, imgwidth, imgheight);
return;
return true;
}
}
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 head = document.getElementsByTagName("head")[0];

window[callback] = function(data) {
head.removeChild(script);
parse_file_name(data);
parse_file_url(data, escape(filename.replace(/ /g, "_")));
};

script.src = url;
head.appendChild(script);
}

function parse_file_name(data) {
function parse_list_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 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 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() {
// See http://www.javascripter.net/faq/browserw.htm
var width = 1024,
height = 768;
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) {
width = document.documentElement.offsetWidth;
height = document.documentElement.offsetHeight;
return [document.documentElement.offsetWidth, document.documentElement.offsetHeight];
}
if (window.innerWidth && window.innerHeight) {
width = window.innerWidth;
height = window.innerHeight;
return [window.innerWidth, window.innerHeight];
}
return [width, height];
return [1024, 768];
}

+ 1
- 1
toolserver/cookies.py View File

@@ -38,7 +38,7 @@ class _CookieManager(SimpleCookie):
return self._path


def parse_cookies(context, environ):
def parse_cookies(environ):
return _CookieManager(environ)

def set_cookie(headers, cookies, key, value, days=0):


+ 6
- 7
toolserver/settings.py View File

@@ -2,18 +2,17 @@

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 .sites import get_sites

def main(context, environ, headers):
def main(context, environ, headers, cookies):
query = Query(environ, method="POST")
cookies = parse_cookies(context, environ)

if query.action == "set":
status = _do_set(query, cookies, headers)
status = _do_set(query, headers, cookies)
elif query.action == "delete":
status = _do_delete(query, cookies, headers)
status = _do_delete(query, headers, cookies)
else:
status = None

@@ -21,7 +20,7 @@ def main(context, environ, headers):
langs, projects = get_sites(bot)
return bot, cookies, status, langs, projects

def _do_set(query, cookies, headers):
def _do_set(query, headers, cookies):
changes = set()
if query.lang:
key = "EarwigDefaultLang"
@@ -38,7 +37,7 @@ def _do_set(query, cookies, headers):
return "Updated {0}.".format(changes)
return None

def _do_delete(query, cookies, headers):
def _do_delete(query, headers, cookies):
if query.cookie in cookies:
delete_cookie(headers, cookies, query.cookie.encode("utf8"))
template = "Deleted cookie <b><tt>{0}</tt></b>."


Loading…
Cancel
Save