📄 history1.php
字号:
<?php//$lang checkeddefined('WikyBlog') or die("Not an entry point...");////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// HISTORY INSTRUCTIONS//function run_Instructions_main($source,$instructions){ if( empty($instructions) ){ return $source; } // 1) Set sourceArray $type = null; if( is_object($source) ){ //$type = get_class( $source ); $resultArray = get_object_vars( $source ); }else{ $resultArray = $source; } // 2) Prep Instructions if( function_exists('gzinflate') ){ $inflated = @gzinflate($instructions); if( $inflated !== false){ $instructions = $inflated; } } $instructions = unserialize($instructions); // message(showArray($resultArray) ); // message(showArray($instructions) ); // 3) Run Instruction For each Key foreach($instructions as $key => $instruction){ $resultArray[$key] = run_Instructions($resultArray[$key],$instruction); } return $resultArray;}function run_Instructions($source,$instructions){ if( is_string($instructions) ){ return $instructions; }else{ $source = stringToArray($source); } // message(showArray($source) ); // message(showArray($instructions) ); //////////////////////////////////////////////////////////////////////////////// // // I) Prepare addRight and deleteLeft // // 1) Delete/Add if( isset($instructions['d']) ){ $deleteLeft = $instructions['d']; } if( isset($instructions['a']) ){ $addRight = $instructions['a']; } // 2) Replace => Delete/Add if( !empty($instructions['r']) ){ foreach($instructions['r'] as $replaceKey => $with){ $deleteLeft[$replaceKey] = ''; foreach($with as $withKey => $withValue){ $addRight[$replaceKey][$withKey] = $withValue; } } } // 3) Move => Delete/Add if( !empty($instructions['m']) ){ $move = $instructions['m']; foreach($move as $from => $to){ $deleteLeft[$from] = ''; list($leftIndex,$rightIndex) = explode('.',$to); $addRight[$leftIndex][$rightIndex] = $source[$from]; } } // echo '<table><tr>'; // echo '<td style="vertical-align:top">Move<br />'; // echo showArray($move); // echo '</td><td style="vertical-align:top">Delete<br />'; // echo showArray($deleteLeft); // echo '</td><td style="vertical-align:top">Add<br />'; // echo showArray($addRight); // echo '</td></table>'; //message(showArray($addRight) ); //////////////////////////////////////////////////////////////////////////////// // // II) Apply add and delete // i) reverse array // ii) line by line // iia) delete // iib) add // iii) reverse array // krsort($source); //message( showArray($source) ); foreach($source as $sourceKey => $sourceValue){ //$message = $sourceKey; if( !isset($deleteLeft[$sourceKey]) ){ //$finalText[$sourceKey] = $source[$sourceKey];// wrong, just treat it as a stack, // otherwise it could result in writing over adds, $finalText[] = $source[$sourceKey]; //$message .= ' Leave: '.htmlspecialchars($source[$sourceKey]); }else{ //$message .= ' Delete: '.htmlspecialchars($source[$sourceKey]); } //message($message); if( isset($addRight[$sourceKey]) ){ krsort($addRight[$sourceKey]); // sort because of additions to addRight from move // krsort() because we're going backwards $add = array(); foreach($addRight[$sourceKey] as $key => $addLine){ $finalText[] = $addLine; } } } $finalText = array_reverse($finalText); // For additional added lines $nextIndex = count($source); if( isset($addRight[$nextIndex]) ){ foreach($addRight[$nextIndex] as $key => $addLine){ $finalText[] = $addLine; } } return implode("\n",$finalText);}//// HISTORY INSTRUCTIONS//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// SINGLE REVISIONS//// $rowLimit could be used to limit the the number of rows to 1// - this could be useful with the xmlHTTP saving where history elements will constantly be overwritten// $user// - limit the revisions to the user// - this was a bit of a hack?... and I'm not using it any morefunction getRevision($revNum){ global $dbObject,$wbTables; if( wbStrtolower($revNum) != 'current'){ if( !is_numeric($revNum) ){ message('INVALID_REVISION'); return false; } $query = ' SELECT * FROM '.$wbTables['all_history'].' WHERE '; $query .= ' `file_id` = '.$dbObject->file_id; $query .= ' AND revision >= '.$revNum; if( wbStrtolower($dbObject->revision) != 'current'){ $query .= ' AND revision < '.$dbObject->revision; } $query .= ' ORDER BY revision DESC'; $result = wbDB::runQuery($query); $num = mysql_num_rows($result); if($num == 0){ message('NO_UNIQUE_REVISION'); return; } applyRevisionRows($result); } }// end function//nearly the same as above function other than this selects the lates revision using LIMIT 1function getLastRevision(){ global $dbObject,$wbTables; if(!$dbObject->exists){ return false; } $query = ' SELECT * FROM '.$wbTables['all_history'].' WHERE '; $query .= ' `file_id` = '.$dbObject->file_id; $query .= ' ORDER BY revision DESC'; $query .= ' LIMIT 1 '; $result = wbDB::runQuery($query); $num = mysql_num_rows($result); if( $num == 0 ){ // Didn't get any rows // ... so just make sure it gets added by setting the modified value correctly // $_SESSION['editPage'][$dbObject->uniqStorage] = $dbObject->modified; return false; } applyRevisionRows($result); return true;}function applyRevisionRows(&$result){ global $dbObject; while($row = mysql_fetch_object($result) ){ unset($temp2); $temp2 = run_Instructions_main($dbObject,$row->instructions); $dbObject->setVariables($temp2,$dbObject->userValues); //must set these values because they aren't part of ->userValues $dbObject->revision = $row->revision; $dbObject->modified = $row->modified; $dbObject->summary = $row->summary; $dbObject->username = $row->username; $dbObject->ip = $row->ip; // $dbObject->distanceToCurrent++; } } function showRevision($link=false){ global $page,$dbObject,$lang; $revNum = $_GET['revNum']; getRevision($revNum); if( !$dbObject){ return false; } $title = $lang['revision'].$dbObject->revision; $dbObject->links[$title] = '/Edit'.$dbObject->uniqLink.'?cmd=show&revNum='.$revNum; //!! this isn't quite right... how do we know that the message will be on the right tab.. $message = $lang['revision_as_of'].dbFromDate($dbObject->modified,3); $message .= ' - '; if( $link ){ $message .= $link; }else{ $message .= wbLinks::local('/Edit'.$dbObject->uniqLink.'?cmd=editRevision&revNum='.$revNum,$lang['edit_revision']); } //previous|next links $showLinks = array(); if( $dbObject->revision > 1){ $prevNum = ($dbObject->revision-1); $showLinks[] = wbLinks::local('/Edit'.$dbObject->uniqLink.'?cmd=show&revNum='.$prevNum,wbLang::text('show_prev_revision',$prevNum)); } if($dbObject->distanceToCurrent === 1){ $showLinks[] = wbLinks::local($dbObject->uniqLink,'current_revision'); }else{ $nextNum = ($dbObject->revision+1); $showLinks[] = wbLinks::local('/Edit'.$dbObject->uniqLink.'?cmd=show&revNum='.$nextNum,wbLang::text('show_next_revision',$nextNum)); } if(count($showLinks) > 0){ $message .= '<br/><span class="sm">'.implode(' | ',$showLinks).'</span>'; } message($message); //!!hack // an older version might not be safe and history tables don't store that data // so we just assume older versions aren't 'safe' if( strpos($dbObject->flags,'safe') !== false ){ $dbObject->flags = str_replace('safe','',$dbObject->flags); } $field = $dbObject->outputObj($title); $dbObject->addFooter($field); }//end function// Edit an older version, saving will make it the current version//// for this to pass the check in toolSavePage.php it needs to have the current `modified` value// so I store `modified` in $mod then reassign it to $dbObject after getRevision();//function editRevision(){ global $page,$dbObject,$lang; message('EDITING_REVISION'); $mod = $dbObject->modified; getRevision($_GET['revNum']); if( !$dbObject){ return false; } $dbObject->modified = $mod; $_POST['summary'] = $lang['reverted_to_rev'].$_GET['revNum']; //$dbObject->links['Edit Revision'] = $dbObject->uniqLink.'?cmd=editRevision&revNum='.$_GET['revNum']; includeFile('tool/EditPage.php');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -