| Error: It's not possible to get tags to HTML
function tagRss($text,$argv,&$parser) {
$args = '';
foreach ($argv as $k => $v) $args .= "$k: $v\n";
return "tagRss():\n\n";
}
# Needed in some versions to prevent Special:Version from breaking
function __toString() { return 'SimpleRSS'; }
# Expand the rss-magic
function magicRss(&$parser) {
# Populate $argv with both named and numeric parameters
$argv = array();
foreach (func_get_args() as $arg) if (!is_object($arg)) {
if (preg_match('/^(.+?)\\s*=\\s*(.+)$/',$arg,$match)) $argv[$match[1]] = $match[2]; else $argv[] = $arg;
}
global $wgRSSUseAjax;
if ($wgRSSUseAjax) {
# Render a container which does ajax requests for content
$text = " an ajax thingie ";
}
else {
# Not using ajax, render the output now
# TODO enforce required params: url template
$error = "fatal error: no template provided";
$error = "fatal error: no url provided";
# template params
$headTemplate = "RSSHead";
$itemTemplate = "RSSItem";
$footTemplate = "RSSFoot";
# grab each url and process
$data = wfReadRSS(preg_split("/[\n\r]/", $argv[url], -1, PREG_SPLIT_NO_EMPTY));
# dump data
foreach ($data as $v) {
# create head template
wfListArrayKeys($v->channel, "", $channel);
$text .= wfMakeTemplate($headTemplate, $channel);
# loop creating item templates
foreach($v->items as $item) {
wfListArrayKeys($item, "", $itemResult);
$text .= wfMakeTemplate($itemTemplate, $itemResult);
}
# create foot template (same as head)
wfListArrayKeys($v->channel, "", $channel);
$text .= wfMakeTemplate($footTemplate, $channel);
}
}
# Return result with available parser flags
return array(
$text,
found => true,
nowiki => false,
noparse => false,
noargs => false,
isHTML => false
);
}
} # object end
- build array of key-value pairs into template syntax
- {{TemplateName...
| Error: It's not possible to get title=foo... | Error: It's not possible to get link=http://foo.com... | Error: It's not possible to get description=Hello!}}
function wfMakeTemplate($template, $array) {
foreach($array as $key => $value)
$params .= "\n... | Error: It's not possible to get ".$key."=".$value;
return "{{".$template.$params."}}\n";
}
- build array of keys to publish (it's recursive!)
- WARNING because this function uses a hash to eliminate duplicate keys
- it no good for lists of items, only one at a time.
function wfListArrayKeys($array, $parent="", &$result) {
foreach($array as $key => $value) {
if(is_array($value))
wfListArrayKeys($value, "$parent$key", $result);
else
$result[$parent.$key] = $value;
}
}
function wfReadRSS($urls) {
$data = array();
foreach ($urls as $url) {
$data[] = fetch_rss($url);
}
return $data;
}
- Needed in MediaWiki >1.8.0 for magic word hooks to work properly
function wfSimpleRSSLanguageGetMagic(&$magicWords,$langCode = 0) {
global $wgSimpleRSSMagic;
$magicWords[$wgSimpleRSSMagic] = array(0,$wgSimpleRSSMagic);
return true;
}
- Called from $wgExtensionFunctions array when initialising extensions
function wfSetupSimpleRSS() {
global $wgSimpleRSS;
$wgSimpleRSS = new SimpleRSS();
}
... |