Exemple #1
0
 public function handle_action_act_preprocess(Doku_Event &$event, $param)
 {
     global $ID;
     global $TEXT;
     global $ACT;
     global $SUM;
     global $RANGE;
     global $REV;
     $act = $event->data;
     if ($act != 'dokutranslate_review') {
         $act = act_clean($act);
         $act = act_permcheck($act);
     }
     # Ignore drafts if the page is being translated
     # FIXME: Find a way to save $_REQUEST['parid'] into the draft
     if (@file_exists(metaFN($ID, '.translate')) && in_array($act, array('draft', 'recover'))) {
         act_draftdel('draftdel');
         $ACT = $act = 'edit';
     }
     if ($act == 'save') {
         # Take over save action if translation is in progress
         # or we're starting it
         if (!@file_exists(metaFN($ID, '.translate')) && empty($_REQUEST['translate'])) {
             return;
         }
         if (!checkSecurityToken()) {
             return;
         }
         # We're starting a translation
         if (!@file_exists(metaFN($ID, '.translate')) && !empty($_REQUEST['translate'])) {
             # Check if the user has permission to start
             # translation in this namespace
             if (!isModerator($ID)) {
                 return;
             }
             # Take the event over
             $event->stopPropagation();
             $event->preventDefault();
             # Save the data but exit if it fails
             $ACT = act_save($act);
             if ($ACT != 'show') {
                 return;
             }
             # Page was deleted, exit
             if (!@file_exists(wikiFN($ID))) {
                 return;
             }
             # Prepare data path
             $datapath = dataPath($ID);
             io_mkdir_p($datapath, 0755, true);
             # Backup the original page
             io_rename(wikiFN($ID), $datapath . '/orig.txt');
             # Backup old revisions
             $revisions = allRevisions($ID);
             foreach ($revisions as $rev) {
                 $tmp = wikiFN($ID, $rev);
                 io_rename($tmp, $datapath . '/' . basename($tmp));
             }
             # Backup meta files
             $metas = metaFiles($ID);
             foreach ($metas as $f) {
                 io_rename($f, $datapath . '/' . basename($f));
             }
             # Generate empty page to hold translated text
             $data = getCleanInstructions($datapath . '/orig.txt');
             saveWikiText($ID, genTranslateFile($data), $SUM, $_REQUEST['minor']);
             $translateMeta = genMeta(count($data));
             # create meta file for current translation state
             io_saveFile(metaFN($ID, '.translate'), serialize($translateMeta));
             # create separate meta file for translation history
             io_saveFile(metaFN($ID, '.translateHistory'), serialize(array('current' => $translateMeta)));
         } else {
             # Translation in progress, take the event over
             $event->preventDefault();
             # Save the data but exit if it fails
             $ACT = act_save($act);
             # Save failed, exit
             if ($ACT != 'show') {
                 return;
             }
             # Save successful, update translation metadata
             $lastrev = getRevisions($ID, 0, 1, 1024);
             updateMeta($ID, getParID(), $lastrev[0]);
         }
     } else {
         if ($act == 'revert') {
             # Take over save action if translation is in progress
             if (!@file_exists(metaFN($ID, '.translate'))) {
                 return;
             }
             if (!checkSecurityToken()) {
                 return;
             }
             # Translation in progress, take the event over
             $event->preventDefault();
             # Save the data but exit if it fails
             $revert = $REV;
             $ACT = act_revert($act);
             # Revert failed, exit
             if ($ACT != 'show') {
                 return;
             }
             # Revert successful, update translation metadata
             $lastrev = getRevisions($ID, 0, 1, 1024);
             updateMeta($ID, getParID(), $lastrev[0], $revert);
         } else {
             if (in_array($act, array('edit', 'preview'))) {
                 if (!@file_exists(metaFN($ID, '.translate')) || isset($TEXT)) {
                     return;
                 }
                 $parid = getParID();
                 $instructions = p_cached_instructions(wikiFN($ID));
                 $separators = array();
                 # Build array of paragraph separators
                 foreach ($instructions as $ins) {
                     if ($ins[0] == 'plugin' && $ins[1][0] == 'dokutranslate' && in_array($ins[1][1][0], array(DOKU_LEXER_ENTER, DOKU_LEXER_SPECIAL, DOKU_LEXER_EXIT))) {
                         $separators[] = $ins[1][1];
                     }
                 }
                 # Validate paragraph ID
                 if ($parid >= count($separators) - 1) {
                     $parid = 0;
                 }
                 # Build range for paragraph
                 $RANGE = strval($separators[$parid][2] + 1) . '-' . strval($separators[$parid + 1][1] - 1);
             } else {
                 if ($act == 'dokutranslate_review') {
                     # This action is mine
                     $event->stopPropagation();
                     $event->preventDefault();
                     # Show the page when done
                     $ACT = 'show';
                     # Load data
                     $meta = unserialize(io_readFile(metaFN($ID, '.translateHistory'), false));
                     $parid = getParID();
                     $writeRev = empty($REV) ? 'current' : intval($REV);
                     $writeRev = empty($meta[$writeRev][$parid]['changed']) ? $writeRev : $meta[$writeRev][$parid]['changed'];
                     $user = $_SERVER['REMOTE_USER'];
                     # Check for permission to write reviews
                     if (!canReview($ID, $meta[$writeRev], $parid)) {
                         return;
                     }
                     # Add review to meta array
                     $data['message'] = $_REQUEST['review'];
                     $data['quality'] = intval($_REQUEST['quality']);
                     $data['incomplete'] = !empty($_REQUEST['incomplete']);
                     $meta[$writeRev][$parid]['reviews'][$user] = $data;
                     # Review applies to latest revision as well
                     if (empty($REV) || $meta['current'][$parid]['changed'] == $writeRev) {
                         $meta['current'][$parid]['reviews'][$user] = $data;
                         io_saveFile(metaFN($ID, '.translate'), serialize($meta['current']));
                     }
                     # Save metadata
                     io_saveFile(metaFN($ID, '.translateHistory'), serialize($meta));
                 }
             }
         }
     }
 }
