Selaa lähdekoodia

Move application logic around; improve exceptions.

pull/24/head
Ben Kurtovic 10 vuotta sitten
vanhempi
commit
e682dbbdda
6 muutettua tiedostoa jossa 284 lisäystä ja 273 poistoa
  1. +18
    -6
      app.fcgi
  2. +3
    -7
      copyvios/settings.py
  3. +7
    -7
      templates/debug.mako
  4. +6
    -0
      templates/error.mako
  5. +147
    -147
      templates/index.mako
  6. +103
    -106
      templates/settings.mako

+ 18
- 6
app.fcgi Näytä tiedosto

@@ -5,12 +5,16 @@ from functools import wraps
from logging import DEBUG
from logging.handlers import TimedRotatingFileHandler
from time import asctime
from traceback import format_exc

from flask import Flask, g, request
from flask.ext.mako import MakoTemplates, render_template, TemplateError
from flup.server.fcgi import WSGIServer

from copyvios.cookies import parse_cookies
from copyvios.misc import get_bot
from copyvios.settings import process_settings
from copyvios.sites import get_sites

app = Flask(__name__)
MakoTemplates(app)
@@ -20,13 +24,15 @@ app.logger.addHandler(TimedRotatingFileHandler(
"logs/app.log", when="D", interval=1, backupCount=7))
app.logger.info(u"Flask server started " + asctime())

def debug_exceptions(func):
def catch_errors(func):
@wraps(func)
def inner(*args, **kwargs):
try:
return func(*args, **kwargs)
except TemplateError as exc:
return "<pre>" + exc.text + "</pre>"
return render_template("error.mako", traceback=exc.text)
except Exception:
return render_template("error.mako", traceback=format_exc())
return inner

@app.before_request
@@ -50,17 +56,23 @@ def write_access_log(response):
return response

@app.route("/")
@debug_exceptions
@catch_errors
def index():
return render_template("index.mako")

@app.route("/settings", methods=["GET", "POST"])
@debug_exceptions
@catch_errors
def settings():
return render_template("settings.mako")
status = process_settings() if request.method == "POST" else None
bot = get_bot()
langs, projects = get_sites(bot)
default = bot.wiki.get_site()
kwargs = {"status": status, "langs": langs, "projects": projects,
"default_lang": default.lang, "default_project": default.project}
return render_template("settings.mako", **kwargs)

@app.route("/debug")
@debug_exceptions
@catch_errors
def debug():
return render_template("debug.mako")



+ 3
- 7
copyvios/settings.py Näytä tiedosto

@@ -4,10 +4,9 @@ from flask import g
from markupsafe import escape

from .cookies import set_cookie, delete_cookie
from .misc import get_bot, Query
from .sites import get_sites
from .misc import Query

def main():
def process_settings():
query = Query(method="POST")
if query.action == "set":
status = _do_set(query)
@@ -15,10 +14,7 @@ def main():
status = _do_delete(query)
else:
status = None

bot = get_bot()
langs, projects = get_sites(bot)
return bot, status, langs, projects
return status

def _do_set(query):
cookies = g.cookies


+ 7
- 7
templates/debug.mako Näytä tiedosto

@@ -1,10 +1,10 @@
<%include file="/support/header.mako" args="title='Debug - Earwig\'s Copyvio Detector'"/>
<%! from flask import request %>\
<ul>
% for key, value in request.environ.items():
% if key not in ["wsgi.input", "wsgi.errors", "PATH"]:
<li><b>${key}</b>: ${value | h}</li>
% endif
% endfor
</ul>
<ul>
% for key, value in request.environ.items():
% if key not in ["wsgi.input", "wsgi.errors", "PATH"]:
<li><b>${key}</b>: ${value | h}</li>
% endif
% endfor
</ul>
<%include file="/support/footer.mako"/>

+ 6
- 0
templates/error.mako Näytä tiedosto

@@ -0,0 +1,6 @@
<%include file="/support/header.mako" args="title='Error! - Earwig\'s Copyvio Detector'"/>
<div id="info-box" class="red-box">
<p>An error occured! If it hasn't been reported (<a href="https://github.com/earwig/copyvios/issues">try to check</a>), please <a href="https://github.com/earwig/copyvios/issues/new">file an issue</a> or <a href="mailto:wikipedia.earwig@gmail.com">email me</a>. Include the following information:</p>
<pre>{{traceback | h}}</pre>
</div>
<%include file="/support/footer.mako"/>

+ 147
- 147
templates/index.mako Näytä tiedosto

