Extension:TransformChanges.php

From Organic Design wiki

<?

  1. Extension:TransformChangesTemplate: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.7, 2007-09-08');

$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 );

  1. Disable enhanced recent changes

$wgExtensionFunctions[] = 'wfSetupTransformChanges'; function wfSetupTransformChanges() { global $wgUser; $wgUser->setOption('usenewrc',false); }

$wgHooks['SpecialPageExecuteAfterPage'][] = 'wfTransformChanges'; function wfTransformChanges() { global $wgOut; $title = $wgOut->getPageTitle(); if ($title != wfMsgForContent('recentchanges') && $title != wfMsgForContent('watchlist')) return true; $text =& $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,$wgSimpleSecurity; $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)) { # Remove talk for email or IP users and make user lowercase list(,$user,$talk) = $m; if (ereg('@',$user) || !eregi('[a-z]',$user)) { $talk = ; $user = strtolower($user); } } if (preg_match('|\\((.+)\\)|',$comment,$m)) $comment = $m[1]; $allowed = true; if (preg_match('|title="(.+?)"|',$title,$m) && is_object($wgSimpleSecurity)) { # Only show row if ok by SimpleSecurity extension $t = Title::newFromText($m[1]); $allowed = $wgSimpleSecurity->validateTitle('view',$t); } if ($allowed) foreach ($cols as $col) $row .= "{$$col}";

    } else $row = $error;

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