Tech
Tech-related questions about third-party wikis should be asked at mw:Project:Support desk. |
A place to talk about tech related to a Wikimedia wiki.
Have a technical wiki question? Ask here. This can include, for example:
- requests for new tools, scripts, and bots;
- help with CSS or JavaScript;
- API help;
- and data collection help (including database queries).
If you are not using the "New topic tool", such as the "Ask a question" button above, please sign manually using four tildes (~~~~
), or by clicking on the signature icon ; this will automatically generate your name and the current timestamp when you publish your changes.
Phabricator profile question
editmw:Talk:Phabricator/Help JJPMaster (she/they) 14:44, 13 January 2025 (UTC)
aide
editBonjour je n'y arrive pas c'est la triste réalité: Toujours ce message : Certaines informations figurant dans cet article ou cette section devraient être mieux reliées aux sources mentionnées dans les sections « Bibliographie », « Sources » ou « Liens externes » (février 2023). Vous pouvez améliorer la vérifiabilité en associant ces informations à des références à l'aide d'appels de notes. Je cherche à metter à jour cet article et ajouter une publication Je suis conscient que cela puisse demander du temps. Je suis ouvert à une proposition de remunerer une telle aide pour https://fr.wikipedia.org/wiki/Ioan_Petrescu Merci PETRESI073767 (talk) 16:56, 14 January 2025 (UTC)
- Vous devriez poser votre question sur la Wikipédia française. Essayez cette page Wikipédia:Forum des nouveaux MarcGarver (talk) 17:07, 14 January 2025 (UTC)
共有データベースを使用した場合のSocialProfileについて
edit当方、マルチwiki運用をした上でユーザーだけは共有データベースを用いております。 https://www.mediawiki.org/wiki/Manual:Shared_database/ja
その上で SocialProfile (https://www.mediawiki.org/wiki/Extension:SocialProfile) を使いたいのですが、wiki ごとに DB が分かれており、その wiki の DB を参照してしまいます。 wiki DB の下には user_profile は存在していないので下記のようなエラーが発生しています。 これを sharedDB に設定した DB を参照して、`share.user_profile` とさせるにはどうしたらいいでしょうか?
PHP Deprecated: Caller from MediaWiki::restInPeace ignored an error originally raised from UserProfile::getProfile: [1146] Table 'contents.user_profile' doesn't exist in /var/www/html/h1g-app/src/includes/debug/MWDebug.php on line 381
119.242.150.186 05:50, 15 January 2025 (UTC)
- This venue is not for general MediaWiki support. See the notice at the top of the page. — JJMC89 (T·C) 17:44, 15 January 2025 (UTC)
Geohack patch
editI have a patch for Geohack that I'd like to get reviewed and merged, but I am not getting any replies from Magnus Manske. Does anyone how I can progress on getting my patch merged? --ysangkok (talk) 22:46, 20 January 2025 (UTC)
A map problem on Belarusian Wikipedia
editHello!
There's a problem with the coordinates of the dot on the map on this page: https://be.wikipedia.org/wiki/%D0%90%D1%81%D1%96%D0%BF%D0%BE%D0%B2%D1%96%D1%87%D1%8B
The coordinates of the town in WikiData and in the main template are set right, but the point is located wrong. The red dot location is too much south.
The problem is connected with these module: https://be.wikipedia.org/wiki/Модуль:Location_map, https://be.wikipedia.org/wiki/Модуль:Location_map/styles.css
How can I fix it? Hapanovicz Anton (talk) 20:36, 22 January 2025 (UTC)
Scoring tool for Wikidata
editHello! I would like to request a scoring tool for Wikidata. I am part of a project that organizes editing contests on Wikipedia, Wikidata, and Wikimedia Commons, and we feel the need for a tool that simplifies the process of scoring contributions on Wikidata. In the Brazilian context, we have a similar initiative for Wikipedia called Wikiscore, but nothing comparable for Wikidata. Does anyone here know of a similar tool for Wikidata or would be interested in participating in its development? Vsdetoni (Projeto Mais+) (talk) 18:25, 28 January 2025 (UTC)
Understanding Wikipedia titles batching API
editWith the MediaWiki API we can query the Wikipedia API. One of the fields is `titles` where one *or more* titles can be queried at the same time. Batching them together is recommended in high load scenarios to avoid multiple consecutive requests. Multiple titles should be separated by a pipe `|` character.
I am using the Wikipedia API to find "translations" of categories. Let's say I have an English category "Antiquity", I want to find the corresponding category in a different language. That is possible by querying the API for the prop `langlinks`.
I find that, indeed, I can find such one-on-one mappings of an English category if I do not use batching, but if I *do* use batching, I do not always get all of the results back. To illustrate, I have a list of English categories, and at each iteration I process one item more than before (starting with only one). With batching, it becomes clear that with larger lists (still well within the max. limit of 50 imposed by the API), the earlier categories are lost and not included anymore. When not using batching (batch size=1), this issue does not occur.
import requests
def get_translated_category(category_titles: str | list[str], target_lang: str, batch_size: int = 50) -> list[str]:
"""Fetch the translated equivalent of a Wikipedia category."""
endpoint = "https://en.wikipedia.org/w/api.php"
if isinstance(category_titles, str):
category_titles = [category_titles]
category_titles = [f"Category:{title}" for title in category_titles]
translated_categories = {}
# API is limited to 50 titles per request
for start_idx in range(0, len(category_titles), batch_size):
end_idx = start_idx + batch_size
batch_titles = category_titles[start_idx:end_idx]
params = {
"action": "query",
"format": "json",
"prop": "langlinks",
"titles": "|".join(batch_titles),
"lllimit": "max"
}
response = requests.get(endpoint, params=params)
data = response.json()
pages = data.get("query", {}).get("pages", {})
for page_data in pages.values():
title = page_data["title"].split(":")[-1]
if title in translated_categories:
print("We already found this category title!")
langlinks = page_data.get("langlinks", [])
for link in langlinks:
if link["lang"] == target_lang:
translated_categories[title] = link["*"].split(":")[-1]
return translated_categories
if __name__ == "__main__":
english_categories: list[str] = [
"Classical antiquity",
"Late antiquity",
"Latin-language literature",
"Roman Kingdom",
"Roman Republic",
"Roman Empire",
"Byzantine Empire",
"Latin language",
"Ancient Greek",
"Ancient Greece",
"Ancient Greek literature",
"Medieval history of Greece",
]
print("Batch size 50 (default)")
for idx in range(len(english_categories)):
categories = english_categories[:idx+1]
latin_categories = get_translated_category(categories, "la")
print(latin_categories)
print()
print("Batch size 1 (no batching)")
for idx in range(len(english_categories)):
categories = english_categories[:idx+1]
latin_categories = get_translated_category(categories, "la", batch_size=1)
print(latin_categories)
The output of the code above is:
# Batch size 50 (default)
{'Classical antiquity': 'Res classicae'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae', 'Roman Empire': 'Imperium Romanum'}
{'Byzantine Empire': 'Imperium Byzantinum', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae', 'Roman Empire': 'Imperium Romanum'}
{'Byzantine Empire': 'Imperium Byzantinum', 'Late antiquity': 'Antiquitas Posterior', 'Latin language': 'Lingua Latina', 'Roman Empire': 'Imperium Romanum'}
{'Byzantine Empire': 'Imperium Byzantinum', 'Late antiquity': 'Antiquitas Posterior', 'Latin language': 'Lingua Latina', 'Roman Empire': 'Imperium Romanum'}
{'Ancient Greece': 'Graecia antiqua', 'Byzantine Empire': 'Imperium Byzantinum', 'Late antiquity': 'Antiquitas Posterior', 'Roman Empire': 'Imperium Romanum'}
{'Ancient Greece': 'Graecia antiqua', 'Byzantine Empire': 'Imperium Byzantinum', 'Late antiquity': 'Antiquitas Posterior', 'Roman Empire': 'Imperium Romanum'}
{'Ancient Greece': 'Graecia antiqua', 'Byzantine Empire': 'Imperium Byzantinum', 'Late antiquity': 'Antiquitas Posterior', 'Roman Empire': 'Imperium Romanum'}
# Batch size 1 (no batching)
{'Classical antiquity': 'Res classicae'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae', 'Roman Empire': 'Imperium Romanum'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae', 'Roman Empire': 'Imperium Romanum', 'Byzantine Empire': 'Imperium Byzantinum'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae', 'Roman Empire': 'Imperium Romanum', 'Byzantine Empire': 'Imperium Byzantinum', 'Latin language': 'Lingua Latina'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae', 'Roman Empire': 'Imperium Romanum', 'Byzantine Empire': 'Imperium Byzantinum', 'Latin language': 'Lingua Latina', 'Ancient Greek': 'Lingua Graeca antiqua'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae', 'Roman Empire': 'Imperium Romanum', 'Byzantine Empire': 'Imperium Byzantinum', 'Latin language': 'Lingua Latina', 'Ancient Greek': 'Lingua Graeca antiqua', 'Ancient Greece': 'Graecia antiqua'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae', 'Roman Empire': 'Imperium Romanum', 'Byzantine Empire': 'Imperium Byzantinum', 'Latin language': 'Lingua Latina', 'Ancient Greek': 'Lingua Graeca antiqua', 'Ancient Greece': 'Graecia antiqua', 'Ancient Greek literature': 'Litterae Graecae antiquae'}
{'Classical antiquity': 'Res classicae', 'Late antiquity': 'Antiquitas Posterior', 'Latin-language literature': 'Litterae Latinae', 'Roman Empire': 'Imperium Romanum', 'Byzantine Empire': 'Imperium Byzantinum', 'Latin language': 'Lingua Latina', 'Ancient Greek': 'Lingua Graeca antiqua', 'Ancient Greece': 'Graecia antiqua', 'Ancient Greek literature': 'Litterae Graecae antiquae'}
It should be immediately clear that there is a difference between batching and not using batching and, more worrisome, that using batching leads to some items being discarded. I thought that perhaps this would be the case if categories are merged in Latin and have the same name, so the API resolves to only returning one of them, but as far as I can tell that is not the case.
How can I ensure that batching my requests (titles) together, I get the same results as firing individual requests with the Wikipedia API?
EDIT: after further investigation it would seem that the API does return results for all categories (the `pages ` variable) but for some reason the corresponding languages (`langlinks`) are not the same. BramVanroy (talk) 13:21, 12 February 2025 (UTC)
- You need to follow API continuation, e.g. using
continuation=True
when using mwapi. Lucas Werkmeister (talk) 14:00, 12 February 2025 (UTC)