## ## Contact: ## ## diafygi (curvy thing) gmail (period) com ## ## ## Description: ## ViewDiff is an action that creates a rendering of a page that ## based on a certain time in its history. It will also display ## the changes made to a page based on a second time. ## ## Use: ## To use ViewDiff, simply call the action 'viewdiff' in your ## page url. This will display a temporary rendering of the ## current page at the current time. ## (http://example.com/wiki/Main/Home?action=viewdiff) ## You can also specify a time by including its unix timestamp ## in the url. ## (http://example.com/wiki/Main/Home?action=viewdiff&time=1122334455) ## You can compare two edits by including two times in the url ## separated by a colon. ## (http://example.com/wiki/Main/Home?action=viewdiff&time=1122334455:2233445566) ## This action also accepts PmWiki formated Edit IDs ## (http://example.com/wiki/Main/Home?action=viewdiff&time=diff:1122334455:2233445566:minor) ## You can also separate the two times into two url variables ## (http://example.com/wiki/Main/Home?action=viewdiff&time1=1122334455&time2=2233445566) ## or, with PmWiki Edit IDs ## (http://example.com/wiki/Main/Home?action=viewdiff&time1=diff:1122334455:2233445566:minor&time2=diff:3344556677:4455667788:minor) ## (This will take the times 1122334455 and 3344556677) ## # Create action and Version id (for RecipeCheck) SDV($HandleActions['viewdiff'], 'ViewDiff'); $RecipeInfo['ViewDiff']['Version'] = '2011-05-13'; #Add custom formats for History page (?action=diff) SDV($ViewDiffCompare, 1); if($ViewDiffCompare) { SDV($DiffStartFmt, "
 
 
\$DiffTime \$[by] \$DiffAuthor - \$DiffChangeSum
"); SDV($PageDiffFmt, "

$[{\$FullName} History]

$DiffMinorFmt - $DiffSourceFmt

"); SDV($HTMLStylesFmt['viewdiff'], " .diffradiotitle { width:570px; height:1.1em; } .diffradiotext { float:right; } .diffradio { float:right; text-align:center; width:3em; }"); SDV($HTMLHeaderFmt['viewdiff'], ($action=="diff") ? " " : ''); } # Include pagerev.php to access RenderDiff function and # default formatting variables SDV($HandleActions['diff'], 'HandleDiffView'); include_once("$FarmD/scripts/pagerev.php"); # Added DiffFmtChanges() function to so formatting # changes can be made before rendering the History # page (?action=diff) function HandleDiffView($pagename, $auth) { DiffFmtChanges(); HandleDiff($pagename, $auth); } # Changes the formatting of the History page (?action=diff) # to include a comparison form function DiffFmtChanges() { global $action, $ViewDiffCompare, $HandleDiffFmt, $PageStartFmt, $PageDiffFmt, $PageEndFmt, $PageDiffFmt, $DiffMinorFmt, $DiffSourceFmt, $DiffStartFmt, $HTMLStylesFmt, $HTMLHeaderFmt; #Change formatting if comparison form should display if($ViewDiffCompare) { #Changed formatting variables in History page to include comparison form $HandleDiffFmt = array(&$PageStartFmt, &$PageDiffFmt,"
", 'function:PrintDiff', '
', &$PageEndFmt); } } # Create formatting defaults for ViewDiff action SDV($ViewDiffTimeFmt, 'D, d M Y H:i:s \G\M\T'); SDV($ViewDiffStartFmt, "

View Differences

\n

\$ViewDiffTime1 (newer)

\n

\$ViewDiffTime2 (older)

\n"); SDV($ViewDiffChangesFmt, "\$ViewDiffChanges\n"); SDV($ViewDiffTextFmt, "
\n
\$ViewDiffText
\n"); # This function runs when the viewdiff action is called. # It takes one or two given times and displays the first # while also showing the changes between the first and # second. function ViewDiff($pagename, $auth = 'read', $time = NULL) { global $action, $PageStartFmt, $PageDiffFmt, $ViewDiffTimeFmt, $ViewDiffStartFmt, $PageEndFmt, $FmtV, $DiffFunction, $ViewDiffTextFmt, $ViewDiffChangesFmt, $ViewDiffFmt, $DiffShow; #Get time from url if($_REQUEST['time']) $time = $_REQUEST['time']; if($_REQUEST['time1']) { $time = $_REQUEST['time1']; if($_REQUEST['time2']) $time .= ':'.$_REQUEST['time2']; } if(is_null($time)) $time = time(); #Check to see if second time given $time = explode(":", $time); switch(count($time)) { case 1: $time[1] = $time[0]; break; case 2: break; case 4: array_shift($time); array_pop($time); break; case 8: $time = array($time[1], $time[5]); break; default: return; } #Reorder so most recent time is first if($time[0]<$time[1]) { $t = $time[0]; $time[0] = $time[1]; $time[1] = $t; } #Generate time for version $FmtV['$ViewDiffTime1'] = gmdate($ViewDiffTimeFmt, $time[0]); $FmtV['$ViewDiffTime2'] = gmdate($ViewDiffTimeFmt, $time[1]); #Get page (with edit history) $page = RetrieveAuthPage($pagename, $auth, true, 0); if (!$page) Abort("?cannot generate feed"); #Restore page to first timestamp $t = 'diff:'.$time[0].':'.$time[0].':'; $markup = RestorePage($pagename, $page, $new, $t); #Create diff if needed if($time[0] != $time[1]) { $t = 'diff:'.$time[1].':'.$time[1].':'; $old = RestorePage($pagename, $page, $new, $t); $diff = $DiffFunction($markup, $old); } #Add text to format variables $FmtV['$ViewDiffText'] = MarkupToHtml($pagename, $markup); $FmtV['$ViewDiffChanges'] = DiffHTML($pagename, $diff); #Print page $VersionTextFmt = FmtPageName($ViewDiffTextFmt, $pagename); SDV($ViewDiffFmt, array(&$PageStartFmt, &$ViewDiffStartFmt, &$ViewDiffChangesFmt, &$ViewDiffTextFmt, &$PageEndFmt)); PrintFmt($pagename, $ViewDiffFmt); }