Menu

#94 interwiki.py should follow category redirect templates

closed
xqt
interwiki (62)
5
2010-02-16
2007-05-21
No

Sometimes when a category is moved, a template like [[en:template:Template:Category redirect]] (see its interwiki links for similar templates in other languages) is left at the old category page.

It would be good if interwiki.py could check for the presence of a such template and follow the redirect to the new category as given by the template argument.

Discussion

  • Nobody/Anonymous

    Implementing this feature involves several steps.

    First the template needs to be detected. This is similar to isDisambig() in wikipedia.py. Perhaps that function should also require isCategory(), so the template is only detected when used in category pages. Unfortunately, there is no equivalent to the MediaWiki:Disambiguationspage to help us find out what the template name is in each language, so we have to list the template translations for each language. I think that should be manageable.

    I propose the new function be called isCategoryRedirect(). Then this function needs to be introduced where isRedirect() is used. Or perhaps isRedirect() should call it? That would save a lot of work.

    Are there some situations where it would be harmful to detect this template? Should the use of the new function be configurable?

     
  • Lars Aronsson

    Lars Aronsson - 2009-01-09

    The previous comment was by me. I don't know why I wasn't logged in.

     
  • Lars Aronsson

    Lars Aronsson - 2009-01-09

    I now have some code that I believe solves this. But since I'm a beginner in Python, I'd like someone more experienced to look at my code before it is submitted.

     
  • Russell Blau

    Russell Blau - 2009-01-09

    category_redirect.py already contains a list of category redirect templates, although only for a few sites. If it is desired to use this capability in other bots, then the template lists should probably be moved into the family files, and an is_category_redirect() method added to the Category object in catlib.py, or alternatively to the Page object.

     
  • Lars Aronsson

    Lars Aronsson - 2009-01-10

    Thanks, I hadn't even looked in category_redirect.py. For the moment, I just copied the list of template names to my version of wikipedia.py so all my changes are in one file. I have updated the list with more template names (and more synonyms).

    The detection of #REDIRECT in wikipedia.py is done in two places, using self.site.redirectRegex() both in Page._getEditPage() and GetAll.oneDone(). These are the two places I added an "elif" branch to look for category redirects. I don't fully understand why there needs to be two places to do this test, but that's a matter of overall design. The naming of redirectRegex() is also hardwired to the use of a single regex, which doesn't scale to category redirects. Perhaps a refactoring would lead to that function being renamed to isRedirect(). I think redirect detection does belong in the Site object, since it depends on language-specific synonyms to REDIRECT and to specific templates used for category redirects.

     
  • NicDumZ — Nicolas Dumazet

    Lars's patch

     
  • Lars Aronsson

    Lars Aronsson - 2009-01-12

    The previous comment was a failed attempt to submit a patch. The same code is available as the attached file mydiff. Most of this patch is a list of template names, that originated in category_redirect.py and really should move to family.py or some place like that.

    What I've done is to add an "elif" branch in the two places, where self.site.redirectRegex() is tested, so it also looks for these templates, but only if we are in a category page. Maybe self.site shouldn't hand out a regex, but instead provide the function that tests for redirects. Feel free to refactor this.

     
  • Russell Blau

    Russell Blau - 2009-01-13
    • assigned_to: nobody --> russblau
     
  • Russell Blau

    Russell Blau - 2009-01-15

    aronsson: Although your patch works, it causes an unacceptable slowdown in the loading of category pages. I have therefore reverted the change, and will not implement this feature for the time being. I'll leave this open in case anyone has a better idea.

     
  • Lars Aronsson

    Lars Aronsson - 2009-01-17

    Could you describe how you measure this slowdown, and what level of slowdown would be acceptable? All the code does is to test for strings similar to {{category redirect | something}}, which shouldn't be much slower than testing for #REDIRECT [[something]].

     
  • xqt

    xqt - 2010-02-16
    • labels: --> interwiki
    • assigned_to: russblau --> xqt
    • status: open --> closed
     
  • xqt

    xqt - 2010-02-16

    category redirects are handled similar to normal redirects since release 7936 (fix for #2949822). This also affects -initialredirect and -noredirect as well

     

Log in to post a comment.