Transform-changes.php
<?
- Merge local changes with changes from other specified MediaWikis
# Extract changes from a page into an array ready for rendering in a table function extractChanges(&$changes, &$page, $wd = array()) { global $xwIsAdmin, $xwUserGroups; list($wiki, $url, $tz) = $wd; #if ($wiki) xwMessage(strlen($page)." bytes of changes received from $wiki wiki.", 'green'); # Change exraction rules (for supporting TWiki and MoinMoin later) $cr = "/^\\((.*?(diff|log|undo)(<\\/a>)?)\\)(.+?\\((.+?<\\/a>)\\))?( \\. \\.\\s+(.*?)\\s+(()?<a.+?<\\/a>(<\\/strong>)?))?.*?; ([0-9]+:[0-9]+) \\. \\. (<a.+?<\\/a>).+?(<a.+?<\\/a>)(.+?\\((.+)\\))?/";
$pr = "/
([0-9]+ [a-z]+ [0-9]+)<\\/h4>\\s*(.+?)<\\/ul>/is";
# Used to make urls from other wiki's absolute
if ($url) { $url = parse_url($url); $url = $url['scheme'].'://'.$url['host']; }
$tr = 999; # patch to stop same time keys overwriting
# First split the page by day sections
preg_match_all($pr, $page, $m1, PREG_SET_ORDER);
# Loop through changes in each day extracting relevent info into $changes array
foreach ($m1 as $day) {
preg_match_all("/- (.+?)<\\/li>/", $day[2], $m2);
foreach ($m2[1] as $change) {
$change = str_replace('href="', "href=\"$url", $change);
if (preg_match($cr, $change, $m3)) {
list(,$diff,,,,$hist,,$flags,$title,,,$time,$user,$talk,,$comment) = $m3;
ereg('>.+</a>', $user, $uname);
$user = ereg_replace($uname[0], str_replace(' ',' ',$uname[0]), $user);
# Get read-perms for article
if ( (!$readable = $xwIsAdmin) && ereg('>(.+)</a>', $title, $anchor) ) {
$readable = xwGetListByTagname( xwArticleProperties($anchor[1]), 'read' ) + array('anyone');
$readable = count( array_intersect( $readable, $xwUserGroups ) );
}
# Store the change if readable by current user
if ( $readable ) $changes[(strtotime("$day[1] $time")+$tz*3600).'.00'.$tr--] = array($wd,$diff,$hist,$flags,$title,$user,$talk,$comment);
} else xwMessage( "Couldn't match change: $change", 'red' );
}
}
return $changes;
}
# Render changes into said table
function renderChanges( &$changes ) {
$head = ;
foreach ( array( 'Date', 'Wiki', 'Article', 'Edit summary', 'Account' ) as $i ) {
$head .= "<th$colspan align=center>
- <a href=\"/wiki/index.php/Talk:transform-changes.php\">$i</a>
\n";
}
$html = "
\n";
$date = ;
$td = '' : '';
$html .= str_replace(">Date", ">$d", $head);
$date = $d; $bg = 1;
};
$bgtag = ++$bg % 2 ? 'bg1' : 'bg2';
if ($wt = $c[0][0]) $wiki = "<a href=\"".$c[0][1]."\" style=\"color:#009900;\">$wt</a>"; else $wiki = ;
$html .= "$td$s$time$td$wiki$s";
if (!$c[2]) {
list($diff,$hist) = explode(' ',$c[1]);
preg_match("/(<a.+?<\\/a>)/",$c[7],$m);
$c[4] = $m[1];
} else list(,$diff,$hist) = $c;
if ($diff == 'diff') $diff = ;
if (ereg('^href',$hist)) {
$diff = "<a $hist>log</a>";
$hist = ;
}
if (ereg('undo',$c[1])) {
$c4 = $c[4];
$c[4] = str_replace(' moved to',,$c[3]);
$c[7] = "moved to $c4";
$c[3] = ;
}
$event = $c[4];
if ($c[3]) $c[7] = "($c[3]) $c[7]";
if (ereg('(.{15}).',$c[5],$m)) $c[5] = "$m[1]…";
$html .= "$td$s$event$s';
$s = ' ';
ksort($changes);
foreach (array_reverse( $changes, SORT_STRING) as $t => $c) {
$time = strftime('%H:%M', $t);
if ($date != ($d = strftime('%d %b',$t))) {
$html .= $date ? ' $s$c[7]$s\n";
$html .= "$td$s$c[5]$td$s$diff$s$td$s$hist$s";
}
return "$html\n
";
}
- Get items in global changes-cache
$changes = array();
$tr = 999;
foreach (array($GLOBALS['IP'].'/Global.changes', $GLOBALS['IP'].'/'.$GLOBALS['xwUserName'].'.changes') as $cache)
if (file_exists($cache)) foreach (file($cache) as $change) {
$change = split("\\|",$change);
$change[2] = split(',',$change[2]);
$change[2][0] = str_replace('Energy Alternatives','EA',$change[2][0]);
$change[2][0] = str_replace('Azzuro Workgroup','AWG',$change[2][0]);
$change[2][0] = str_replace('JewelWiki','JW',$change[2][0]);
$change[2][0] = str_replace('GeeXboX wiki','GeeXboX',$change[2][0]);
$change[2][0] = str_replace('Organic Design','OD',$change[2][0]);
$changes[(strtotime(array_shift($change))+3600*intval(array_shift($change))).'.00'.$tr--] = $change;
}
- Extract local changes and replace with merged table
$article = preg_replace( "/[0-9]+ [a-z]+ [0-9]+<\\/h4>\\s*.+(?=
|
}
$html = "\n"; $date = ; $td = '' : '';
$html .= str_replace(">Date", ">$d", $head); $date = $d; $bg = 1; }; $bgtag = ++$bg % 2 ? 'bg1' : 'bg2'; if ($wt = $c[0][0]) $wiki = "<a href=\"".$c[0][1]."\" style=\"color:#009900;\">$wt</a>"; else $wiki = ;
$html .= "$td$s$time$td$wiki$s"; if (!$c[2]) { list($diff,$hist) = explode(' ',$c[1]); preg_match("/(<a.+?<\\/a>)/",$c[7],$m); $c[4] = $m[1]; } else list(,$diff,$hist) = $c; if ($diff == 'diff') $diff = ; if (ereg('^href',$hist)) { $diff = "<a $hist>log</a>"; $hist = ; } if (ereg('undo',$c[1])) { $c4 = $c[4]; $c[4] = str_replace(' moved to',,$c[3]); $c[7] = "moved to $c4"; $c[3] = ; } $event = $c[4]; if ($c[3]) $c[7] = "($c[3]) $c[7]"; if (ereg('(.{15}).',$c[5],$m)) $c[5] = "$m[1]…"; $html .= "$td$s$event$s';
$s = ' '; ksort($changes); foreach (array_reverse( $changes, SORT_STRING) as $t => $c) { $time = strftime('%H:%M', $t); if ($date != ($d = strftime('%d %b',$t))) { $html .= $date ? ' |
$s$c[7]$s\n";
$html .= "$td$s$c[5]$td$s$diff$s$td$s$hist$s"; } return "$html\n |
}
- Get items in global changes-cache
$changes = array(); $tr = 999; foreach (array($GLOBALS['IP'].'/Global.changes', $GLOBALS['IP'].'/'.$GLOBALS['xwUserName'].'.changes') as $cache) if (file_exists($cache)) foreach (file($cache) as $change) { $change = split("\\|",$change); $change[2] = split(',',$change[2]); $change[2][0] = str_replace('Energy Alternatives','EA',$change[2][0]); $change[2][0] = str_replace('Azzuro Workgroup','AWG',$change[2][0]); $change[2][0] = str_replace('JewelWiki','JW',$change[2][0]); $change[2][0] = str_replace('GeeXboX wiki','GeeXboX',$change[2][0]); $change[2][0] = str_replace('Organic Design','OD',$change[2][0]); $changes[(strtotime(array_shift($change))+3600*intval(array_shift($change))).'.00'.$tr--] = $change; }
- Extract local changes and replace with merged table