Ejemplo n.º 1
0
/**
* Write a new/edited wiki page to database
*
* @param    string  keyword WikiPage name
* @param    string  version WikiPage version
* @param    string  body    WikiPage text
* @param    string  user_id Internal user id of editor
* @param    string  range_id    Internal id of seminar/einrichtung
*
**/
function submitWikiPage($keyword, $version, $body, $user_id, $range_id) {

    releasePageLocks($keyword, $user_id); // kill lock that was set when starting to edit
    // write changes to db, show new page
    $latestVersion=getWikiPage($keyword,false);
    if ($latestVersion) {
        $date=time();
        $lastchange = $date - $latestVersion['chdate'];
    }

    StudipTransformFormat::addStudipMarkup('wiki-comments', '(\[comment\])', null, function(){return sprintf('[comment=%s]', get_fullname());});

    //TODO: Die $message Texte klingen fürchterlich. Halbsätze, Denglisch usw...
    if ($latestVersion && ($latestVersion['body'] == $body)) {
        $message = MessageBox::info(_('Keine Änderung vorgenommen.'));
        PageLayout::postMessage($message);
    } else if ($latestVersion && ($version !== null) && ($lastchange < 30*60) && ($user_id == $latestVersion['user_id'])) {
        // if same author changes again within 30 minutes, no new verison is created
        NotificationCenter::postNotification('WikiPageWillUpdate', array($range_id, $keyword));

        // apply replace-before-save transformations
        $body = transformBeforeSave($body);

        $query = "UPDATE wiki
                  SET body = ?, chdate = UNIX_TIMESTAMP()
                  WHERE keyword = ? AND range_id = ? AND version = ?";
        $statement = DBManager::get()->prepare($query);
        $statement->execute(array($body, $keyword, $range_id, $version));

        NotificationCenter::postNotification('WikiPageDidUpdate', array($range_id, $keyword));
    } else {
        if ($version === null) {
            $version=0;
        } else {
            $version=$latestVersion['version']+1;
        }

        NotificationCenter::postNotification('WikiPageWillCreate', array($range_id, $keyword));

        // apply replace-before-save transformations
        $body = transformBeforeSave($body);

        $query = "INSERT INTO wiki (range_id, user_id, keyword, body, chdate, version)
                  VALUES (?, ?, ?, ?, UNIX_TIMESTAMP(), ?)";
        $statement = DBManager::get()->prepare($query);
        $statement->execute(array($range_id, $user_id, $keyword, $body, $version));

        NotificationCenter::postNotification('WikiPageDidCreate', array($range_id, $keyword));
    }
    StudipTransformFormat::removeStudipMarkup('wiki-comments');
    refreshBacklinks($keyword, $body);
}
Ejemplo n.º 2
0
 // kill old locks
 $special = "";
 if (Request::submitted('submit')) {
     //
     // Page was edited and submitted
     //
     submitWikiPage($keyword, $version, Studip\Markup::purifyHtml(Request::get('body')), $user->id, $SessSemName[1]);
     $version = "";
     // $version="" means: get latest
 } else {
     if ($cmd == "abortedit") {
         // Editieren abgebrochen
         //
         // Editing page was aborted
         //
         releasePageLocks($keyword, $user->id);
         // kill lock (set when starting to edit)
         if (Request::quoted('lastpage')) {
             // if editing new page was aborted, display last page again
             $keyword = Request::quoted('lastpage');
         }
     } else {
         if ($cmd == "delete") {
             //
             // Delete request sent -> confirmdialog and current page
             //
             $special = "delete";
         } else {
             if ($cmd == "really_delete") {
                 //
                 // Delete was confirmed -> really delete