Search code examples
mediawikimediawiki-apimediawiki-extensions

MediaWiki: How to update a link status programmatically


My extension renders additional links on a page (that is adds some <a href='...'>...</a> to the page text (in HtmlPageLinkRendererEnd hook)).

See small arrows in https://withoutvowels.org/wiki/Tanakh:Genesis_1:1 for an example. The arrows are automatically added by my extension (sorry, at the time of writing this the source code is not yet released).

The problem is that red/blue ("new") status is not updated for links which I add.

Please explain how to make Wikipedia to update color of my links as appropriate together with regular [[...]] MediaWiki links.

My current workaround is to run php maintenance/update.php. It is a very bad workaround. How to do it better?


Solution

  • With valuable help of Wikitech-l mailing list, I found a solution.

    The solution is to use ParserAfterTidy hook.

    public static function onParserAfterTidy( &$parser, &$text ) {
                # ...
    
                $parserOutput = $parser->getOutput();
    
                foreach($parserOutput->getLinks() as ...) {
                        # ...
    
                        $parserOutput->addLink( Title::newFromDBkey(...) );
                }
    }