/** * RevertPageToPreviousByTag * * Reverts a page to the version immediately preceding the "latest" * version. New page is created with previous version's metadata. * * @param object $wakka Wakka class instantiation * @param string $tag Page tag * @param string $comment Page comment (defaults to T_("Reverting last edit by %s [%d] to previous version [%d]")) * @return string T_("Reverted to previous version") or T_("Reversion to previous version FAILED!") * */ function RevertPageToPreviousByTag($wakka, $tag, $comment = '') { $message = T_("Reversion to previous version FAILED!"); $tag = mysql_real_escape_string($tag); $comment = mysql_real_escape_string($comment); if (TRUE === $wakka->IsAdmin()) { // Select current version of this page and version immediately preceding $res = LoadLastTwoPagesByTag($wakka, $tag); if ($res) { // $res[0] is current page, $res[1] is page we're reverting to // Set default comment if (TRUE === empty($comment)) { $comment = sprintf(T_("Reverting last edit by %s [%d] to previous version [%d]"), $res[0]['user'], $res[0]['id'], $res[1]['id']); } // Save reverted page $wakka->SavePage($tag, $res[1]['body'], $comment, $res[1]['owner']); $message = T_("Reverted to previous version"); } else { $message = T_("Reversion to previous version FAILED!"); } } return $message; }
<?php /** * Revert link menulet (admin-only) * * Displays a link allowing admins to revert the current page to the previous * version. * * Syntax: {{revertlink}} * * @package Actions * @subpackage Menulets * @name Revert link * * @author {@link http://wikkawiki.org/DarTar Dario Taraborelli} * * @todo Use a new HasRevisions() method instead of loading admin class */ if ($this->IsAdmin()) { include_once $this->BuildFullpathFromMultipath('..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR . 'admin.lib.php', $this->GetConfigValue('action_path')); $res = LoadLastTwoPagesByTag($this, $this->GetPageTag()); if (null !== $res) { echo '<a href="' . $this->Href('revert') . '" title="Click to revert this page to the previous revision">' . T_("[Revert]") . '</a>'; } else { echo '<span class="disabled" title="' . T_("This is the oldest known version for this page") . '">' . T_("[Revert]") . '</span>'; } }
#not implemented $data_table = '<table id="adminpages" summary="' . T_("List of pages on this server") . '" border="1px" class="data">' . "\n" . '<thead>' . "\n" . ' <tr>' . "\n" . ' <th> </th>' . "\n" . ' <th>' . $tagheader . '</th>' . "\n" . ' <th>' . $ownerheader . '</th>' . "\n" . ' <th>' . $userheader . '</th>' . "\n" . ' <th>' . $lasteditheader . '</th>' . "\n" . ' <th' . ($c_color == 1 ? ' class="c1"' : '') . ' title="' . T_("Hits") . '"><img src="images/icons/star.png" alt="' . T_("Hits") . '" /></th>' . "\n" . ' <th' . ($c_color == 1 ? ' class="c2"' : '') . ' title="' . T_("Revisions") . '"><img src="images/icons/edit.png" alt="' . T_("Revisions") . '" /></th>' . "\n" . ' <th' . ($c_color == 1 ? ' class="c3"' : '') . ' title="' . T_("Comments") . '"><img src="images/icons/comment.png" alt="' . T_("Comments") . '" /></th>' . "\n" . ' <th' . ($c_color == 1 ? ' class="c4"' : '') . ' title="' . T_("Backlinks") . '"><img src="images/icons/link.png" alt="' . T_("Backlinks") . '" /></th>' . "\n" . ' <th' . ($c_color == 1 ? ' class="c5"' : '') . ' title="' . T_("Referrers") . '"><img src="images/icons/world.png" alt="' . T_("Referrers") . '" /></th>' . "\n" . ' <th>' . T_("Actions") . '</th>' . "\n" . ' </tr>' . "\n" . '</thead>' . "\n"; // feed table with data foreach ($pagedata as $page) { // truncate long page names $pagename = strlen($page['tag']) > ADMINPAGES_DEFAULT_TAG_LENGTH ? substr($page['tag'], 0, ADMINPAGES_DEFAULT_TAG_LENGTH) . ADMINPAGES_DEFAULT_TERMINATOR : $page['tag']; // build handler links $lastedit = '<a class="datetime" href="' . $this->Href('revisions', $page['tag'], '') . '">' . $page['time'] . '</a>'; if ($pagename != $page['tag']) { $showpage = '<a href="' . $this->Href('', $page['tag'], '') . '" title="' . $page['tag'] . '">' . $pagename . '</a>'; } else { $showpage = '<a href="' . $this->Href('', $page['tag'], '') . '">' . $pagename . '</a>'; } // Disable revert link if only one page revision exists $revertpage = ''; $res = LoadLastTwoPagesByTag($this, $page['tag']); if (null === $res) { $revertpage = "<span class='disabled'>" . T_("revert") . "</span>"; } else { $revertpage = '<a href="' . $this->Href('revert', $page['tag'], '') . '" title="' . sprintf(T_("Revert %s to previous version"), $page['tag']) . '">' . T_("revert") . '</a>'; } $editpage = '<a href="' . $this->Href('edit', $page['tag'], '') . '" title="' . sprintf(T_("Edit %s"), $page['tag']) . '">' . T_("edit") . '</a>'; $deletepage = '<a href="' . $this->Href('delete', $page['tag'], '') . '" title="' . sprintf(T_("Delete %s"), $page['tag']) . '">' . T_("delete") . '</a>'; $clonepage = '<a href="' . $this->Href('clone', $page['tag'], '') . '" title="' . sprintf(T_("Clone %s"), $page['tag']) . '">' . T_("clone") . '</a>'; $aclpage = '<a href="' . $this->Href('acls', $page['tag'], '') . '" title="' . sprintf(T_("Change Access Control List for %s"), $page['tag']) . '">' . T_("acl") . '</a>'; // get page owner if ($page['owner']) { // is the owner a registered user? if ($this->LoadUser($page['owner'])) { // does user's homepage exist? if ($this->ExistsPage($page['owner'])) {