User:LinkFA-Bot/function
Appearance
Detailed explanation of the bot's work
[edit]The database tables
[edit]This bot (written in PHP) is using a local MySQL - database with (currently) 3 tables, just to keep the number of queries it has to do low.
- LinkFA_config
- The config-table keeps the current phase or state of the bot, so when it's stopped, it can continue where it left off.
- LinkFA_linking_articles
- A list of articles using the Link FA template (or the respective template on the wikipedia), and a marker for each article whether said article has been checked or not.
- LinkFA_featured_articles
- A list of articles marked as 'featured' in any wikipedia-language.
A bot run
[edit]The following steps are basically what the bot does on a full run. The order does not exactly match the code, but fit to the program logic.
Preparation
[edit]- Empty the database-tables LinkFA_linking_articles and LinkFA_featured_articles
- Gather all articles from all wikipedia languages we are supposed to work on that are using the template Link FA and add them to LinkFA_linking_articles
- Read all links from the Templates. For all links, gather all articles using the template and add those to LinkFA_featured_articles
- Read all links from Categories. For all links, gather all articles within those categories and add those to LinkFA_featured_articles
- Go to mode Check
Check
[edit]- Get one article from LinkFA_linking_articles that has not been marked 'done' yet. (Sorted alphabetically ascending by title, language version ignored for sorting). If there is none left, go to mode Search
- Get the text of the latest revision
- mark the current article as 'done'
- gather all interwiki links of the article
- For each interwiki link, check whether the destination is included in LinkFA_featured_articles. If yes, the interwiki link should be marked.
- Gather all occurrences of Link FA from the article
- Compare the "should be marked" list with the "is marked" list - if they are equal, skip to the next article
- For all Markups that would be erased, check whether the link only points to a redirect and - if so - try to resolve that and check the link again.
- Remove all Link FA markups from the article text
- Add those Link FA markups that were found to be needed to the article, right above the interwiki link block itself
- save the article
Search
[edit]- Get a not yet 'checked' article from LinkFA_featured_articles. If there's none left, the bot is done.
- Mark the article as 'checked'
- Check the article's interwiki - links and search for a link to any of the wikis the bot works on. If there's none, the bot just skips the article (creating an interwiki - link - net is left to the pros).
- If there's an article linked in that points to an article we didn't encounter during the 'Check' phase, and the found article already has a backlink to the featured article we're working on, run a Check on the found article.