Saturday, January 06, 2007

MediaWiki Hacks III

This blog moved to a new location, please visit us at http://ramble.m2m.at.

To integrate RSS feeds there are a couple extensions for MediaWiki. The most up to date extension seems to be GISWiki/RSS which uses Magpie RSS as back end to fetch the RSS feeds.

To enable blogger atom feeds some tweaks are necessary to match the different formats:

Find the comment "# Bild items" and enter the following lines into the following foreach loop:
if (isset($item['atom_content'])) {
 $item['description'] =& $item['atom_content'];
 $item['date_timestamp'] = parse_w3cdtf($item['published']);
}
Above the "# Bild items" comment there is another foreach loop. Place the following lines inside that loop right after the if statement.
if (isset($item['atom_content']) && $item['atom_content']) {
 $description = true; break;
}
Because we did not want to show the complete description we added the following function to truncate the text:
function mTruncate($string, $length = 200, $etc = ' ...') {
 if ($length == 0) return '';
 $string = strip_tags($string);
 if (strlen($string) <= $length) return $string;       
 $length -= strlen($etc);       
 return substr(preg_replace('/\s+?(\S+)?$/', '',     
   substr($string, 0, $length+1)), 0, $length).$etc; 
}
To activate the truncate function we changed the following line
if ($text) $output.="\n$text";
to
if ($text) $output .= "\n" . mTruncate($text);
multilang breaks NOSECTIONEDIT magic word
To fix this we had to add the following line:
  $parser->mOptions->mEditSection = false; 

No comments: