Page MenuHomePhabricator

Invalid DB key being added to categorylinks table on zhwikibooks
Open, Needs TriagePublic

Description

I created https://zh.wikibooks.org/wiki/User:This,_that_and_the_other/test (page id 23795) with the text [[Category:Blender 3D︰從入門到精通|插图集 ]] and a brand new invalid categorylinks row got added:

*** Looking for invalid cl_to entries in categorylinks...
*** Number of invalid rows: 4
   cl_from |  ns | dbkey
     15789 |  14 | Blender 3D︰从入门到精通
     15790 |  14 | Blender 3D︰从入门到精通
     15792 |  14 | Blender 3D︰从入门到精通
     23795 |  14 | Blender 3D︰从入门到精通     <<<<<< this one is new
*** Run with --fix to clean up these rows

This works fine on my local test wiki (in English). LinksUpdate.php has a call to $wgContLang->findVariantLink( $name, $nt, true ); which looks suspicious to me, and would explain why it works locally but fails on zhwikibooks.

Event Timeline

I agree, the call to $wgContLang->findVariantLink( $name, $nt, true ); looks suspicious.

It looks like LinksUpdate::getCategoryInsertions() assumes that ParserOutput::getCategories() returns an array with keys being title dbkeys, which at least in core and deployed extensions is true (it all depends on what gets passed to ParserOutput::addCategory()). But when $wgContLang->findVariantLink( $name, $nt, true ); does a variant conversion it populates $name with the title display text (->getText()) rather than the dbkey.

The thing to do is probably to 'cl_to' => $nt ? $nt->getDBkey() : $name instead of always using $name, or maybe skip the insertion entirely if $nt isn't a Title.