Extension talk:Data
From MediaWiki.org
Any user names refer to users of that site, who are not necessarily users of MediaWiki.org (even if they share the same username).
Contents |
[edit] Indexes
What indexing should be used on the data_extension table. John Stanton 19:47, 4 November 2006 (UTC)
- I think at least item and key columns should be indexed. Nikola 02:28, 16 November 2006 (UTC)
[edit] Code
It seems that the following is needed to avoid PHP warnings:
$wgHooks['LanguageGetMagic'][] = 'wfDataLanguageGetMagic';
function wfDataLanguageGetMagic( &$magicWords, $langCode ) {
switch ( $langCode ) {
default:
$magicWords['data'] = array( 0, 'data' );
$magicWords['sort'] = array( 0, 'sort' );
}
return true;
}
Patrick 11:36, 5 February 2007 (UTC)
Note that the above conversation may have been edited or added to since the transfer. If in doubt, check the edit history.
[edit] Added default handling
Hi!
I just want to inform you that I have added the handling of defaults to the get function, so that one can use constructs like
{{#data:key|default}}
which will output "default" if key is not set. I have made it such, that it looks like parameter references in templates
{{{paramname|default}}}
I noticed that I needed this functionality pretty often, and that it can replace the somewhat lengthy
{{#if:{{#data:item->key}}|{{#data:item->key}}|default}}
If you want to include this functionality into the extension, just go ahead. Here is the modified "get" function:
function get(&$parser,$desc="",$default="") { list($lang,$item,$key)=$this->parseDesc($desc); if($key=="") return $item; #echo "$lang|$item|$key"; $res=mysql_query("SELECT `value` FROM data_extension WHERE `item`='". mysql_real_escape_string($item). "' AND `key`='". mysql_real_escape_string($key)."'"); $res=mysql_fetch_row($res); $r=$res[0]; if ($r=="") $r=$default; return array($r,"noparse"=>TRUE); }
Cheers --141.2.138.89 16:27, 6 November 2007 (UTC) (de:Benutzer:olenz)
[edit] PHP failing
Just downloaded the code from the 3 Feb update. I get the following error (twice) when I load any wiki page
Warning: array_slice() [function.array-slice]: The first argument should be an array in /var/www/wikijfh/languages/Language.php on line 1153
Noted that an extra piece of code (function wfDataLanguageGetMagic) is recommended and included in the latest version, except for the line
$wgHooks['LanguageGetMagic'][] = 'wfDataLanguageGetMagic';
I get the error with and without this extra line. I have created the required table in wikidb. My LocalSettings includes the following lines
include("extensions/Expr.php");
include("extensions/ParserFunctions.php");
include("extensions/Data.php");
Ideas ???
- The line is there, fourth line of code in wfDataExtension() function. But something weird is going on. Try moving data extension to the top of your list of extensions (including it before any other extension), see if that works. Alternarively, you could add a @ at the beginning of the line 1153 in languages/Language.php . Nikola Smolenski 09:32, 9 February 2008 (UTC)