/**
 * Handle 'save'
 *
 * Checks for spam and conflicts and saves the page.
 * Does a redirect to show the page afterwards or
 * returns a new action.
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function act_save($act)
{
    global $ID;
    global $DATE;
    global $PRE;
    global $TEXT;
    global $SUF;
    global $SUM;
    //spam check
    if (checkwordblock()) {
        return 'wordblock';
    }
    //conflict check //FIXME use INFO
    if ($DATE != 0 && @filemtime(wikiFN($ID)) > $DATE) {
        return 'conflict';
    }
    //save it
    saveWikiText($ID, con($PRE, $TEXT, $SUF, 1), $SUM, $_REQUEST['minor']);
    //use pretty mode for con
    //unlock it
    unlock($ID);
    //delete draft
    act_draftdel($act);
    //show it
    session_write_close();
    header("Location: " . wl($ID, '', true));
    exit;
}
Exemple #3
0
/**
 * Revert to a certain revision
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function act_revert($act)
{
    global $ID;
    global $REV;
    global $lang;
    // when no revision is given, delete current one
    // FIXME this feature is not exposed in the GUI currently
    $text = '';
    $sum = $lang['deleted'];
    if ($REV) {
        $text = rawWiki($ID, $REV);
        if (!$text) {
            return 'show';
        }
        //something went wrong
        $sum = $lang['restored'];
    }
    // spam check
    if (checkwordblock($Text)) {
        return 'wordblock';
    }
    saveWikiText($ID, $text, $sum, false);
    msg($sum, 1);
    //delete any draft
    act_draftdel($act);
    session_write_close();
    // when done, show current page
    $_SERVER['REQUEST_METHOD'] = 'post';
    //should force a redirect
    $REV = '';
    return 'show';
}
Exemple #4
0
/**
 * Revert to a certain revision
 *
 * @author Andreas Gohr <*****@*****.**>
 *
 * @param string $act action command
 * @return string action command
 */
function act_revert($act)
{
    global $ID;
    global $REV;
    global $lang;
    /* @var Input $INPUT */
    global $INPUT;
    // FIXME $INFO['writable'] currently refers to the attic version
    // global $INFO;
    // if (!$INFO['writable']) {
    //     return 'show';
    // }
    // when no revision is given, delete current one
    // FIXME this feature is not exposed in the GUI currently
    $text = '';
    $sum = $lang['deleted'];
    if ($REV) {
        $text = rawWiki($ID, $REV);
        if (!$text) {
            return 'show';
        }
        //something went wrong
        $sum = sprintf($lang['restored'], dformat($REV));
    }
    // spam check
    if (checkwordblock($text)) {
        msg($lang['wordblock'], -1);
        return 'edit';
    }
    saveWikiText($ID, $text, $sum, false);
    msg($sum, 1);
    //delete any draft
    act_draftdel($act);
    session_write_close();
    // when done, show current page
    $INPUT->server->set('REQUEST_METHOD', 'post');
    //should force a redirect
    $REV = '';
    return 'show';
}