Now that $wgMessageCache is obsolete in 1.18.0, what is the approved way for an extension to add a system message dynamically at runtime?
That is, what is the new way to do $wgMessageCache->addMessage(a, b)?
http://www.mediawiki.org/wiki/Manual:$wgMessageCache does not say.
Thanks, DanB
On 07/12/11 06:38, Daniel Barrett wrote:
Now that $wgMessageCache is obsolete in 1.18.0, what is the approved way for an extension to add a system message dynamically at runtime?
That is, what is the new way to do $wgMessageCache->addMessage(a, b)?
There's no precise equivalent.
You can add or modify messages when the cache is built by hooking LocalisationCacheRecache, and you can add a cache dependency to trigger a rebuild by adding elements to $allData['deps'].
What extension is this for?
-- Tim Starling
Tim Starling writes:
You can add or modify messages when the cache is built by hooking LocalisationCacheRecache, and you can add a cache dependency to trigger a rebuild by adding elements to $allData['deps'].
Thanks. Do I need to do both, or is this an either/or choice?
What extension is this for?
A parser tag extension (unreleased) that hits a SQL Server database to retrieve data. The parser tag dynamically categorizes its calling articles in "Category:Pages that hit SQL Server databases" for our bookkeeping purposes (and our DBA staff). To make this flexible, the extension doesn't insert a category tag directly, but transcludes a system message that contains the category tag. (This way we can change the category tag by editing the system message, rather than modifying PHP code.) That's where we're calling $wgMessageCache->addMessage().
DanB
On 07/12/11 09:52, Daniel Barrett wrote:
Tim Starling writes:
You can add or modify messages when the cache is built by hooking LocalisationCacheRecache, and you can add a cache dependency to trigger a rebuild by adding elements to $allData['deps'].
Thanks. Do I need to do both, or is this an either/or choice?
You don't need to add the cache dependency if the message only changes when the *.i18n.php or Messages*.php files change. It sounds like that's the case for your extension.
What extension is this for?
A parser tag extension (unreleased) that hits a SQL Server database to retrieve data. The parser tag dynamically categorizes its calling articles in "Category:Pages that hit SQL Server databases" for our bookkeeping purposes (and our DBA staff). To make this flexible, the extension doesn't insert a category tag directly, but transcludes a system message that contains the category tag. (This way we can change the category tag by editing the system message, rather than modifying PHP code.) That's where we're calling $wgMessageCache->addMessage().
You should have a look at how tracking categories work in the core, see Parser::addTrackingCategory(). It's not necessary to add any text to the page if there's a parser function on the page, the parser function can register the category directly in the output object.
-- Tim Starling
Tim Starling writes:
You should have a look at how tracking categories work in the core, see Parser::addTrackingCategory().
Ooo, shiny! Thanks for the great tip.
Is there any way to use addTrackingCategory (or similar) if the category name must be computed at runtime, not a piece of static text in a system message file? Our parser tag doesn't actually categorize articles in "Category:Pages that hit SQL Server databases" -- this was a simplification. It actually categorizes as "Category:Pages that hit SQL Server database %s", where %s is the name of the database (passed as a parameter to the parser tag).
This is why $wgMessageCache->addMessage() worked so well.
A variant $parser->addTrackingCategory($msg, $args...) would work great if it existed.
Thanks so much for your help, DanB
On 07/12/11 12:32, Daniel Barrett wrote:
A variant $parser->addTrackingCategory($msg, $args...) would work great if it existed.
Parser::addTrackingCategory() is protected, so you will have to duplicate it before you can use it in your extension. It only calls public functions, so it is possible to duplicate in a foreign class. You can add arguments to the copy.
-- Tim Starling
wikitech-l@lists.wikimedia.org