I am currently upgrading our intranet Wiki installation to 1.21 (yes, we are 
one version behind), and I have faced the problem with deprecated message 
functions, as outlined at 
mediawiki.org<http://www.mediawiki.org/wiki/Manual:Messages_API#Deprecated_wfMsg.2A_functions>.
 For instance:

Instead of:
wfMsg( 'key' );
Do:
wfMessage( 'key' )->text();

The problem of course is that the parametrized messages can have arbitrary 
parameters which can be themselves function calls, making simple regexp 
substitution infeasible. Well, I figured out that Perl can be used to solve 
this problem, because Perl allows arbitrary recursive regexps, which are 
conveniently accessible via the Regexp::Common module. Something like this does 
the trick:

use Regexp::Common;

# Convert 'wfMsg->(...)' to 'wfMessage(...)->text()'
sub fix_wfMsg ($) {
    (my $string = shift) =~ 
s/wfMsg\s*($RE{balanced}{-parens=>'()'})/wfMessage$1->text()/g;
    return $string;
}

This method would take the string you provide (should be the entire file 
contents, to account for multi-line wfMsg calls), and do the appropriate string 
substitution to replace the deprecated call with the correct one, accounting 
for nested recursive parentheses. As far as I can tell, the only thing it can 
get wrong in unbalanced parentheses in comments, e.g. if your line ends in '// 
unbalanced paren (' type of comment.

I hope this helps someone.



_______________________________________________
MediaWiki-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l

Reply via email to