×
Create a new article
Write your page title here:
We currently have 3,185 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,185Articles

    Difference between revisions of "Custom Recent Changes"

    imported>mutante
    imported>mutante
    m
    Line 1: Line 1:
     
    Use <nowiki><customrc>Subset</customrc></nowiki> in any wiki page to include a custom Recent Changes page with this:
     
    Use <nowiki><customrc>Subset</customrc></nowiki> in any wiki page to include a custom Recent Changes page with this:
       
      +
    Example: check the [http://is-root.de/wiki/index.php?title=Debian/RecentChanges&action=edit source] of [[Debian/RecentChanges]].
       
     
    == Situation ==
     
    == Situation ==

    Revision as of 22:47, 1 March 2005

    Use <customrc>Subset</customrc> in any wiki page to include a custom Recent Changes page with this:

    Example: check the source of Debian/RecentChanges.

    Situation

    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:

    Custom Recent Changes Extension

    <?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;
     }
     ?>
    

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


    mutante 22:07, 1 Mar 2005 (UTC)

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.