コード例 #1
0
ファイル: action.php プロジェクト: k4m1/master-thesis
    function _handle_tpl_act(&$event, $param)
    {
        global $TEXT;

	    if($event->data != 'weaki') return;//check if is "weaki" after do= in URL
	    $event->preventDefault();//prevent default behaviour

        $filenames = $this->_get_filenames();
        $TEXT = $this->_weaki_headers($filenames);

        if($_GET["action"] == 'save'){
            act_save('save');
        }else{
            print $this -> _html_weaki_box();
        }

        $instructions = p_get_instructions($TEXT);
        $html .= p_render('xhtml',$instructions,$info); // render the instructions on the fly
        print $html;
    }
コード例 #2
0
ファイル: action.php プロジェクト: houshuang/folders2web
 public function handle_action_act_preprocess(Doku_Event &$event, $param)
 {
     global $ID, $INFO, $REV, $RANGE, $TEXT, $PRE, $SUF;
     // check if the action was given as array key
     if (is_array($event->data)) {
         list($act) = array_keys($event->data);
     } else {
         $act = $event->data;
     }
     if ($act == 'save' && $_REQUEST['saveandedit'] && actionOK($act)) {
         if (act_permcheck($act) == 'save' && checkSecurityToken()) {
             $event->data = act_save($act);
             if ($event->data == 'show') {
                 $event->data = 'edit';
                 $REV = '';
                 // now we are working on the current revision
                 // Handle section edits
                 if ($PRE || $SUF) {
                     // $from and $to are 1-based indexes of the actually edited content
                     $from = strlen($PRE) + 1;
                     $to = $from + strlen($TEXT);
                     $RANGE = $from . '-' . $to;
                 }
                 // Ensure the current text is loaded again from the file
                 unset($GLOBALS['TEXT'], $GLOBALS['PRE'], $GLOBALS['SUF']);
                 // Reset the date of the last modification to avoid conflict messages
                 unset($GLOBALS['DATE']);
                 // Reset the change check
                 unset($_REQUEST['changecheck']);
                 // Force rendering of the metadata in order to ensure metadata is correct
                 p_set_metadata($ID, array(), true);
                 $INFO = pageinfo();
                 // reset pageinfo to new data (e.g. if the page exists)
             } elseif ($event->data == 'conflict') {
                 // DokuWiki won't accept 'conflict' as action here.
                 // Just execute save again, the conflict will be detected again
                 $event->data = 'save';
             }
         }
     }
 }
コード例 #3
0
ファイル: action.php プロジェクト: nextghost/Dokutranslate
 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));
                 }
             }
         }
     }
 }
コード例 #4
0
ファイル: actions.php プロジェクト: JeromeS/dokuwiki
/**
 * Call the needed action handlers
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 * @triggers ACTION_ACT_PREPROCESS
 * @triggers ACTION_HEADERS_SEND
 */
