Add category search, license handling, and message page improvements
Add /category route to find Wikipedia articles without images in a category using the MediaWiki API. Filter out non-content images (UI icons, logos) when checking articles. Show image license on message page with alternate message for non-free CC licenses (NC/ND) explaining Wikipedia's restrictions. For photos with free licenses, show upload options linking to UploadWizard instead of a message form. Add Flickr CC 4.0 license codes, user profile links, previous message detection from sent mail index, and back-navigation between category, search results, and message pages. Closes #3 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d59e67b55d
commit
c5efd429ce
4 changed files with 403 additions and 19 deletions
67
templates/category.html
Normal file
67
templates/category.html
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Category Search - Flickr mail{% endblock %}
|
||||
|
||||
{% block style %}
|
||||
<style>
|
||||
.article-link:visited { color: #6f42c1; }
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<h1>Find articles needing images</h1>
|
||||
<p class="text-muted">Enter a Wikipedia category to find articles without images</p>
|
||||
|
||||
<form action="{{ url_for('category_search') }}" method="get">
|
||||
<div class="mb-3">
|
||||
<label for="cat" class="form-label">Wikipedia category name or URL:</label>
|
||||
<input type="text" class="form-control" id="cat" name="cat" value="{{ cat }}"
|
||||
placeholder="e.g., Living people or https://en.wikipedia.org/wiki/Category:Living_people" required>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-primary" value="Search">
|
||||
<a href="{{ url_for('start') }}" class="btn btn-outline-secondary ms-2">Back to main</a>
|
||||
</form>
|
||||
|
||||
{% if error %}
|
||||
<div class="alert alert-danger mt-3">{{ error }}</div>
|
||||
{% endif %}
|
||||
|
||||
{% if category and articles is defined %}
|
||||
<div class="mt-4">
|
||||
<h5>Articles without images in <a href="https://en.wikipedia.org/wiki/{{ category | replace(' ', '_') }}" target="_blank">{{ category_name }}</a></h5>
|
||||
|
||||
{% if articles %}
|
||||
<p class="text-muted small">Found {{ articles | length }} article(s) without images{% if continue_token %} (more available){% endif %}</p>
|
||||
|
||||
<div class="list-group">
|
||||
{% for article in articles %}
|
||||
<div class="list-group-item d-flex justify-content-between align-items-center">
|
||||
<a href="{{ url_for('start', enwp=article.title, cat=cat) }}" class="text-decoration-none article-link">{{ article.title }}</a>
|
||||
<a href="{{ article.wikipedia_url }}" target="_blank" class="badge bg-secondary text-decoration-none">Wikipedia</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if continue_token %}
|
||||
<p class="text-muted small mt-3">Note: Only showing first batch of results. More articles may be available in this category.</p>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<div class="alert alert-success mt-3">
|
||||
All articles in this category have images!
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="mt-4">
|
||||
<p class="text-muted small">
|
||||
<a href="{{ url_for('start') }}">Back to Flickr mail home</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
</div>
|
||||
|
||||
<input type="submit" value="Submit">
|
||||
<a href="{{ url_for('category_search') }}" class="btn btn-outline-secondary ms-2">Find articles by category</a>
|
||||
</form>
|
||||
|
||||
{% if recent_uploads is defined and recent_uploads and not name %}
|
||||
|
|
@ -58,6 +59,9 @@
|
|||
|
||||
{% if name and search_result is defined and search_result.photos %}
|
||||
|
||||
{% if cat %}
|
||||
<p><a href="{{ url_for('category_search', cat=cat) }}">← Back to category</a></p>
|
||||
{% endif %}
|
||||
<p>Wikipedia article: {{ name }}</p>
|
||||
<p>Select a photo to compose a message ({{ search_result.total_photos | default(0) }} results):</p>
|
||||
|
||||
|
|
@ -65,12 +69,12 @@
|
|||
{% for photo in search_result.photos %}
|
||||
<div class="col">
|
||||
<div class="card h-100">
|
||||
<a href="{{ url_for(request.endpoint, enwp=enwp, flickr=photo.flickr_url, img=photo.medium_url) }}">
|
||||
<a href="{{ url_for(request.endpoint, enwp=enwp, flickr=photo.flickr_url, img=photo.medium_url, license=photo.license, flickr_user=photo.realname or photo.username, cat=cat) }}">
|
||||
<img src="{{ photo.thumb_url }}" alt="{{ photo.title }}" class="card-img-top" style="aspect-ratio: 1; object-fit: cover;">
|
||||
</a>
|
||||
<div class="card-body p-2">
|
||||
<p class="card-text small mb-1 text-truncate" title="{{ photo.realname or photo.username }}">{{ photo.realname or photo.username }}</p>
|
||||
<span class="badge {{ 'bg-success' if photo.license in [4, 5, 7, 8, 9, 10] else 'bg-secondary' }}">{{ photo.license_name }}</span>
|
||||
<span class="badge {{ 'bg-success' if photo.license in [4, 5, 7, 8, 9, 10, 14, 15] else 'bg-secondary' }}">{{ photo.license_name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -82,7 +86,7 @@
|
|||
<ul class="pagination justify-content-center">
|
||||
{% if search_result.current_page > 1 %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{{ url_for(request.endpoint, enwp=enwp, page=search_result.current_page - 1) }}">Previous</a>
|
||||
<a class="page-link" href="{{ url_for(request.endpoint, enwp=enwp, page=search_result.current_page - 1, cat=cat) }}">Previous</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
|
|
@ -95,7 +99,7 @@
|
|||
|
||||
{% if start_page > 1 %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{{ url_for(request.endpoint, enwp=enwp, page=1) }}">1</a>
|
||||
<a class="page-link" href="{{ url_for(request.endpoint, enwp=enwp, page=1, cat=cat) }}">1</a>
|
||||
</li>
|
||||
{% if start_page > 2 %}
|
||||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
|
|
@ -104,7 +108,7 @@
|
|||
|
||||
{% for p in range(start_page, end_page + 1) %}
|
||||
<li class="page-item {{ 'active' if p == search_result.current_page else '' }}">
|
||||
<a class="page-link" href="{{ url_for(request.endpoint, enwp=enwp, page=p) }}">{{ p }}</a>
|
||||
<a class="page-link" href="{{ url_for(request.endpoint, enwp=enwp, page=p, cat=cat) }}">{{ p }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
||||
|
|
@ -113,13 +117,13 @@
|
|||
<li class="page-item disabled"><span class="page-link">...</span></li>
|
||||
{% endif %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{{ url_for(request.endpoint, enwp=enwp, page=search_result.total_pages) }}">{{ search_result.total_pages }}</a>
|
||||
<a class="page-link" href="{{ url_for(request.endpoint, enwp=enwp, page=search_result.total_pages, cat=cat) }}">{{ search_result.total_pages }}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if search_result.current_page < search_result.total_pages %}
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="{{ url_for(request.endpoint, enwp=enwp, page=search_result.current_page + 1) }}">Next</a>
|
||||
<a class="page-link" href="{{ url_for(request.endpoint, enwp=enwp, page=search_result.current_page + 1, cat=cat) }}">Next</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled">
|
||||
|
|
@ -136,8 +140,11 @@
|
|||
|
||||
{% elif name and not flickr_url %}
|
||||
|
||||
{% if cat %}
|
||||
<p><a href="{{ url_for('category_search', cat=cat) }}">← Back to category</a></p>
|
||||
{% endif %}
|
||||
<p>Wikipedia article: {{ name }}</p>
|
||||
<p class="text-warning">No photos found. Try a different search term.</p>
|
||||
<div class="alert alert-warning">No photos found. Try a different search term.</div>
|
||||
<p><a href="https://flickr.com/search/?view_all=1&text={{ '"' + name + '"' | urlencode }}" target="_blank">Search on Flickr directly</a></p>
|
||||
|
||||
{% endif %}
|
||||
|
|
@ -155,7 +162,36 @@
|
|||
{% else %}
|
||||
<div class="col-12">
|
||||
{% endif %}
|
||||
{% if flickr_user %}
|
||||
<p><strong>User:</strong> <a href="{{ flickr_user_url }}" target="_blank">{{ flickr_user }}</a></p>
|
||||
{% endif %}
|
||||
{% if previous_messages %}
|
||||
<div class="alert alert-info">
|
||||
<strong>Previously contacted:</strong> You have sent {{ previous_messages | length }} message(s) to this user.
|
||||
<ul class="mb-0 mt-2">
|
||||
{% for msg in previous_messages %}
|
||||
<li><a href="{{ msg.url }}" target="_blank">{{ msg.subject }}</a> <small class="text-muted">({{ msg.date }})</small></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if is_free_license %}
|
||||
<div class="alert alert-success">
|
||||
<strong>Ready to upload!</strong> This photo is licensed under <span class="badge bg-success">{{ license_name }}</span> and can be used on Wikipedia.
|
||||
</div>
|
||||
<p>
|
||||
<a href="https://commons.wikimedia.org/wiki/Special:UploadWizard" class="btn btn-primary" target="_blank">
|
||||
Upload to Wikimedia Commons
|
||||
</a>
|
||||
</p>
|
||||
<p class="text-muted small">
|
||||
After uploading, you can add the image to the Wikipedia article for <a href="{{ wikipedia_url }}" target="_blank">{{ name }}</a>.
|
||||
</p>
|
||||
{% else %}
|
||||
<p><a href="https://www.flickr.com/mail/write/?to={{nsid}}" class="btn btn-primary">Send message on Flickr</a></p>
|
||||
{% if license_name %}
|
||||
<div class="mb-2"><strong>Current license:</strong> <span class="badge {{ 'bg-success' if license_code in [4, 5, 7, 8, 9, 10, 14, 15] else 'bg-warning text-dark' if license_code in [1, 2, 3, 6, 11, 12, 13, 16] else 'bg-secondary' }}">{{ license_name }}</span></div>
|
||||
{% endif %}
|
||||
<div class="mb-2"><strong>Subject:</strong> {{ subject }} <button class="btn btn-sm btn-outline-secondary" id="copy-subject">copy</button></div>
|
||||
<div>
|
||||
<h5>Message <button class="btn btn-sm btn-outline-secondary" id="copy-message">copy</button></h5>
|
||||
|
|
@ -163,6 +199,10 @@
|
|||
<p>{{ p }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<p class="mt-3">
|
||||
<a href="{{ url_for('start', enwp=enwp, cat=cat) if cat else url_for('start', enwp=enwp) }}">← Back to search results</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,33 @@
|
|||
{# vim:ft=jinja
|
||||
#}
|
||||
{% if is_nonfree_cc %}
|
||||
Hi,
|
||||
|
||||
I'd like to use your photo to illustrate the article about {{ name }} on Wikipedia.
|
||||
|
||||
{{ flickr_url }}
|
||||
|
||||
{{ wiki_part1 }}{{ wiki_part2 | urlencode }}
|
||||
|
||||
I noticed your photo is licensed under {{ license_name }}. Thank you for sharing your work with a Creative Commons license! Unfortunately, Wikipedia can only use images that allow commercial use and derivative works, so the current license restrictions prevent us from using it.
|
||||
|
||||
{% if 'NC' in license_name and 'ND' in license_name %}
|
||||
The "NonCommercial" restriction means the image can't be used on Wikipedia because Wikipedia content may be reused commercially. The "NoDerivs" restriction also prevents use because Wikipedia needs to allow image cropping and other modifications.
|
||||
{% elif 'NC' in license_name %}
|
||||
The "NonCommercial" restriction means the image can't be used on Wikipedia because Wikipedia content may be reused commercially by anyone.
|
||||
{% elif 'ND' in license_name %}
|
||||
The "NoDerivs" restriction means the image can't be used on Wikipedia because Wikipedia needs to allow modifications like cropping or colour correction.
|
||||
{% endif %}
|
||||
|
||||
Would you consider changing the license to Creative Commons Attribution (CC BY) or Attribution-ShareAlike (CC BY-SA)? These licenses still require credit to be given to you, but allow the broader use that Wikipedia requires.
|
||||
|
||||
To adjust the license settings, you can click on the license name on the right-hand side of the photo's page, just underneath the date.
|
||||
|
||||
Thanks,
|
||||
|
||||
Edward
|
||||
edward@4angle.com
|
||||
{% else %}
|
||||
Hi,
|
||||
|
||||
I'd like to use your photo to illustrate the article about {{ name }} on Wikipedia.
|
||||
|
|
@ -18,3 +46,4 @@ Thanks,
|
|||
|
||||
Edward
|
||||
edward@4angle.com
|
||||
{% endif %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue