User:LinkFA-Bot/function
From Wikipedia, the free encyclopedia
Contents |
[edit] Detailed explanation of the bot's work
[edit] The database tables
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. In addition, the config table keeps a counter of added / removed Link FA markups for statistical purpose.
- LinkFA_local_articles
- A list of local articles using the Link FA template, and a marker for each article whether said article has been checked or not.
- LinkFA_remote_articles
- A list of articles similar to articles, but with an extra language code field. In this table, the excellent articles of foreign wikis are gathered and marked when encountered / linked to.
[edit] A bot run
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.
[edit] Preparation
- Empty the database-tables LinkFA_local_articles and LinkFA_remote_articles
- Gather all articles using the template Link FA and add them to LinkFA_local_articles
- Read all links from Templates. For all links except those leading back into the work wiki, gather all articles using the template and add those to LinkFA_remote_articles
- Read all links from Categories. For all links except those leading back into the work wiki, gather all articles within those categories and add those to LinkFA_remote_articles
- Go to mode Check
[edit] Check
- Get one article from LinkFA_local_articles that has not been marked 'done' yet. (unsorted, the order only depends on the database, as it doesn't matter at all). 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_remote_articles. If yes, the interwiki link should be marked, and the article in foreign_articles gets marked as 'referenced'
- Gather all occurences 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 before the interwiki link block itself
- save the article
[edit] Search
- Get a not yet 'referenced' article from foreign_articles. If there's none left, the bot is done.
- Mark the article as 'referenced' (or 'done with')
- Check the article's interwiki - links and search for a link to the local wiki. If there's none, the bot just skips the article (creating an interwiki - link - net is left to the pros).
- If there's a local article linked in, and the local article already has a backlink to the featured article, run a Check on the local article.