WCF 2.1 — Edit History

  • Community Framework 2.1 introduces a new edit history. It allows you to easily save older versions of your content. You only have to tell the system when it should save a new version and how to revert to an older version. Everything else, such as generating the differences and bulk reverting are automatically provided for you. You only need an object type, two PHP classes and a small modification to your “update” function, as well as your templates.


    XML: objectType.xml
    <type>
    <name>com.woltlab.wbb.post</name>
    <definitionname>com.woltlab.wcf.edit.historySavingObject</definitionname>
    <classname>wbb\data\post\HistorySavingPostProvider</classname>
    </type>




    Now you have to call EditHistoryManager::getInstance()->add($objectType, $objectID, $currentMessageText, $currentUserID, $currentUsername, $reason); whenever the content is edited:


    PHP: PostAction.class.php
    if (isset($this->parameters['data']['message'])) {
    $historySavingPost = new HistorySavingPost($post->getDecoratedObject());
    $userID = $historySavingPost->getUserID();
    $username = $historySavingPost->getUsername();
    $time = $historySavingPost->getTime();
    $reason = $historySavingPost->getEditReason();
    EditHistoryManager::getInstance()->add('com.woltlab.wbb.post', $post->postID, $post->message, $time, $userID, $username, $reason, WCF::getUser()->userID);
    }


    And EditHistoryManager::getInstance()->delete($objectType, $objectIDs); whenever content is removed.


    The edit history will be ready now, but you really should provide a link for the user to view it! You can create the link like this:

    Code
    {link controller='EditHistory' objectType='com.woltlab.wbb.post' objectID=$post->postID}{/link}