function act_dispatch()
{
    global $INFO;
    global $ACT;
    global $ID;
    global $QUERY;
    global $lang;
    global $conf;
    global $license;
    $preact = $ACT;
    // give plugins an opportunity to process the action
    $evt = new Doku_Event('ACTION_ACT_PREPROCESS', $ACT);
    if ($evt->advise_before()) {
        //sanitize $ACT
        $ACT = act_clean($ACT);
        //check if searchword was given - else just show
        $s = cleanID($QUERY);
        if ($ACT == 'search' && empty($s)) {
            $ACT = 'show';
        }
        //login stuff
        if (in_array($ACT, array('login', 'logout'))) {
            $ACT = act_auth($ACT);
        }
        //check if user is asking to (un)subscribe a page
        if ($ACT == 'subscribe') {
            try {
                $ACT = act_subscription($ACT);
            } catch (Exception $e) {
                msg($e->getMessage(), -1);
            }
        }
        //check permissions
        $ACT = act_permcheck($ACT);
        //register
        $nil = array();
        if ($ACT == 'register' && $_POST['save'] && register()) {
            $ACT = 'login';
        }
        if ($ACT == 'resendpwd' && act_resendpwd()) {
            $ACT = 'login';
        }
        //update user profile
        if ($ACT == 'profile') {
            if (!$_SERVER['REMOTE_USER']) {
                $ACT = 'login';
            } else {
                if (updateprofile()) {
                    msg($lang['profchanged'], 1);
                    $ACT = 'show';
                }
            }
        }
        //revert
        if ($ACT == 'revert') {
            if (checkSecurityToken()) {
                $ACT = act_revert($ACT);
            } else {
                $ACT = 'show';
            }
        }
        //save
        if ($ACT == 'save') {
            if (checkSecurityToken()) {
                $ACT = act_save($ACT);
            } else {
                $ACT = 'show';
            }
        }
        //cancel conflicting edit
        if ($ACT == 'cancel') {
            $ACT = 'show';
        }
        //draft deletion
        if ($ACT == 'draftdel') {
            $ACT = act_draftdel($ACT);
        }
        //draft saving on preview
        if ($ACT == 'preview') {
            $ACT = act_draftsave($ACT);
        }
        //edit
        if (($ACT == 'edit' || $ACT == 'preview') && $INFO['editable']) {
            $ACT = act_edit($ACT);
        } else {
            unlock($ID);
            //try to unlock
        }
        //handle export
        if (substr($ACT, 0, 7) == 'export_') {
            $ACT = act_export($ACT);
        }
        //display some infos
        if ($ACT == 'check') {
            check();
            $ACT = 'show';
        }
        //handle admin tasks
        if ($ACT == 'admin') {
            // retrieve admin plugin name from $_REQUEST['page']
            if (!empty($_REQUEST['page'])) {
                $pluginlist = plugin_list('admin');
                if (in_array($_REQUEST['page'], $pluginlist)) {
                    // attempt to load the plugin
                    if (($plugin =& plugin_load('admin', $_REQUEST['page'])) !== null) {
                        $plugin->handle();
                    }
                }
            }
        }
        // check permissions again - the action may have changed
        $ACT = act_permcheck($ACT);
    }
    // end event ACTION_ACT_PREPROCESS default action
    $evt->advise_after();
    unset($evt);
    // when action 'show', the intial not 'show' and POST, do a redirect
    if ($ACT == 'show' && $preact != 'show' && strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
        act_redirect($ID, $preact);
    }
    //call template FIXME: all needed vars available?
    $headers[] = 'Content-Type: text/html; charset=utf-8';
    trigger_event('ACTION_HEADERS_SEND', $headers, 'act_sendheaders');
    include template('main.php');
    // output for the commands is now handled in inc/templates.php
    // in function tpl_content()
}
コード例 #5
0
ファイル: actions.php プロジェクト: kevinlovesing/dokuwiki
/**
 * Call the needed action handlers
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 * @triggers ACTION_ACT_PREPROCESS
 * @triggers ACTION_HEADERS_SEND
 */
