Difference between revisions of "Extension:TransformChanges.php"

From Organic Design wiki
m (oops)
 
(23 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<?
+
{{legacy}}
# Extension:TransformChanges{{php}}{{Category:Extensions|TransformChanges}}
+
{{svn|extensions|TransformChanges/TransformChanges.php}}
# - See http://www.mediawiki.org/Extension:TransformChanges for installation and usage details
+
[[Category:Extensions]]
# - 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'      => '[http://www.organicdesign.co.nz/nad 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
 
);
 
 
# 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('|(</ul>\\s*)?<h4>(.+?)</h4>\\s*(<ul class="special">)<li>|s','$3<li $2>',$text);
 
$text = preg_replace_callback('|<ul class="special">(.+?)</ul>|s','wfTransformChangesUL',$text);
 
return true;
 
}
 
 
 
function wfTransformChangesUL($match) {
 
global $wgTransformChangesRow;
 
$wgTransformChangesRow = 0;
 
$rows = preg_replace_callback('|<li\\s*(.*?)>(.+?)</li>|s','wfTransformChangesLI',$match[1]);
 
return "<table class=\"changes\">$rows</table>";
 
}
 
 
 
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 = '<td colspan="$ncols"><font color="red"><b>Error: match failed!</b></font></td>';
 
if ($date) {
 
$row = "<tr><td class=\"heading\" colspan=\"$ncols\">$date</td></tr>\n";
 
$wgTransformChangesRow = 'even';
 
}
 
$row .= "<tr class=\"$wgTransformChangesRow\">";
 
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 .= "<small>$m[1]</small>";
 
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 .= "<td class=\"$col\">{$$col}</td>";
 
} else $row = $error;
 
$row .= "</tr>\n";
 
return $row;
 
}
 
?>
 

Latest revision as of 01:53, 4 July 2013

Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, now this page is for historic record only.


Info.svg This code is in our Git repository here.

Note: If there is no information in this page about this code and it's a MediaWiki extension, there may be something at mediawiki.org.