@@ -7,155 +7,155 @@
lang, orig_lang, title, oldid, url, nocache = query.lang, query.orig_lang, query.title, query.oldid, query.url, query.nocache
bot, site, page, result = query.bot, query.site, query.page, query.result
%>\
% if query.project and lang and (title or oldid):
% if not site:
<div id="info-box" class="red-box">
<p>The given site (project=<b><span class="mono">${query.project | h}</span></b>, language=<b><span class="mono">${lang | h}</span></b>) doesn't seem to exist. It may also be closed or private. <a href="//${lang | h}.${query.project | h}.org/">Confirm its URL.</a></p>
</div>
% elif title and not result:
<div id="info-box" class="red-box">
<p>The given page doesn't seem to exist: <a href="${page.url}">${page.title | h}</a>.</p>
</div>
% elif oldid and not result:
<div id="info-box" class="red-box">
<p>The given revision ID doesn't seem to exist: <a href="//${site.domain | h}/w/index.php?oldid=${oldid | h}">${oldid | h}</a>.</p>
</div>
% elif url and result == "bad URI":
<% result = None %>
<div id="info-box" class="red-box">
<p>Unsupported URI scheme: <a href="${url | h}">${url | h}</a>.</p>
</div>
% endif
%endif
<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 or ID of the revision you want to check and hit Submit. The tool will search for similar content elsewhere on the web and display a report if a match 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><i>Note:</i> The tool is still in beta. You are completely welcome to use it and provide <a href="//en.wikipedia.org/wiki/User_talk:The_Earwig">feedback</a>, but be aware that it may produce strange or broken results.</p>
<form action="${environ['REQUEST_URI']}" method="get">
<table id="cv-form">
<tr>
<td>Site:</td>
<td colspan="3">
<span class="mono">http://</span>
<select name="lang">
<% selected_lang = orig_lang if orig_lang else cookies["CopyviosDefaultLang"].value if "CopyviosDefaultLang" in cookies else bot.wiki.get_site().lang %>\
% for code, name in query.all_langs:
% if code == selected_lang:
<option value="${code | h}" selected="selected">${name}</option>
% else:
<option value="${code | h}">${name}</option>
% endif
% endfor
</select>
<span class="mono">.</span>
<select name="project">
<% selected_project = query.project if query.project else cookies["CopyviosDefaultProject"].value if "CopyviosDefaultProject" in cookies else bot.wiki.get_site().project %>\
% for code, name in query.all_projects:
% if code == selected_project:
<option value="${code | h}" selected="selected">${name}</option>
% else:
<option value="${code | h}">${name}</option>
% endif
% endfor
</select>
<span class="mono">.org</span>
</td>
</tr>
<tr>
<td id="cv-col1">Page&nbsp;title:</td>
<td id="cv-col2">
% if page:
<input class="cv-text" type="text" name="title" value="${page.title | h}" />
% elif title:
<input class="cv-text" type="text" name="title" value="${title | h}" />
% else:
<input class="cv-text" type="text" name="title" />
% endif
</td>
<td id="cv-col3">or&nbsp;revision&nbsp;ID:</td>
<td id="cv-col4">
% if oldid:
<input class="cv-text" type="text" name="oldid" value="${oldid | h}" />
% else:
<input class="cv-text" type="text" name="oldid" />
% endif
</td>
</tr>
<tr>
<td>URL&nbsp;(optional):</td>
<td colspan="3">
% if url:
<input class="cv-text" type="text" name="url" value="${url | h}" />
% else:
<input class="cv-text" type="text" name="url" />
% endif
</td>
</tr>
% if nocache or (result and result.cached):
<tr>
<td>Bypass&nbsp;cache:</td>
<td colspan="3">
% if nocache:
<input type="checkbox" name="nocache" value="1" checked="checked" />
% else:
<input type="checkbox" name="nocache" value="1" />
% endif
</td>
</tr>
% endif
<tr>
<td colspan="4">
<button type="submit">Submit</button>
</td>
</tr>
</table>
</form>
% if result:
<% show_details = "CopyviosShowDetails" in cookies and cookies["CopyviosShowDetails"].value == "True" %>
<div class="divider"></div>
<div id="cv-result" class="${'red' if result.violation else 'green'}-box">
% if result.violation:
<h2 id="cv-result-header"><a href="${page.url}">${page.title | h}</a> is a suspected violation of <a href="${result.url | h}">${result.url | urlstrip, h}</a>.</h2>
% else:
<h2 id="cv-result-header">No violations detected in <a href="${page.url}">${page.title | h}</a>.</h2>
% endif
<ul id="cv-result-list">
% if not result.violation and not url:
% if result.url:
<li>Best match: <a href="${result.url | h}">${result.url | urlstrip, h}</a>.</li>
% else:
<li>No matches found.</li>
% endif
% if query.project and lang and (title or oldid):
% if not site:
<div id="info-box" class="red-box">
<p>The given site (project=<b><span class="mono">${query.project | h}</span></b>, language=<b><span class="mono">${lang | h}</span></b>) doesn't seem to exist. It may also be closed or private. <a href="//${lang | h}.${query.project | h}.org/">Confirm its URL.</a></p>
</div>
% elif title and not result:
<div id="info-box" class="red-box">
<p>The given page doesn't seem to exist: <a href="${page.url}">${page.title | h}</a>.</p>
</div>
% elif oldid and not result:
<div id="info-box" class="red-box">
<p>The given revision ID doesn't seem to exist: <a href="//${site.domain | h}/w/index.php?oldid=${oldid | h}">${oldid | h}</a>.</p>
</div>
% elif url and result == "bad URI":
<% result = None %>
<div id="info-box" class="red-box">
<p>Unsupported URI scheme: <a href="${url | h}">${url | h}</a>.</p>
</div>
% endif
%endif
<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 or ID of the revision you want to check and hit Submit. The tool will search for similar content elsewhere on the web and display a report if a match 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><i>Note:</i> The tool is still in beta. You are completely welcome to use it and provide <a href="//en.wikipedia.org/wiki/User_talk:The_Earwig">feedback</a>, but be aware that it may produce strange or broken results.</p>
<form action="${environ['REQUEST_URI']}" method="get">
<table id="cv-form">
<tr>
<td>Site:</td>
<td colspan="3">
<span class="mono">http://</span>
<select name="lang">
<% selected_lang = orig_lang if orig_lang else cookies["CopyviosDefaultLang"].value if "CopyviosDefaultLang" in cookies else bot.wiki.get_site().lang %>\
% for code, name in query.all_langs:
% if code == selected_lang:
<option value="${code | h}" selected="selected">${name}</option>
% else:
<option value="${code | h}">${name}</option>
% endif
<li><b><span class="mono">${round(result.confidence * 100, 1)}%</span></b> confidence of a violation.</li>
% if result.cached:
<li>Results are <a id="cv-cached" href="#">cached
<span>To save time (and money), this tool will retain the results of checks for up to 72 hours. This includes the URL of the "violated" source, but neither its content nor the content of the article. Future checks on the same page (assuming it remains unchanged) will not involve additional search queries, but a fresh comparison against the source URL will be made. If the page is modified, a new check will be run.</span>
</a> from ${result.cache_time} (${result.cache_age} ago). <a href="${environ['REQUEST_URI'] | h}&amp;nocache=1">Bypass the cache.</a></li>
% endfor
</select>
<span class="mono">.</span>
<select name="project">
<% selected_project = query.project if query.project else cookies["CopyviosDefaultProject"].value if "CopyviosDefaultProject" in cookies else bot.wiki.get_site().project %>\
% for code, name in query.all_projects:
% if code == selected_project:
<option value="${code | h}" selected="selected">${name}</option>
% else:
<li>Results generated in <span class="mono">${round(result.time, 3)}</span> seconds using <span class="mono">${result.queries}</span> queries.</li>
<option value="${code | h}">${name}</option>
% endif
<li><a id="cv-result-detail-link" href="#cv-result-detail" onclick="copyvio_toggle_details()">${"Hide" if show_details else "Show"} details:</a></li>
</ul>
<div id="cv-result-detail" style="display: ${'block' if show_details else 'none'};">
<ul id="cv-result-detail-list">
<li>Trigrams: <i>Article:</i> <span class="mono">${result.article_chain.size()}</span> / <i>Source:</i> <span class="mono">${result.source_chain.size()}</span> / <i>Delta:</i> <span class="mono">${result.delta_chain.size()}</span></li>
% if result.cached:
% if result.queries:
<li>Retrieved from cache in <span class="mono">${round(result.time, 3)}</span> seconds (originally generated in <span class="mono">${round(result.original_time, 3)}</span>s using <span class="mono">${result.queries}</span> queries; <span class="mono">${round(result.original_time - result.time, 3)}</span>s saved).</li>
% else:
<li>Retrieved from cache in <span class="mono">${round(result.time, 3)}</span> seconds (originally generated in <span class="mono">${round(result.original_time, 3)}</span>s; <span class="mono">${round(result.original_time - result.time, 3)}</span>s saved).</li>
% endif
% endif
% if result.queries:
<li><i>Fun fact:</i> The Wikimedia Foundation paid Yahoo! Inc. <a href="http://info.yahoo.com/legal/us/yahoo/search/bosspricing/details.html">$${result.queries * 0.0008} USD</a> for these results.</li>
% endif
</ul>
<table id="cv-chain-table">
<tr>
<td class="cv-chain-cell">Article: <div class="cv-chain-detail"><p>${highlight_delta(result.article_chain, result.delta_chain)}</p></div></td>
<td class="cv-chain-cell">Source: <div class="cv-chain-detail"><p>${highlight_delta(result.source_chain, result.delta_chain)}</p></div></td>
</tr>
</table>
</div>
</div>
% endfor
</select>
<span class="mono">.org</span>
</td>
</tr>
<tr>
<td id="cv-col1">Page&nbsp;title:</td>
<td id="cv-col2">
% if page:
<input class="cv-text" type="text" name="title" value="${page.title | h}" />
% elif title:
<input class="cv-text" type="text" name="title" value="${title | h}" />
% else:
<input class="cv-text" type="text" name="title" />
% endif
</td>
<td id="cv-col3">or&nbsp;revision&nbsp;ID:</td>
<td id="cv-col4">
% if oldid:
<input class="cv-text" type="text" name="oldid" value="${oldid | h}" />
% else:
<input class="cv-text" type="text" name="oldid" />
% endif
</td>
</tr>
<tr>
<td>URL&nbsp;(optional):</td>
<td colspan="3">
% if url:
<input class="cv-text" type="text" name="url" value="${url | h}" />
% else:
<input class="cv-text" type="text" name="url" />
% endif
</td>
</tr>
% if nocache or (result and result.cached):
<tr>
<td>Bypass&nbsp;cache:</td>
<td colspan="3">
% if nocache:
<input type="checkbox" name="nocache" value="1" checked="checked" />
% else:
<input type="checkbox" name="nocache" value="1" />
% endif
</td>
</tr>
% endif
<tr>
<td colspan="4">
<button type="submit">Submit</button>
</td>
</tr>
</table>
</form>
% if result:
<% show_details = "CopyviosShowDetails" in cookies and cookies["CopyviosShowDetails"].value == "True" %>
<div class="divider"></div>
<div id="cv-result" class="${'red' if result.violation else 'green'}-box">
% if result.violation:
<h2 id="cv-result-header"><a href="${page.url}">${page.title | h}</a> is a suspected violation of <a href="${result.url | h}">${result.url | urlstrip, h}</a>.</h2>
% else:
<h2 id="cv-result-header">No violations detected in <a href="${page.url}">${page.title | h}</a>.</h2>
% endif
<ul id="cv-result-list">
% if not result.violation and not url:
% if result.url:
<li>Best match: <a href="${result.url | h}">${result.url | urlstrip, h}</a>.</li>
% else:
<li>No matches found.</li>
% endif
% endif
<li><b><span class="mono">${round(result.confidence * 100, 1)}%</span></b> confidence of a violation.</li>
% if result.cached:
<li>Results are <a id="cv-cached" href="#">cached
<span>To save time (and money), this tool will retain the results of checks for up to 72 hours. This includes the URL of the "violated" source, but neither its content nor the content of the article. Future checks on the same page (assuming it remains unchanged) will not involve additional search queries, but a fresh comparison against the source URL will be made. If the page is modified, a new check will be run.</span>
</a> from ${result.cache_time} (${result.cache_age} ago). <a href="${environ['REQUEST_URI'] | h}&amp;nocache=1">Bypass the cache.</a></li>
% else:
<li>Results generated in <span class="mono">${round(result.time, 3)}</span> seconds using <span class="mono">${result.queries}</span> queries.</li>
% endif
<li><a id="cv-result-detail-link" href="#cv-result-detail" onclick="copyvio_toggle_details()">${"Hide" if show_details else "Show"} details:</a></li>
</ul>
<div id="cv-result-detail" style="display: ${'block' if show_details else 'none'};">
<ul id="cv-result-detail-list">
<li>Trigrams: <i>Article:</i> <span class="mono">${result.article_chain.size()}</span> / <i>Source:</i> <span class="mono">${result.source_chain.size()}</span> / <i>Delta:</i> <span class="mono">${result.delta_chain.size()}</span></li>
% if result.cached:
% if result.queries:
<li>Retrieved from cache in <span class="mono">${round(result.time, 3)}</span> seconds (originally generated in <span class="mono">${round(result.original_time, 3)}</span>s using <span class="mono">${result.queries}</span> queries; <span class="mono">${round(result.original_time - result.time, 3)}</span>s saved).</li>
% else:
<li>Retrieved from cache in <span class="mono">${round(result.time, 3)}</span> seconds (originally generated in <span class="mono">${round(result.original_time, 3)}</span>s; <span class="mono">${round(result.original_time - result.time, 3)}</span>s saved).</li>
% endif
% endif
% if result.queries:
<li><i>Fun fact:</i> The Wikimedia Foundation paid Yahoo! Inc. <a href="http://info.yahoo.com/legal/us/yahoo/search/bosspricing/details.html">$${result.queries * 0.0008} USD</a> for these results.</li>
% endif
</ul>
<table id="cv-chain-table">
<tr>
<td class="cv-chain-cell">Article: <div class="cv-chain-detail"><p>${highlight_delta(result.article_chain, result.delta_chain)}</p></div></td>
<td class="cv-chain-cell">Source: <div class="cv-chain-detail"><p>${highlight_delta(result.source_chain, result.delta_chain)}</p></div></td>
</tr>
</table>
</div>
</div>
% endif
<%include file="/support/footer.mako"/>

