Difference between revisions of "Extension:TransformChanges.php"

From Organic Design wiki
(add credz and const ver etc)
(use odd and even classes here)
Line 6: Line 6:
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
if (!defined('MEDIAWIKI')) die('Not an entry point.');
 
   
 
   
define('TRANSFORMCHANGES_VERSION','1.0.1, 2007-05-10');
+
define('TRANSFORMCHANGES_VERSION','1.0.2, 2007-05-16');
 
   
 
   
 
$wgExtensionCredits['other'][] = array(
 
$wgExtensionCredits['other'][] = array(
Line 35: Line 35:
 
function wfTransformChangesLI($match) {
 
function wfTransformChangesLI($match) {
 
global $wgTransformChangesRow;
 
global $wgTransformChangesRow;
$wgTransformChangesRow = ++$wgTransformChangesRow%2;
+
$wgTransformChangesRow = $wgTransformChangesRow == 'even' ? 'odd' : 'even';
 
list(,$date,$text) = $match;
 
list(,$date,$text) = $match;
 
$cols = array('time','title','comment','user','talk','diff','info');
 
$cols = array('time','title','comment','user','talk','diff','info');
Line 43: Line 43:
 
if ($date) {
 
if ($date) {
 
$row = "<tr><td class=\"heading\" colspan=\"$ncols\">$date</td></tr>\n";  
 
$row = "<tr><td class=\"heading\" colspan=\"$ncols\">$date</td></tr>\n";  
$wgTransformChangesRow = 1;
+
$wgTransformChangesRow = 'even';
 
}
 
}
$row .= "<tr class=\"bg$wgTransformChangesRow\">";
+
$row .= "<tr class=\"$wgTransformChangesRow\">";
 
if (preg_match('|^(.+?); (\\d+:\\d+)(.+?)(<a.+?\\))\\s*(.*?)$|',$text,$m)) {
 
if (preg_match('|^(.+?); (\\d+:\\d+)(.+?)(<a.+?\\))\\s*(.*?)$|',$text,$m)) {
 
list(,$diff,$time,$bytes,$user,$comment) = $m;
 
list(,$diff,$time,$bytes,$user,$comment) = $m;

Revision as of 06:00, 16 May 2007

<?

  1. Extension:TransformChanges{{#Security:*|dev}}{{#Security:view|*}}Template:Php
Info.svg These are the MediaWiki extensions we're using and/or developing. Please refer to the information on the mediawiki.org wiki for installation and usage details. Extensions here which have no corresponding mediawiki article are either not ready for use or have been superseded. You can also browse our extension code in our local Subversion repository or our GitHub mirror.
  1. - See http://www.mediawiki.org/Extension:TransformChanges for installation and usage details
  2. - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)

if (!defined('MEDIAWIKI')) die('Not an entry point.');

define('TRANSFORMCHANGES_VERSION','1.0.2, 2007-05-16');

$wgExtensionCredits['other'][] = array( 'name' => 'TransformChanges', 'author' => 'User:Nad', 'description' => 'Makes recent-changes and watchlists render in nice columns for easier reading.', 'url' => 'http://www.organicdesign.co.nz/Extension:TransformChanges', 'version' => TRANSFORMCHANGES_VERSION );

$wgHooks['SpecialPageExecuteAfterPage'][] = 'wfTransformChanges'; function wfTransformChanges() { $title = $GLOBALS['wgTitle']->getDBkey(); if ($title != 'Recentchanges' && $title != 'Watchlist') return true; $text =& $GLOBALS['wgOut']->mBodytext;

$text = preg_replace('|(\\s*)?

(.+?)

\\s*(

    )
  • |s','$3
  • ',$text); $text = preg_replace_callback('|
      (.+?)
    |s','wfTransformChangesUL',$text);

    return true; }

    function wfTransformChangesUL($match) { global $wgTransformChangesRow; $wgTransformChangesRow = 0;

    $rows = preg_replace_callback('|<li\\s*(.*?)>(.+?)
  • |s','wfTransformChangesLI',$match[1]); return "$rows
    ";

    }

    function wfTransformChangesLI($match) { global $wgTransformChangesRow; $wgTransformChangesRow = $wgTransformChangesRow == 'even' ? 'odd' : 'even'; list(,$date,$text) = $match; $cols = array('time','title','comment','user','talk','diff','info'); $ncols = count($cols); $row = ;

    $error = 'Error: match failed!';

    if ($date) {

    $row = "$date\n";

    $wgTransformChangesRow = 'even'; }

    $row .= ""; if (preg_match('|^(.+?); (\\d+:\\d+)(.+?)(<a.+?\\))\\s*(.*?)$|',$text,$m)) { list(,$diff,$time,$bytes,$user,$comment) = $m; if (preg_match('|^(.+\\)).*?\\. \\.\\s*(.*?)\\s*(<a.+)$|',$diff,$m)) list(,$diff,$info,$title) = $m; else $info = $title = ; if (preg_match('|(\\(.+?\\))|',$bytes,$m)) $info .= "$m[1]"; if (preg_match('|(<a.+?</a>).+?(\\(.+?\\))|',$user,$m)) list(,$user,$talk) = $m; if (preg_match('|\\((.+)\\)|',$comment,$m)) $comment = $m[1]; foreach ($cols as $col) $row .= "{$$col}";

    } else $row = $error;

    $row .= "\n"; return $row; } ?>