Difference between revisions of "Extension:TransformChanges.php"

From Organic Design wiki
m
(don't show items if no permission to view)
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.3, 2007-05-17');
+
define('TRANSFORMCHANGES_VERSION','1.0.4, 2007-05-20');
 
   
 
   
 
$wgExtensionCredits['other'][] = array(
 
$wgExtensionCredits['other'][] = array(
Line 35: Line 35:
  
 
function wfTransformChangesLI($match) {
 
function wfTransformChangesLI($match) {
global $wgTransformChangesRow;
+
global $wgTransformChangesRow,$wgSimpleSecurity;
 
$wgTransformChangesRow = $wgTransformChangesRow == 'even' ? 'odd' : 'even';
 
$wgTransformChangesRow = $wgTransformChangesRow == 'even' ? 'odd' : 'even';
 
list(,$date,$text) = $match;
 
list(,$date,$text) = $match;
Line 53: Line 53:
 
if (preg_match('|(<a.+?</a>).+?(\\(.+?\\))|',$user,$m)) list(,$user,$talk) = $m;
 
if (preg_match('|(<a.+?</a>).+?(\\(.+?\\))|',$user,$m)) list(,$user,$talk) = $m;
 
if (preg_match('|\\((.+)\\)|',$comment,$m)) $comment = $m[1];
 
if (preg_match('|\\((.+)\\)|',$comment,$m)) $comment = $m[1];
foreach ($cols as $col) $row .= "<td class=\"$col\">{$$col}</td>";
+
$allowed = true;
 +
if (preg_match('|title="(.+?)"|',$title,$m) && is_object($wgSimpleSecurity)) {
 +
$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;
 
} else $row = $error;
 
$row .= "</tr>\n";
 
$row .= "</tr>\n";

Revision as of 06:27, 20 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.4, 2007-05-20');

$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() { 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)) list(,$user,$talk) = $m; if (preg_match('|\\((.+)\\)|',$comment,$m)) $comment = $m[1]; $allowed = true; if (preg_match('|title="(.+?)"|',$title,$m) && is_object($wgSimpleSecurity)) { $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; } ?>