+ 103
- 106
templates/settings.mako Näytä tiedosto

@@ -1,113 +1,110 @@
<%!
from json import dumps, loads

from flask import g, request
from copyvios.settings import main
%>\
<% bot, status, langs, projects = main() %>\
<%include file="/support/header.mako" args="title='Settings - Earwig\'s Copyvio Detector'"/>
% if status:
<div id="info-box" class="green-box">
<p>${status}</p>
</div>
% endif
<p>This page contains some configurable options for the copyvio detector. Settings are saved as cookies. You can view and delete all cookies generated by this site at the bottom of this page.</p>
<form action="${request.base_url}" method="post">
<table>
<tr>
<td>Default site:</td>
<td>
<span class="mono">http://</span>
<select name="lang">
<% selected_lang = g.cookies["CopyviosDefaultLang"].value if "CopyviosDefaultLang" in g.cookies else bot.wiki.get_site().lang %>\
% for code, name in langs:
% if code == selected_lang:
<option value="${code | h}" selected="selected">${name}</option>
% else:
<option value="${code | h}">${name}</option>
% endif
% endfor
</select>
<span class="mono">.</span>
<select name="project">
<% selected_project = g.cookies["CopyviosDefaultProject"].value if "CopyviosDefaultProject" in g.cookies else bot.wiki.get_site().project %>\
% for code, name in projects:
% if code == selected_project:
<option value="${code | h}" selected="selected">${name}</option>
% else:
<option value="${code | h}">${name}</option>
% endif
% endfor
</select>
<span class="mono">.org</span>
</td>
</tr>
<%
background_options = [
("list", 'Randomly select from <a href="http://commons.wikimedia.org/wiki/User:The_Earwig/POTD">a subset</a> of previous <a href="//commons.wikimedia.org/">Wikimedia Commons</a> <a href="//commons.wikimedia.org/wiki/Commons:Picture_of_the_day">Pictures of the Day</a> that work well as widescreen backgrounds, refreshed daily (default).'),
("potd", 'Use the current Commons Picture of the Day, unfiltered. Certain POTDs may be unsuitable as backgrounds due to their aspect ratio or subject matter.'),
("plain", "Use a plain background."),
]
selected = g.cookies["CopyviosBackground"].value if "CopyviosBackground" in g.cookies else "list"
%>\
% for i, (value, desc) in enumerate(background_options):
<tr>
% if i == 0:
<td>Background:</td>
% else:
<td>&nbsp;</td>
% endif
<td>
<input type="radio" name="background" value="${value}" ${'checked="checked"' if value == selected else ''} /> ${desc}
</td>
</tr>
% if status:
<div id="info-box" class="green-box">
<p>${status}</p>
</div>
% endif
<p>This page contains some configurable options for the copyvio detector. Settings are saved as cookies. You can view and delete all cookies generated by this site at the bottom of this page.</p>
<form action="${request.base_url}" method="post">
<table>
<tr>
<td>Default site:</td>
<td>
<span class="mono">http://</span>
<select name="lang">
<% selected_lang = g.cookies["CopyviosDefaultLang"].value if "CopyviosDefaultLang" in g.cookies else default_lang %>\
% for code, name in langs:
% if code == selected_lang:
<option value="${code | h}" selected="selected">${name}</option>
% else:
<option value="${code | h}">${name}</option>
% endif
% endfor
<tr>
<td colspan="2">
<input type="hidden" name="action" value="set"/>
<button type="submit">Save</button>
</td>
</tr>
</table>
</form>
<h2>Cookies</h2>
% if g.cookies:
<table>
<% cookie_order = ["CopyviosDefaultProject", "CopyviosDefaultLang", "CopyviosBackground", "CopyviosShowDetails", "CopyviosScreenCache"] %>\
% for key in [key for key in cookie_order if key in g.cookies]:
<% cookie = g.cookies[key] %>\
<tr>
<td><b><span class="mono">${key | h}</span></b></td>
% try:
<% lines = dumps(loads(cookie.value), indent=4).splitlines() %>\
<td>
% for line in lines:
<span class="mono"><div class="indentable">${line | h}</div></span>
% endfor
</td>
% except ValueError:
<td><span class="mono">${cookie.value | h}</span></td>
% endtry
<td>
<form action="${request.base_url}" method="post">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="cookie" value="${key | h}">
<button type="submit">Delete</button>
</form>
</td>
</tr>
% endfor
<tr>
<td>
<form action="${request.base_url}" method="post">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="all" value="1">
<button type="submit">Delete all</button>
</form>
</td>
</tr>
</table>
% else:
<p>No cookies!</p>
% endif
</select>
<span class="mono">.</span>
<select name="project">
<% selected_project = g.cookies["CopyviosDefaultProject"].value if "CopyviosDefaultProject" in g.cookies else default_project %>\
% for code, name in projects:
% if code == selected_project:
<option value="${code | h}" selected="selected">${name}</option>
% else:
<option value="${code | h}">${name}</option>
% endif
% endfor
</select>
<span class="mono">.org</span>
</td>
</tr>
<%
background_options = [
("list", 'Randomly select from <a href="http://commons.wikimedia.org/wiki/User:The_Earwig/POTD">a subset</a> of previous <a href="//commons.wikimedia.org/">Wikimedia Commons</a> <a href="//commons.wikimedia.org/wiki/Commons:Picture_of_the_day">Pictures of the Day</a> that work well as widescreen backgrounds, refreshed daily (default).'),
("potd", 'Use the current Commons Picture of the Day, unfiltered. Certain POTDs may be unsuitable as backgrounds due to their aspect ratio or subject matter.'),
("plain", "Use a plain background."),
]
selected = g.cookies["CopyviosBackground"].value if "CopyviosBackground" in g.cookies else "list"
%>\
% for i, (value, desc) in enumerate(background_options):
<tr>
% if i == 0:
<td>Background:</td>
% else:
<td>&nbsp;</td>
% endif
<td>
<input type="radio" name="background" value="${value}" ${'checked="checked"' if value == selected else ''} /> ${desc}
</td>
</tr>
% endfor
<tr>
<td colspan="2">
<input type="hidden" name="action" value="set"/>
<button type="submit">Save</button>
</td>
</tr>
</table>
</form>
<h2>Cookies</h2>
% if g.cookies:
<table>
<% cookie_order = ["CopyviosDefaultProject", "CopyviosDefaultLang", "CopyviosBackground", "CopyviosShowDetails", "CopyviosScreenCache"] %>\
% for key in [key for key in cookie_order if key in g.cookies]:
<% cookie = g.cookies[key] %>\
<tr>
<td><b><span class="mono">${key | h}</span></b></td>
% try:
<% lines = dumps(loads(cookie.value), indent=4).splitlines() %>\
<td>
% for line in lines:
<span class="mono"><div class="indentable">${line | h}</div></span>
% endfor
</td>
% except ValueError:
<td><span class="mono">${cookie.value | h}</span></td>
% endtry
<td>
<form action="${request.base_url}" method="post">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="cookie" value="${key | h}">
<button type="submit">Delete</button>
</form>
</td>
</tr>
% endfor
<tr>
<td>
<form action="${request.base_url}" method="post">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="all" value="1">
<button type="submit">Delete all</button>
</form>
</td>
</tr>
</table>
% else:
<p>No cookies!</p>
% endif
<%include file="/support/footer.mako"/>

Ladataan…
Peruuta
Tallenna