A proposal to move this page to MediaWiki.org was rejected.

Situation

edit

You have installed your own Mediawiki engine and you are hosting (have imported) more than one (former) Wikis on/into it, becoming a so called Wikihive or Wikifarm. So you have pages sorted like Somewiki/Fnord, Somewiki/Foobar and now the users of Somewiki are asking for their own Recent Changes page that only includes the pages of their (sub)-wiki, so a subset of your complete RC page that only shows pages beggining with the string "Somewiki" in this case. (Another approach would have been sorting out by categories,but this would have meant having to look inside page content instead of doing it inside a SELECT statement).

So i read Write your own MediaWiki extension and came up with this code:

<customrc> Tag

edit

Users can just insert a tag like <customrc>Whatever</customrc> into any wiki page and will include a Recent changes table of all pages beginning with "Whatever". Normally they would insert this into index.php/Subwiki/RecentChanges then.

Example

edit

Compare S23Wiki:Debian/RecentChanges with its source.


Custom Recent Changes Extension

edit
<?php
 # Custom RC-page WikiMedia extension
 # display custom recent changes pages for a subset of pages inside any wiki page
 # insert <customrc>Fnord<customrc> into a wikipage and it will be replaced
 # by a table containing stripped RecentChanges for all pages begging with "Fnord".
 # This is made for making RC pages for "subwikis" on a "wikihive" where all pages
 # below a /Subwiki page should be taken into account. like yourwiki/subwiki/RecentChanges.
 # by mutante of s23 - 01.03.2005

$wgExtensionFunctions[] = "wfCustomRCExtension";

  function wfCustomRCExtension() {
     global $wgParser;

     # register the extension with the WikiText parser
     # the first parameter is the name of the new tag. In this case it defines the tag <example> ... </example>
     # the second parameter is the callback function for processing the text between the tags
     $wgParser->setHook( "customrc", "renderCustomRC" );
 }
# The callback function for converting the input text to HTML output
 function renderCustomRC( $input ) {

# strip possible evil characters from user 
$input = mysql_escape_string($input);

# db connect (replace "password" of course)
$hd = mysql_connect("localhost", "wikiuser", "password") or die ("Unable to connect");

# select db
mysql_select_db ("wikidb", $hd) or die ("Unable to select database");

# mysql query
$res = mysql_query("SELECT rc_id,rc_timestamp,rc_title,rc_comment,rc_user_text FROM recentchanges WHERE rc_title LIKE \"$input%\" ORDER by rc_timestamp desc", $hd) or die ("Unable to run query");

# table head
$output=<<<FNORD
<h3>$input-wiki Recent Changes</h3>
<table border="1">
<tr><th>Time</th><th>Title</th><th>Comment</th><th>Author</th></tr>
FNORD;

# main loop (spit out table rows)

while ($row = mysql_fetch_assoc($res))
{

# assign into variables fetching from mysql-table rows

$rcid = $row["rc_id"];
$rctimestamp = $row["rc_timestamp"];
$rctitle = $row["rc_title"];
$rccomment = $row["rc_comment"];
$rcuser = $row["rc_user_text"];

# convert the mediawiki custom yymmddhhmmss timestamp
$year = substr($rctimestamp, 0, 4);
$month = substr($rctimestamp, 4, 2);
$day = substr($rctimestamp, 6, 2);
$hour = substr($rctimestamp, 8, 2);
$minute = substr($rcstimestamp, 10, 2);
$second = substr($rctimestamp, 12, 2);

$date = date('M d, Y H:m:s', mktime($hour, $minute, $second, $month, $day, $year));

# output table rows (replace yourhost.org)

$output.="<tr><td>$date</td><td><a href=\"http://yourhost.org/wiki/index.php/$rctitle\">$rctitle</a></td><td>$rccomment</td><td><a href=\"http://yourhost.org/wiki/index.php/User:$rcuser\">$rcuser</a></td></tr>";
}

# close db connect
mysql_close($hd);

# foot
$output.="</table>";

return $output;
 }
 ?>


Mutante 22:07, 1 Mar 2005 (UTC)