Topic on Extension talk:SyntaxHighlight

how to batch replace <source> with <syntaxhighlight>

4
Summary by Ernstkm

There are several options: 1) use a (semi)automated editing tool such as AutoWikiBrowser or Pywikibot; 2) Extension:ReplaceText; or 3) use a tool such as sed to edit the raw article text of a SQL database dump, then re-import from that SQL dump. The first two can be done on a live site; the third would require special care (such as setting $wgReadOnly) to ensure no user edits are lost in the interim.

Hawk914 (talkcontribs)

Hi, I am new to mediawiki. But I have to upgrade an old mediawiki that contains lots of page with source tags. Since it's deprecated by syntaxhighlight tag, how do I replace all source tags in all pages with syntaxhighlight tag in a batch way?

Dinoguy1000 (talkcontribs)

The way I'd do it is via AutoWikiBrowser (AWB) or a similar (semi)automated editing tool (if you're handy with a programming language and don't mind spending time on it, you could also write such a tool yourself). If you can install extensions yourself, or can request to have them installed, another option is Extension:ReplaceText , though personally I don't recommend this versus running AWB or similar.

2001:A61:BDD:901:C911:EA05:A98:C376 (talkcontribs)

Another possibility for linux is the pywikibot replace script (see Manual:Pywikibot/replace.py) with the following user-fix.py entry:

fixes['source_tag'] = {
    'regex': False,
    'msg': {
        '_default': 'source-tag ersetzt durch syntaxhighlight',
    },
    'replacements': [
        (r'<source', '<syntaxhighlight'),
        (r'</source', '</syntaxhighlight'),
    ]
}

called like this:

python3 pwb.py replace -fix:source_tag -start:!
Mustakioren (talkcontribs)

that worked for me

cat wiki.sql | sed 's/<source/<syntaxhighlight/g' | sed 's/<\/source/<\/syntaxhighlight/g' > wiki.new.sql

make sure to backup and check thoroughly after importing back

Reply to "how to batch replace <source> with <syntaxhighlight>"