Pybot Wiki
Register
Advertisement
You may be looking for our collection of fix files.
This page will INTRODUCE you to a basic topic.
This page describes a USER-FIX.

A user-fix is a user-defined bit of regex that is used by replace.py to perform some kind of text replacement.

It is one of the two ways in which a regular expression can be introduced into the replace.py script. It can be contrasted with what, for lack of a better term, we might call "inline regex" — a piece of regex entered at the command prompt.

User-fixes offer at least two significant advantages over inline regex:

  • they can handle multiple replacements simultaneously
  • they are saved, and therefore can be called at a later date.

Example of a user-fix[]

Inline regex is great for the quick fix. But inline regex only offers you the ability to change a single thing — like a single word that's frequently misspelled, or the removal of a single section that appears on several articles.

But what if you want to change several misspellings simultaneously? Or get rid of multiple categories?

For that, you need a user-fix.

Let's imagine you have an infobox that appears on hundreds of pages on your wiki. This temlate is called, let's say, Template:Story infobox. It has a couple of navigation variables on it for the previous and next stories in a series. These variables, sensibly, are called "previous story" and "next story", but you come to feel one day that this is just too long. You want to change the variables to "prev" and "next". So you open up user-fixes.py and you enter this:

fixes['prevnext'] = {
    'regex': True,
    'msg' : {
        'en': u'changing previous story/next story to just prev/next'
        },
    'replacements': [
        (r'[Pp]revious story( *?)=', r'prev\1='),
        (r'[Nn]ext story( *?)=', r'next\1='),
        ]
    }

To run this, you'd type:

ptyhon replace.py -fix:prevnext -transcludes:"Story infobox"

This would run the fix called prevnext on every page where the template Story infobox was transcluded. The replacement would take the word "Previous story" (or "previous story"), plus whatever spaces are before the equals sign, plus the equals sign itself, and replace it with prev<however many spaces existed before>=

And while it was replacing the "previous story" bit, it would also replace the "next story" variable.

If you were doing this with inline regex, you'd have to make two runs: one for "prev" and one for "next".

There's a lot you can do with user-fixes, and this page won't even attempt to list everything. Instead, go to our Fix Files and check out all the ready-to-use fixes that we have to offer.

How to employ user-fixes[]

Fixes are called by the following language:

python replace.py -fix:fixname <parameter defining the pages to work on>

Thus, if I wanted to call a user-fix named "spell" and apply it to every page in namespace:0, I would type the following:

python replace.py -fix:spell -start:!
Advertisement