function act_dispatch()
{
    global $ACT;
    global $ID;
    global $INFO;
    global $QUERY;
    /* @var Input $INPUT */
    global $INPUT;
    global $lang;
    global $conf;
    $preact = $ACT;
    // give plugins an opportunity to process the action
    $evt = new Doku_Event('ACTION_ACT_PREPROCESS', $ACT);
    $headers = array();
    if ($evt->advise_before()) {
        //sanitize $ACT
        $ACT = act_validate($ACT);
        //check if searchword was given - else just show
        $s = cleanID($QUERY);
        if ($ACT == 'search' && empty($s)) {
            $ACT = 'show';
        }
        //login stuff
        if (in_array($ACT, array('login', 'logout'))) {
            $ACT = act_auth($ACT);
        }
        //check if user is asking to (un)subscribe a page
        if ($ACT == 'subscribe') {
            try {
                $ACT = act_subscription($ACT);
            } catch (Exception $e) {
                msg($e->getMessage(), -1);
            }
        }
        //display some info
        if ($ACT == 'check') {
            check();
            $ACT = 'show';
        }
        //check permissions
        $ACT = act_permcheck($ACT);
        //sitemap
        if ($ACT == 'sitemap') {
            act_sitemap($ACT);
        }
        //recent changes
        if ($ACT == 'recent') {
            $show_changes = $INPUT->str('show_changes');
            if (!empty($show_changes)) {
                set_doku_pref('show_changes', $show_changes);
            }
        }
        //diff
        if ($ACT == 'diff') {
            $difftype = $INPUT->str('difftype');
            if (!empty($difftype)) {
                set_doku_pref('difftype', $difftype);
            }
        }
        //register
        if ($ACT == 'register' && $INPUT->post->bool('save') && register()) {
            $ACT = 'login';
        }
        if ($ACT == 'resendpwd' && act_resendpwd()) {
            $ACT = 'login';
        }
        // user profile changes
        if (in_array($ACT, array('profile', 'profile_delete'))) {
            if (!$INPUT->server->str('REMOTE_USER')) {
                $ACT = 'login';
            } else {
                switch ($ACT) {
                    case 'profile':
                        if (updateprofile()) {
                            msg($lang['profchanged'], 1);
                            $ACT = 'show';
                        }
                        break;
                    case 'profile_delete':
                        if (auth_deleteprofile()) {
                            msg($lang['profdeleted'], 1);
                            $ACT = 'show';
                        } else {
                            $ACT = 'profile';
                        }
                        break;
                }
            }
        }
        //revert
        if ($ACT == 'revert') {
            if (checkSecurityToken()) {
                $ACT = act_revert($ACT);
            } else {
                $ACT = 'show';
            }
        }
        //save
        if ($ACT == 'save') {
            if (checkSecurityToken()) {
                $ACT = act_save($ACT);
            } else {
                $ACT = 'preview';
            }
        }
        //cancel conflicting edit
        if ($ACT == 'cancel') {
            $ACT = 'show';
        }
        //draft deletion
        if ($ACT == 'draftdel') {
            $ACT = act_draftdel($ACT);
        }
        //draft saving on preview
        if ($ACT == 'preview') {
            $headers[] = "X-XSS-Protection: 0";
            $ACT = act_draftsave($ACT);
        }
        //edit
        if (in_array($ACT, array('edit', 'preview', 'recover'))) {
            $ACT = act_edit($ACT);
        } else {
            unlock($ID);
            //try to unlock
        }
        //handle export
        if (substr($ACT, 0, 7) == 'export_') {
            $ACT = act_export($ACT);
        }
        //handle admin tasks
        if ($ACT == 'admin') {
            // retrieve admin plugin name from $_REQUEST['page']
            if (($page = $INPUT->str('page', '', true)) != '') {
                /** @var $plugin DokuWiki_Admin_Plugin */
                if ($plugin = plugin_getRequestAdminPlugin()) {
                    $plugin->handle();
                }
            }
        }
        // check permissions again - the action may have changed
        $ACT = act_permcheck($ACT);
    }
    // end event ACTION_ACT_PREPROCESS default action
    $evt->advise_after();
    // Make sure plugs can handle 'denied'
    if ($conf['send404'] && $ACT == 'denied') {
        http_status(403);
    }
    unset($evt);
    // when action 'show', the intial not 'show' and POST, do a redirect
    if ($ACT == 'show' && $preact != 'show' && strtolower($INPUT->server->str('REQUEST_METHOD')) == 'post') {
        act_redirect($ID, $preact);
    }
    global $INFO;
    global $conf;
    global $license;
    //call template FIXME: all needed vars available?
    $headers[] = 'Content-Type: text/html; charset=utf-8';
    trigger_event('ACTION_HEADERS_SEND', $headers, 'act_sendheaders');
    include template('main.php');
    // output for the commands is now handled in inc/templates.php
    // in function tpl_content()
}