public function write()
 {
     $output = PKWK_YAMLCONFIG_HEAD . yaml_emit($this->getArrayCopy()) . PKWK_YAMLCONFIG_TAIL;
     $source = get_source($this->page, TRUE, TRUE);
     $source = $source != FALSE && preg_match(PKWK_YAMLCONFIG_PATTERN, $source) ? preg_replace(PKWK_YAMLCONFIG_PATTERN, $output, $source) : $output;
     page_write($this->page, $source);
     return $source;
 }
Esempio n. 2
0
function plugin_vote_action()
{
    global $vars, $script, $cols, $rows;
    global $_title_collided, $_msg_collided, $_title_updated;
    global $_vote_plugin_votes;
    if (PKWK_READONLY) {
        die_message('PKWK_READONLY prohibits editing');
    }
    $postdata_old = get_source($vars['refer']);
    $vote_no = 0;
    $title = $body = $postdata = $postdata_input = $vote_str = '';
    $matches = array();
    foreach ($postdata_old as $line) {
        if (!preg_match('/^#vote(?:\\((.*)\\)(.*))?$/i', $line, $matches) || $vote_no++ != $vars['vote_no']) {
            $postdata .= $line;
            continue;
        }
        $args = explode(',', $matches[1]);
        $lefts = isset($matches[2]) ? $matches[2] : '';
        foreach ($args as $arg) {
            $cnt = 0;
            if (preg_match('/^(.+)\\[(\\d+)\\]$/', $arg, $matches)) {
                $arg = $matches[1];
                $cnt = $matches[2];
            }
            $e_arg = encode($arg);
            if (!empty($vars['vote_' . $e_arg]) && $vars['vote_' . $e_arg] == $_vote_plugin_votes) {
                ++$cnt;
            }
            $votes[] = $arg . '[' . $cnt . ']';
        }
        $vote_str = '#vote(' . @join(',', $votes) . ')' . $lefts . "\n";
        $postdata_input = $vote_str;
        $postdata .= $vote_str;
    }
    if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
        $title = $_title_collided;
        $s_refer = htmlsc($vars['refer']);
        $s_digest = htmlsc($vars['digest']);
        $s_postdata_input = htmlsc($postdata_input);
        $body = <<<EOD
{$_msg_collided}
<form action="{$script}?cmd=preview" method="post">
 <div>
  <input type="hidden" name="refer"  value="{$s_refer}" />
  <input type="hidden" name="digest" value="{$s_digest}" />
  <textarea name="msg" rows="{$rows}" cols="{$cols}" id="textarea">{$s_postdata_input}</textarea><br />
 </div>
</form>

EOD;
    } else {
        page_write($vars['refer'], $postdata);
        $title = $_title_updated;
    }
    $vars['page'] = $vars['refer'];
    return array('msg' => $title, 'body' => $body);
}
Esempio n. 3
0
function plugin_memo_action()
{
    global $script, $vars, $cols, $rows;
    global $_title_collided, $_msg_collided, $_title_updated;
    if (PKWK_READONLY) {
        die_message('PKWK_READONLY prohibits editing');
    }
    if (!isset($vars['msg']) || $vars['msg'] == '') {
        return;
    }
    $memo_body = preg_replace('/' . "\r" . '/', '', $vars['msg']);
    $memo_body = str_replace("\n", '\\n', $memo_body);
    $memo_body = str_replace('"', '&#x22;', $memo_body);
    // Escape double quotes
    $memo_body = str_replace(',', '&#x2c;', $memo_body);
    // Escape commas
    $postdata_old = get_source($vars['refer']);
    $postdata = '';
    $memo_no = 0;
    foreach ($postdata_old as $line) {
        if (preg_match("/^#memo\\(?.*\\)?\$/i", $line)) {
            if ($memo_no == $vars['memo_no']) {
                $postdata .= '#memo(' . $memo_body . ')' . "\n";
                $line = '';
            }
            ++$memo_no;
        }
        $postdata .= $line;
    }
    $postdata_input = $memo_body . "\n";
    $body = '';
    if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
        $title = $_title_collided;
        $body = $_msg_collided . "\n";
        $s_refer = htmlspecialchars($vars['refer']);
        $s_digest = htmlspecialchars($vars['digest']);
        $s_postdata_input = htmlspecialchars($postdata_input);
        $body .= <<<EOD
<form action="{$script}?cmd=preview" method="post">
 <div>
 <p>
  <input type="hidden" name="refer"  value="{$s_refer}" />
  <input type="hidden" name="digest" value="{$s_digest}" />
  <textarea name="msg" rows="{$rows}" cols="{$cols}" id="textarea">{$s_postdata_input}</textarea>
 </p>
 </div>
</form>
EOD;
    } else {
        page_write($vars['refer'], $postdata);
        $title = $_title_updated;
    }
    $retvars['msg'] =& $title;
    $retvars['body'] =& $body;
    $vars['page'] = $vars['refer'];
    return $retvars;
}
Esempio n. 4
0
function plugin_insert_action()
{
    global $script, $vars, $cols, $rows;
    global $_title_collided, $_msg_collided, $_title_updated;
    if (PKWK_READONLY) {
        die_message('PKWK_READONLY prohibits editing');
    }
    if (!isset($vars['msg']) || $vars['msg'] == '') {
        return;
    }
    $vars['msg'] = preg_replace('/' . "\r" . '/', '', $vars['msg']);
    $insert = $vars['msg'] != '' ? "\n" . $vars['msg'] . "\n" : '';
    $postdata = '';
    $postdata_old = get_source($vars['refer']);
    $insert_no = 0;
    foreach ($postdata_old as $line) {
        if (!INSERT_INS) {
            $postdata .= $line;
        }
        if (preg_match('/^#insert$/i', $line)) {
            if ($insert_no == $vars['insert_no']) {
                $postdata .= $insert;
            }
            $insert_no++;
        }
        if (INSERT_INS) {
            $postdata .= $line;
        }
    }
    $postdata_input = $insert . "\n";
    $body = '';
    if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
        $title = $_title_collided;
        $body = $_msg_collided . "\n";
        $s_refer = htmlsc($vars['refer']);
        $s_digest = htmlsc($vars['digest']);
        $s_postdata_input = htmlsc($postdata_input);
        $body .= <<<EOD
<form action="{$script}?cmd=preview" method="post">
 <div>
  <input type="hidden" name="refer"  value="{$s_refer}" />
  <input type="hidden" name="digest" value="{$s_digest}" />
  <textarea name="msg" rows="{$rows}" cols="{$cols}" id="textarea">{$s_postdata_input}</textarea><br />
 </div>
</form>
EOD;
    } else {
        page_write($vars['refer'], $postdata);
        $title = $_title_updated;
    }
    $retvars['msg'] = $title;
    $retvars['body'] = $body;
    $vars['page'] = $vars['refer'];
    return $retvars;
}
Esempio n. 5
0
function replace_do($search, $replace, $notimestamp)
{
    global $cycle, $cantedit;
    global $_replace_msg;
    // パスワードが合ってたらいよいよ置換
    $pages = auth::get_existpages();
    $replaced_pages = array();
    foreach ($pages as $page) {
        if (REPLACE_IGNORE_FREEZE) {
            $editable = !in_array($page, $cantedit);
        } else {
            $editable = (!is_freeze($page) and !in_array($page, $cantedit));
        }
        if ($editable) {
            // パスワード一致
            $postdata = '';
            $postdata_old = get_source($page);
            foreach ($postdata_old as $line) {
                // キーワードの置換
                $line = str_replace($search, $replace, $line);
                $postdata .= $line;
            }
            if ($postdata != join('', $postdata_old)) {
                $cycle = 0;
                set_time_limit(30);
                page_write($page, $postdata, $notimestamp);
                $replaced_pages[] = htmlspecialchars($page);
            }
        }
    }
    $vars['cmd'] = 'read';
    if (count($replaced_pages) == 0) {
        return array('msg' => $_replace_msg['msg_H0_no_data'], 'body' => '<p>' . $_replace_msg['msg_no_replaced'] . '</p>');
    }
    return array('msg' => $_replace_msg['msg_H0_replaced'], 'body' => '<p>' . $_replace_msg['msg_replaced'] . "</p>\n<p>" . join("<br />\n", $replaced_pages) . '</p>');
}
Esempio n. 6
0
function plugin_delete_write()
{
    global $vars, $trackback, $layout_pages;
    global $notimeupdate, $do_update_diff_table;
    $qm = get_qm();
    $page = isset($vars['page']) ? $vars['page'] : '';
    $digest = isset($vars['digest']) ? $vars['digest'] : '';
    // Collision Detection
    $oldpagesrc = join('', get_source($page));
    $oldpagemd5 = md5($oldpagesrc);
    if ($digest == $oldpagemd5) {
        $retvars = array();
        page_write($page, '');
        $retvars['msg'] = $qm->m['fmt_title_deleted'];
        $retvars['body'] = str_replace('$1', htmlspecialchars($page), $qm->m['fmt_title_deleted']);
        if ($trackback) {
            tb_delete($page);
        }
    } else {
        $retvars['msg'] = '$1 を削除できません';
        $retvars['body'] = $page . 'を削除できませんでした。';
    }
    return $retvars;
}
 /**
  * get readings of pages
  *
  * PukiWiki API Extension
  *
  * arguments $pages version of lib/file.php get_reading
  *
  * @access public
  * @static
  * @param mixed $pages array of pages or a pagename
  *   if not given, get readings of all existing pages
  * @return array readings
  * @version $Id: v 1.0 2008-06-05 11:14:46 sonots $
  */
 function get_readings($pages = array())
 {
     global $pagereading_enable, $pagereading_kanji2kana_converter;
     global $pagereading_kanji2kana_encoding, $pagereading_chasen_path;
     global $pagereading_kakasi_path, $pagereading_config_page;
     global $pagereading_config_dict;
     $pages = (array) $pages;
     if (empty($pages)) {
         $pages = get_existpages();
     }
     $readings = array();
     foreach ($pages as $page) {
         $readings[$page] = '';
     }
     $deletedPage = false;
     $matches = array();
     foreach (get_source($pagereading_config_page) as $line) {
         $line = chop($line);
         if (preg_match('/^-\\[\\[([^]]+)\\]\\]\\s+(.+)$/', $line, $matches)) {
             if (isset($readings[$matches[1]])) {
                 // This page is not clear how to be pronounced
                 $readings[$matches[1]] = $matches[2];
             } else {
                 // This page seems deleted
                 $deletedPage = true;
             }
         }
     }
     // If enabled ChaSen/KAKASI execution
     if ($pagereading_enable) {
         // Check there's non-clear-pronouncing page
         $unknownPage = false;
         foreach ($readings as $page => $reading) {
             if ($reading == '') {
                 $unknownPage = true;
                 break;
             }
         }
         // Execute ChaSen/KAKASI, and get annotation
         if ($unknownPage) {
             switch (strtolower($pagereading_kanji2kana_converter)) {
                 case 'chasen':
                     if (!file_exists($pagereading_chasen_path)) {
                         die_message('ChaSen not found: ' . $pagereading_chasen_path);
                     }
                     $tmpfname = tempnam(realpath(CACHE_DIR), 'PageReading');
                     $fp = fopen($tmpfname, 'w') or die_message('Cannot write temporary file "' . $tmpfname . '".' . "\n");
                     foreach ($readings as $page => $reading) {
                         if ($reading != '') {
                             continue;
                         }
                         fputs($fp, mb_convert_encoding($page . "\n", $pagereading_kanji2kana_encoding, SOURCE_ENCODING));
                     }
                     fclose($fp);
                     $chasen = "{$pagereading_chasen_path} -F %y {$tmpfname}";
                     $fp = popen($chasen, 'r');
                     if ($fp === false) {
                         unlink($tmpfname);
                         die_message('ChaSen execution failed: ' . $chasen);
                     }
                     foreach ($readings as $page => $reading) {
                         if ($reading != '') {
                             continue;
                         }
                         $line = fgets($fp);
                         $line = mb_convert_encoding($line, SOURCE_ENCODING, $pagereading_kanji2kana_encoding);
                         $line = chop($line);
                         $readings[$page] = $line;
                     }
                     pclose($fp);
                     unlink($tmpfname) or die_message('Temporary file can not be removed: ' . $tmpfname);
                     break;
                 case 'kakasi':
                     /*FALLTHROUGH*/
                 /*FALLTHROUGH*/
                 case 'kakashi':
                     if (!file_exists($pagereading_kakasi_path)) {
                         die_message('KAKASI not found: ' . $pagereading_kakasi_path);
                     }
                     $tmpfname = tempnam(realpath(CACHE_DIR), 'PageReading');
                     $fp = fopen($tmpfname, 'w') or die_message('Cannot write temporary file "' . $tmpfname . '".' . "\n");
                     foreach ($readings as $page => $reading) {
                         if ($reading != '') {
                             continue;
                         }
                         fputs($fp, mb_convert_encoding($page . "\n", $pagereading_kanji2kana_encoding, SOURCE_ENCODING));
                     }
                     fclose($fp);
                     $kakasi = "{$pagereading_kakasi_path} -kK -HK -JK < {$tmpfname}";
                     $fp = popen($kakasi, 'r');
                     if ($fp === false) {
                         unlink($tmpfname);
                         die_message('KAKASI execution failed: ' . $kakasi);
                     }
                     foreach ($readings as $page => $reading) {
                         if ($reading != '') {
                             continue;
                         }
                         $line = fgets($fp);
                         $line = mb_convert_encoding($line, SOURCE_ENCODING, $pagereading_kanji2kana_encoding);
                         $line = chop($line);
                         $readings[$page] = $line;
                     }
                     pclose($fp);
                     unlink($tmpfname) or die_message('Temporary file can not be removed: ' . $tmpfname);
                     break;
                 case 'none':
                     $patterns = $replacements = $matches = array();
                     foreach (get_source($pagereading_config_dict) as $line) {
                         $line = chop($line);
                         if (preg_match('|^ /([^/]+)/,\\s*(.+)$|', $line, $matches)) {
                             $patterns[] = $matches[1];
                             $replacements[] = $matches[2];
                         }
                     }
                     foreach ($readings as $page => $reading) {
                         if ($reading != '') {
                             continue;
                         }
                         $readings[$page] = $page;
                         foreach ($patterns as $no => $pattern) {
                             $readings[$page] = mb_convert_kana(mb_ereg_replace($pattern, $replacements[$no], $readings[$page]), 'aKCV');
                         }
                     }
                     break;
                 default:
                     die_message('Unknown kanji-kana converter: ' . $pagereading_kanji2kana_converter . '.');
                     break;
             }
         }
         if ($unknownPage || $deletedPage) {
             asort($readings);
             // Sort by pronouncing(alphabetical/reading) order
             $body = '';
             foreach ($readings as $page => $reading) {
                 $body .= '-[[' . $page . ']] ' . $reading . "\n";
             }
             page_write($pagereading_config_page, $body);
         }
     }
     // Pages that are not prounouncing-clear, return pagenames of themselves
     foreach ($pages as $page) {
         if ($readings[$page] == '') {
             $readings[$page] = $page;
         }
     }
     return $readings;
 }
Esempio n. 8
0
function plugin_listbox_mkconfig()
{
    $conffile = ':config/' . PLUGIN_LISTBOX_CONFIGPAGE;
    if (!is_page($conffile)) {
        $qm = get_qm();
        $maxyear = date("Y") + 5;
        $contents = '#close

* listbox setting [#v69f5c78]

' . $qm->m['plg_listbox']['cfg_desc'] . '

' . $qm->m['plg_listbox']['cfg_ex1'] . '

' . $qm->m['plg_listbox']['cfg_ex2'] . '

' . $qm->m['plg_listbox']['cfg_ntc'] . '


* member [#j18e38d8]
| -- |
|Taro|
|Hanako|
|Ken|
|Michael|

* year [#cad00f59]
|1960|' . $maxyear . '|

* mon [#c1ae4bb0]
|1|12|

* Mon
|Jan.|
|Feb.|
|Mar.|
|Apr.|
|May |
|Jun.|
|Jul.|
|Aug.|
|Sep.|
|Oct.|
|Nov.|
|Dec.|

* Month
|January|
|February|
|March|
|April|
|May|
|June|
|July|
|August|
|September|
|October|
|November|
|December|

* day [#ub609568]
|1|31|

* hour [#l156dc58]
|1|24|

* min [#h6c0ab82]
|1|60|

* sec [#lfb1a875]
|1|60|
';
        page_write($conffile, $contents);
    }
}
Esempio n. 9
0
function plugin_tracker_action()
{
    global $post, $vars, $now;
    if (PKWK_READONLY) {
        die_message('PKWK_READONLY prohibits editing');
    }
    $config_name = array_key_exists('_config', $post) ? $post['_config'] : '';
    $config = new Config('plugin/tracker/' . $config_name);
    if (!$config->read()) {
        return "<p>config file '" . htmlsc($config_name) . "' not found.</p>";
    }
    $config->config_name = $config_name;
    $source = $config->page . '/page';
    $refer = array_key_exists('_refer', $post) ? $post['_refer'] : $post['_base'];
    if (!is_pagename($refer)) {
        return array('msg' => 'cannot write', 'body' => 'page name (' . htmlsc($refer) . ') is not valid.');
    }
    if (!is_page($source)) {
        return array('msg' => 'cannot write', 'body' => 'page template (' . htmlsc($source) . ') is not exist.');
    }
    // ページ名を決定
    $base = $post['_base'];
    $num = 0;
    $name = array_key_exists('_name', $post) ? $post['_name'] : '';
    if (array_key_exists('_page', $post)) {
        $page = $real = $post['_page'];
    } else {
        $real = is_pagename($name) ? $name : ++$num;
        $page = get_fullname('./' . $real, $base);
    }
    if (!is_pagename($page)) {
        $page = $base;
    }
    while (is_page($page)) {
        $real = ++$num;
        $page = "{$base}/{$real}";
    }
    // ページデータを生成
    $postdata = plugin_tracker_get_source($source);
    // 規定のデータ
    $_post = array_merge($post, $_FILES);
    $_post['_date'] = $now;
    $_post['_page'] = $page;
    $_post['_name'] = $name;
    $_post['_real'] = $real;
    // $_post['_refer'] = $_post['refer'];
    $fields = plugin_tracker_get_fields($page, $refer, $config);
    // Creating an empty page, before attaching files
    touch(get_filename($page));
    foreach (array_keys($fields) as $key) {
        $value = array_key_exists($key, $_post) ? $fields[$key]->format_value($_post[$key]) : '';
        foreach (array_keys($postdata) as $num) {
            if (trim($postdata[$num]) == '') {
                continue;
            }
            $postdata[$num] = str_replace("[{$key}]", ($postdata[$num][0] == '|' or $postdata[$num][0] == ':') ? str_replace('|', '&#x7c;', $value) : $value, $postdata[$num]);
        }
    }
    // Writing page data, without touch
    page_write($page, join('', $postdata));
    $r_page = rawurlencode($page);
    pkwk_headers_sent();
    header('Location: ' . get_script_uri() . '?' . $r_page);
    exit;
}
Esempio n. 10
0
function plugin_approve_action()
{
    global $vars, $post;
    if (auth::check_role('readonly')) {
        die_message(_('PKWK_READONLY prohibits editing'));
    }
    if (auth::is_check_role(PKWK_CREATE_PAGE)) {
        die_message(_('PKWK_CREATE_PAGE prohibits editing'));
    }
    // Petit SPAM Check (Client(Browser)-Server Ticket Check)
    $spam = FALSE;
    if (function_exists('pkwk_session_start') && pkwk_session_start() != 0) {
        $s_tracker = md5(get_ticket() . 'Approve');
        error_log("\$s_tracker: " . $s_tracker);
        error_log("\$_SESSION['tracker']: " . $_SESSION['tracker']);
    } else {
        if (isset($post['encode_hint']) && $post['encode_hint'] != '') {
            error_log("\$post['encode_hint']: " . $post['encode_hint']);
            if (PKWK_ENCODING_HINT != $post['encode_hint']) {
                $spam = TRUE;
            }
        } else {
            error_log("PKWK_ENCODING_HINT: " . PKWK_ENCODING_HINT);
            if (PKWK_ENCODING_HINT != '') {
                $spam = TRUE;
            }
        }
        error_log("is_spampost: " . is_spampost(array('body'), PLUGIN_TRACKER_REJECT_SPAMCOUNT));
        if (is_spampost(array('body'), PLUGIN_TRACKER_REJECT_SPAMCOUNT)) {
            $spam = TRUE;
        }
    }
    error_log("isSpam: " . $spam);
    if ($spam) {
        honeypot_write();
        return array('msg' => 'cannot write', 'body' => '<p>prohibits editing</p>');
    }
    $name = isset($post['name']) ? $post['name'] : '';
    $page = isset($post['_page']) ? $post['_page'] : '';
    if ($name == '') {
        return '<p>approve(): empty name.</p>';
    }
    if ($page == '') {
        return '<p>approve(): empty page.</p>';
    }
    $config_path = PLUGIN_APPROVE_CONFIG_ROOT . $name;
    $config = new YamlConfig($config_path);
    if (!$config->read()) {
        return array('msg' => 'Approve', 'body' => '<p>approve(): failed to load config. "' . $config_path . '"</p>');
    }
    $pattern = $config[PLUGIN_APPROVE_KEY_PATTERN];
    $replace = $config[PLUGIN_APPROVE_KEY_REPLACE];
    $page_regex = $config[PLUGIN_APPROVE_KEY_PAGE_REGEX];
    if ($page == '') {
        return array('msg' => 'Approve', 'body' => '<p>approve(): empty page.</p>');
    }
    if ($pattern == '') {
        return array('msg' => 'Approve', 'body' => '<p>approve(): empty pattern.</p>');
    }
    if ($page_regex == '') {
        return array('msg' => 'Approve', 'body' => '<p>approve(): empty page_regex.</p>');
    }
    if (!preg_match($page_regex, $page)) {
        return array('msg' => 'Approve', 'body' => '<p>approve(): page not match.</p>');
    }
    if (PKWK_READONLY > 0 || is_freeze($vars['page']) || !plugin_approve_is_edit_authed($page)) {
        return array('msg' => 'Approve', 'body' => '<p>approve(): prohibit editing. "' . $page . '"</p>');
    }
    $source = get_source($page, TRUE, TRUE);
    if ($source === FALSE) {
        return array('msg' => 'Approve', 'body' => '<p>approve(): failed to load page. "' . $page . '"</p>');
    }
    if (strpos($source, $pattern) === FALSE) {
        return array('msg' => 'Approve', 'body' => '<p>approve(): pattern not match.</p>');
    }
    $source = str_replace($pattern, $replace, $source);
    //return array('msg'=>'Approve', 'body'=>$source);
    page_write($page, $source);
    pkwk_headers_sent();
    header('Location: ' . get_page_location_uri($page));
    exit;
}
function plugin_replace_tak_action()
{
    global $script, $post;
    $pass = isset($post['pass']) ? $post['pass'] : NULL;
    $prefix = isset($post['prefix']) ? $post['prefix'] : NULL;
    $search = isset($post['search']) ? $post['search'] : PLUGIN_REPLACE_TAK_SEARCH_DEFAULT;
    $replace = isset($post['replace']) ? $post['replace'] : NULL;
    $act = isset($post['act']) ? $post['act'] : NULL;
    $preserveTimeStamp = array_key_exists('preserveTimeStamp', $post) ? $post['preserveTimeStamp'] : NULL;
    $changedpages = array();
    $body = '';
    $replace_real = stripcslashes($replace);
    $preserveTimeStamp = $preserveTimeStamp != '' ? TRUE : FALSE;
    $islogin = pkwk_login($pass);
    // パスワード一致
    if ($search != PLUGIN_REPLACE_TAK_SEARCH_DEFAULT && $islogin) {
        $pages = get_existpages();
        if ($prefix != NULL) {
            $tmppages = array();
            foreach ($pages as $page) {
                if (preg_match($prefix, $page)) {
                    $tmppages[] = $page;
                }
            }
            $pages = $tmppages;
        }
        natsort($pages);
        foreach ($pages as $page) {
            $postdata = '';
            $count = 0;
            $postdata_old = join('', get_source($page));
            // キーワードの置換
            $postdata = preg_replace($search, $replace_real, $postdata_old, -1, $count);
            if ($count > 0) {
                $changedpages[] = htmlspecialchars($page);
                if ($act == 'Replace') {
                    set_time_limit(30);
                    page_write($page, $postdata, $preserveTimeStamp);
                }
            }
        }
        if ($act == 'Replace') {
            $body = '<p>Completed.</p>';
        }
    }
    if ($pass !== NULL && !$islogin) {
        $body .= "<p><strong>Password error.</strong></p>\n";
    }
    $replacebutton = $islogin && count($changedpages) > 0 && ($act == 'Preview' || $act == 'Replace') ? '<input type="submit" name="act" value="Replace" />' : '';
    $statTimeStamp = $preserveTimeStamp ? 'checked' : '';
    $body .= <<<EOD
<p>Please input the keyword and password to replace.</p>
<form action="{$script}" method="post">
 <div>
  <input type="hidden" name="plugin" value="replace_tak" />
  <p>Page Prefix (option, 'Regular Expression (Perl-Compatible)' needed)<br />
  <input type="text" name="prefix" size="60" value="{$prefix}" /> </p>
  <p>Search word ('Regular Expression (Perl-Compatible)' needed)<br />
  <input type="text" name="search" size="60" value="{$search}" /></p>
  <p>Replace word<br />
  <input type="text" name="replace" size="60" value="{$replace}" /> </p>
  <p>Password<br />
  <input type="password" name="pass" size="12" value="{$pass}" /> </p>
  <p><input type="checkbox" name="preserveTimeStamp" {$statTimeStamp} /> preserve time stamp</p>
  <p><input type="submit" name="act" value="Preview" /> {$replacebutton}</p>
 </div>
</form>

EOD;
    if ($search != PLUGIN_REPLACE_TAK_SEARCH_DEFAULT) {
        $body .= "<p>Target: " . count($changedpages) . " page(s).</p>\n";
    }
    if (count($changedpages) > 0) {
        $body .= "<ul>\n";
        foreach ($changedpages as $page) {
            $body .= '<li>' . make_link($page) . "\n";
        }
        $body .= "</ul>\n";
    }
    return array('msg' => 'Replace with regular expression', 'body' => $body);
}
function plugin_urlbookmark_action()
{
    global $script, $vars, $post, $now;
    if (auth::check_role('readonly')) {
        die_message('PKWK_READONLY prohibits editing');
    }
    $post['msg'] = preg_replace("/\n/", '', $post['msg']);
    $url = $post['url'];
    if ($url == '') {
        return array('msg' => '', 'body' => '');
    }
    $head = '';
    if (preg_match('/^(-{1,2})(.*)/', $post['msg'], $match)) {
        $head = $match[1];
        $post['msg'] = $match[2];
    }
    $title = $post['title'];
    if ($title == '') {
        // try to get the title from the site
        $title = plugin_urlbookmark_get_title($url);
    }
    if ($title == '') {
        $_name = str_replace('$name', $url, URLBOOKMARK_NAME_FORMAT);
    } else {
        $patterns = array("/:/", "/\\[/", "/\\]/");
        $replace = array(" ", "(", ")");
        $title = preg_replace($patterns, $replace, $title);
        $_name = str_replace('$name', '[[' . $title . ":" . $url . ']]', URLBOOKMARK_NAME_FORMAT);
    }
    $_msg = str_replace('$msg', $post['msg'], URLBOOKMARK_MSG_FORMAT);
    $_now = $post['nodate'] == '1' ? '' : str_replace('$now', $now, URLBOOKMARK_NOW_FORMAT);
    $urlbookmark = str_replace("MSG", $_msg, URLBOOKMARK_FORMAT);
    $urlbookmark = str_replace("NAME", $_name, $urlbookmark);
    $urlbookmark = str_replace("NOW", $_now, $urlbookmark);
    $urlbookmark = $head . $urlbookmark;
    $postdata = '';
    $postdata_old = get_source($post['refer']);
    $urlbookmark_no = 0;
    $urlbookmark_ins = $post['above'] == '1';
    foreach ($postdata_old as $line) {
        if (!$urlbookmark_ins) {
            $postdata .= $line;
        }
        if (preg_match('/^#urlbookmark/', $line) and $urlbookmark_no++ == $post['urlbookmark_no']) {
            $postdata = rtrim($postdata) . "\n-{$urlbookmark}\n";
            if ($urlbookmark_ins) {
                $postdata .= "\n";
            }
        }
        if ($urlbookmark_ins) {
            $postdata .= $line;
        }
    }
    $title = _(" \$1 was updated");
    $body = '';
    if (md5(@join('', get_source($post['refer']))) != $post['digest']) {
        $title = _("On updating  \$1, a collision has occurred.");
        $body = _("It seems that someone has already updated this page while you were editing it.<br />") . _("It is likely to be inserted in a different position though it bookmarked.<br />") . make_pagelink($post['refer']);
    }
    page_write($post['refer'], $postdata);
    $retvars['msg'] = $title;
    $retvars['body'] = $body;
    $post['page'] = $vars['page'] = $post['refer'];
    return $retvars;
}
Esempio n. 13
0
function plugin_commentx_write()
{
    global $script, $vars, $now;
    global $_no_name;
    //	global $_msg_comment_collided, $_title_comment_collided, $_title_updated;
    $_title_updated = _("\$1 was updated");
    $_title_comment_collided = _("On updating  \$1, a collision has occurred.");
    $_msg_comment_collided = _("It seems that someone has already updated the page you were editing.<br />") . _("The comment was added, alhough it may be inserted in the wrong position.<br />");
    if (!isset($vars['msg'])) {
        return array('msg' => '', 'body' => '');
    }
    // Do nothing
    if (preg_match(PLUGIN_COMMENTX_NGWORD, $vars['msg'])) {
        return array('msg' => '', 'body' => '');
    }
    // Validate
    if (is_spampost(array('msg'))) {
        return plugin_commentx_honeypot();
    }
    $vars['msg'] = preg_replace('/\\s+$/', "", $vars['msg']);
    // Cut last LF
    if (PLUGIN_COMMENTX_LINE_BREAK) {
        // Convert linebreaks into pukiwiki's linebreaks &br;
        $vars['msg'] = str_replace("\n", "&br;\n", $vars['msg']);
    } else {
        // Replace empty lines into #br
        $vars['msg'] = preg_replace('/^\\s*\\n/m', "#br\n", $vars['msg']);
    }
    $head = '';
    $match = array();
    if (preg_match('/^(-{1,2})-*\\s*(.*)/', $vars['msg'], $match)) {
        $head =& $match[1];
        $vars['msg'] =& $match[2];
    }
    if ($vars['msg'] == '') {
        return array('msg' => '', 'body' => '');
    }
    // Do nothing
    $comment = str_replace('$msg', $vars['msg'], PLUGIN_COMMENTX_FORMAT_MSG);
    list($nick, $vars['name'], $disabled) = plugin_commentx_get_nick();
    if (isset($vars['name']) || $vars['nodate'] != '1') {
        $_name = !isset($vars['name']) || $vars['name'] == '' ? $_no_name : $vars['name'];
        $_name = $_name == '' ? '' : str_replace('$name', $_name, PLUGIN_COMMENTX_FORMAT_NAME);
        $_now = $vars['nodate'] == '1' ? '' : str_replace('$now', $now, PLUGIN_COMMENTX_FORMAT_NOW);
        $comment = str_replace("MSG", $comment, PLUGIN_COMMENTX_FORMAT_STRING);
        $comment = str_replace("NAME", $_name, $comment);
        $comment = str_replace("NOW", $_now, $comment);
    }
    $comment = '-' . $head . ' ' . $comment;
    $postdata = '';
    $comment_no = 0;
    $above = isset($vars['above']) && $vars['above'] == '1';
    foreach (get_source($vars['refer']) as $line) {
        if (!$above) {
            $postdata .= $line;
        }
        if (preg_match('/^#commentx/i', $line) && $comment_no++ == $vars['comment_no']) {
            if ($above) {
                $postdata = rtrim($postdata) . "\n" . $comment . "\n" . "\n";
                // Insert one blank line above #commment, to avoid indentation
            } else {
                $postdata = rtrim($postdata) . "\n" . $comment . "\n";
                // Insert one blank line below #commment
            }
        }
        if ($above) {
            $postdata .= $line;
        }
    }
    $title = $_title_updated;
    $body = '';
    if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
        $title = $_title_comment_collided;
        $body = $_msg_comment_collided . make_pagelink($vars['refer']);
    }
    page_write($vars['refer'], $postdata);
    $retvars['msg'] = $title;
    $retvars['body'] = $body;
    if ($vars['refpage']) {
        header("Location: {$script}?" . rawurlencode($vars['refpage']));
        exit;
    }
    $vars['page'] = $vars['refer'];
    return $retvars;
}
Esempio n. 14
0
function paint_insert_ref($filename)
{
    global $script, $vars, $now, $do_backup;
    global $_paint_messages, $_no_name;
    $ret['msg'] = $_paint_messages['msg_title'];
    $msg = mb_convert_encoding(rtrim($vars['msg']), SOURCE_ENCODING, 'auto');
    $name = mb_convert_encoding($vars['yourname'], SOURCE_ENCODING, 'auto');
    $msg = str_replace('$msg', $msg, PAINT_MSG_FORMAT);
    $name = $name == '' ? $_no_name : $vars['yourname'];
    $name = $name == '' ? '' : str_replace('$name', $name, PAINT_NAME_FORMAT);
    $now = str_replace('$now', $now, PAINT_NOW_FORMAT);
    $msg = trim($msg);
    $msg = $msg == '' ? PAINT_FORMAT_NOMSG : str_replace("MSG", $msg, PAINT_FORMAT);
    $msg = str_replace("NAME", $name, $msg);
    $msg = str_replace("NOW", $now, $msg);
    //ブロックに食われないように、#clearの直前に\nを2個書いておく
    $msg = "#ref({$filename},wrap,around)\n" . trim($msg) . "\n\n" . "#clear\n";
    $postdata_old = get_source($vars['refer']);
    $postdata = '';
    $paint_no = 0;
    //'#paint'の出現回数
    foreach ($postdata_old as $line) {
        if (!PAINT_INSERT_INS) {
            $postdata .= $line;
        }
        if (preg_match('/^#paint/i', $line)) {
            if ($paint_no == $vars['paint_no']) {
                $postdata .= $msg;
            }
            $paint_no++;
        }
        if (PAINT_INSERT_INS) {
            $postdata .= $line;
        }
    }
    // 更新の衝突を検出
    if (md5(join('', $postdata_old)) != $vars['digest']) {
        $ret['msg'] = $_paint_messages['msg_title_collided'];
        $ret['body'] = $_paint_messages['msg_collided'];
    }
    page_write($vars['refer'], $postdata);
    return $ret;
}
function adm_auth_wkgrp_import()
{
    global $_adm_auth_wkgrp_msg;
    $config_page_name = ':config/' . CONFIG_AUTH_WKGRP;
    // 処理中に誰かがページを作成した場合にしか発生しないはず
    if (is_page($config_page_name)) {
        return $_adm_auth_wkgrp_msg['err_already'];
    }
    $data = "#check_role(2)\n" . adm_auth_wkgrp_file2page();
    // このイメージをページに出力
    page_write($config_page_name, $data);
    // php ファイルのタイムスタンプとページを一致させる
    adm_auth_wkgrp_touch_file2page();
    return sprintf($_adm_auth_wkgrp_msg['msg_ok_import'], $config_page_name);
}
Esempio n. 16
0
function plugin_pcomment_auto_log($page, $dir, $count, &$postdata)
{
    if (!PLUGIN_PCOMMENT_AUTO_LOG) {
        return;
    }
    $keys = array_keys(preg_grep('/(?:^-(?!-).*$)/m', $postdata));
    if (count($keys) < PLUGIN_PCOMMENT_AUTO_LOG + $count) {
        return;
    }
    if ($dir) {
        // Top N comments (N = PLUGIN_PCOMMENT_AUTO_LOG)
        $old = array_splice($postdata, $keys[0], $keys[PLUGIN_PCOMMENT_AUTO_LOG] - $keys[0]);
    } else {
        // Bottom N comments
        $old = array_splice($postdata, $keys[count($keys) - PLUGIN_PCOMMENT_AUTO_LOG]);
    }
    // Decide new page name
    $i = 0;
    do {
        ++$i;
        $_page = $page . '/' . $i;
    } while (is_page($_page));
    page_write($_page, '[[' . $page . ']]' . "\n\n" . join('', $old));
    // Recurse :)
    plugin_pcomment_auto_log($page, $dir, $count, $postdata);
}
Esempio n. 17
0
function show_insert_ref($filename)
{
    global $script, $vars, $now, $do_backup;
    $qm = get_qm();
    $slen = strlen(SWFU_IMAGE_DIR);
    $filename = substr($filename, 0, $slen) == SWFU_IMAGE_DIR ? substr($filename, $slen) : $filename;
    $ret['msg'] = $qm->m['plg_attachref']['title'];
    $args = split(",", $vars['show_opt']);
    if (count($args)) {
        $args[0] = $filename;
        //array_shift,unshiftって要するにこれね
        $s_args = implode(",", $args);
    } else {
        $s_args = $filename;
    }
    $msg = "&show({$s_args})";
    $refer = $vars['refer'];
    $digest = $vars['digest'];
    $postdata_old = get_source($refer);
    $thedigest = md5(join('', $postdata_old));
    $postdata = '';
    $show_ct = 0;
    //'#show'の出現回数
    $show_no = $vars['show_no'];
    $skipflag = 0;
    $is_box = false;
    $boxcnt = 0;
    $boxdata = array();
    foreach ($postdata_old as $line) {
        if ($is_box == false && ($skipflag || substr($line, 0, 1) == ' ' || substr($line, 0, 2) == '//')) {
            $postdata .= $line;
            continue;
        }
        if ($is_box == true && preg_match('/^\\}\\}/', $line)) {
            $postdata .= $line;
            $is_box = false;
            continue;
        }
        if ($is_box) {
            $boxdata[$boxcnt][] = $line;
            continue;
        }
        if ($is_box == false && preg_match('/^#.+\\{\\{$/', $line)) {
            $postdata .= $line;
            $is_box = true;
            $postdata .= '${box' . ++$boxcnt . "}\n";
            $boxdata[$boxcnt] = array();
            continue;
        }
        $ct = preg_match_all('/&show(?=[({;])/', $line, $out);
        if ($ct) {
            for ($i = 0; $i < $ct; $i++) {
                if ($show_ct++ == $show_no) {
                    $line = preg_replace('/&show(\\([^(){};]*\\))?(\\{[^{}]*\\})?;/', $msg . '$2;', $line, 1);
                    $skipflag = 1;
                    break;
                } else {
                    $line = preg_replace('/&show(\\([^(){};]*\\))?(\\{[^{}]*\\})?;/', '&___show$1$2___;', $line, 1);
                }
            }
            $line = preg_replace('/&___show(\\([^(){};]*\\))?(\\{[^{}]*\\})?___;/', '&show$1$2;', $line);
        }
        $postdata .= $line;
    }
    foreach ($boxdata as $bi => $box) {
        $boxstr = '';
        foreach ($box as $line) {
            if ($skipflag || substr($line, 0, 1) == ' ' || substr($line, 0, 2) == '//') {
                $boxstr .= $line;
                continue;
            }
            $ct = preg_match_all('/&show(?=[({;])/', $line, $out);
            if ($ct) {
                for ($i = 0; $i < $ct; $i++) {
                    if ($show_ct++ == $show_no) {
                        $line = preg_replace('/&show(\\([^(){};]*\\))?(\\{[^{}]*\\})?;/', $msg . '$2;', $line, 1);
                        $skipflag = 1;
                        break;
                    } else {
                        $line = preg_replace('/&show(\\([^(){};]*\\))?(\\{[^{}]*\\})?;/', '&___show$1$2___;', $line, 1);
                    }
                }
                $line = preg_replace('/&___show(\\([^(){};]*\\))?(\\{[^{}]*\\})?___;/', '&show$1$2;', $line);
            }
            $boxstr .= $line;
        }
        $postdata = str_replace('${box' . $bi . '}', trim($boxstr), $postdata);
    }
    // 更新の衝突を検出
    if ($thedigest != $digest) {
        $ret['msg'] = $qm->m['fmt_title_collided'];
        $ret['body'] = $qm->m['plg_attachref']['collided'];
    }
    page_write($vars['refer'], $postdata);
    return $ret;
}
Esempio n. 18
0
 /**
  * Recent Voted
  *
  * @param string $page voted page
  * @param string $pcmd convert or inline
  * @param integer $vote_id
  * @param integer $choice_id
  * @param array $votes
  * @return void
  */
 function update_recent_voted($page, $pcmd, $vote_id, $choice_id, $votes)
 {
     $limit = max(0, $this->CONF['RECENT_LIMIT']);
     $time = UTIME;
     // RecentVoted
     $lines = get_source($this->CONF['RECENT_PAGE']);
     $anchor = $this->get_anchor($pcmd, $vote_id);
     $args = array();
     foreach ($votes as $vote) {
         list($choice, $count) = $vote;
         $args[] = $choice . '[' . $count . ']';
     }
     $arg = csv_implode(',', $args);
     list($choice, $count) = $votes[$choice_id];
     $addline = '-' . format_date($time) . ' - [[' . $page . '#' . $vote_id . '>' . $page . '#' . $anchor . ']] ' . $choice . ' (' . $arg . ')' . "\n";
     array_unshift($lines, $addline);
     $lines = array_splice($lines, 0, $limit);
     page_write($this->CONF['RECENT_PAGE'], implode('', $lines));
     // recentvoted.dat (serialization)
     if (is_readable($this->CONF['RECENT_LOG'])) {
         $log_contents = file_get_contents($this->CONF['RECENT_LOG']);
         $logs = unserialize($log_contents);
     } else {
         $logs = array();
     }
     $addlog = array($time, $page, $pcmd, $vote_id, $choice_id, $votes);
     array_unshift($logs, $addlog);
     $logs = array_splice($logs, 0, $limit);
     file_put_contents($this->CONF['RECENT_LOG'], serialize($logs));
 }
Esempio n. 19
0
function plugin_mceedit_write()
{
    global $vars, $trackback;
    global $notimeupdate;
    //	global $_title_collided, $_msg_collided_auto, $_msg_collided, $_title_deleted;
    //	global $_msg_invalidpass;
    $page = isset($vars['page']) ? $vars['page'] : '';
    $retvars = array();
    // 手書きの#freezeを削除
    $vars['msg'] = preg_replace('/^#freeze\\s*$/im', '', $vars['msg']);
    $vars['msg'] = $vars['before'] . "\n#html{{\n" . $vars['msg'] . "\n}}\n";
    //TinyMCE
    $postdata = $postdata_input = $vars['msg'];
    if (isset($vars['add']) && $vars['add']) {
        if (isset($vars['add_top']) && $vars['add_top']) {
            $postdata = $postdata . "\n\n" . @join('', get_source($page));
        } else {
            $postdata = @join('', get_source($page)) . "\n\n" . $postdata;
        }
    } else {
        if (isset($vars['id']) && $vars['id']) {
            $source = preg_split('/([^\\n]*\\n)/', $vars['original'], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
            if (plugin_mceedit_parts($vars['id'], $source, $vars['msg']) !== FALSE) {
                $postdata = $postdata_input = join('', $source);
            } else {
                // $post['msg']だけがページに書き込まれてしまうのを防ぐ。
                $postdata = $postdata_input = rtrim($vars['original']) . "\n\n" . $vars['msg'];
            }
        }
    }
    $oldpagesrc = join('', get_source($page));
    $oldpagemd5 = md5($oldpagesrc);
    if (!isset($vars['digest']) || $vars['digest'] != $oldpagemd5) {
        $vars['digest'] = $oldpagemd5;
        $retvars['msg'] = _('On updating  $1, a collision has occurred.');
        list($postdata_input, $auto) = do_update_diff($oldpagesrc, $postdata_input, $vars['original']);
        $_msg_collided_auto = _('It seems that someone has already updated this page while you were editing it.<br />') . _('The collision has been corrected automatically, but there may still be some problems with the page.<br />') . _('To confirm the changes to the page, press [Update].<br />');
        $_msg_collided = _('It seems that someone has already updated this page while you were editing it.<br />') . _(' + is placed at the beginning of a line that was newly added.<br />') . _(' ! is placed at the beginning of a line that has possibly been updated.<br />') . _(' Edit those lines, and submit again.');
        $_msg_invalidpass = _('Invalid password.');
        $retvars['body'] = ($auto ? $_msg_collided_auto : $_msg_collided) . "\n";
        if (TRUE) {
            global $do_update_diff_table;
            $retvars['body'] .= $do_update_diff_table;
        }
        unset($vars['id']);
        // 更新が衝突したら全文編集に切り替え
        $retvars['body'] .= plugin_mceedit_edit_form($page, $postdata_input, $oldpagemd5, FALSE);
    } else {
        if ($postdata) {
            $notimestamp = $notimeupdate != 0 && (isset($vars['notimestamp']) && $vars['notimestamp'] != '');
            // if($notimestamp && ($notimeupdate == 2) && !pkwk_login($vars['pass'])) {
            if ($notimestamp && $notimeupdate == 2 && auth::check_role('role_adm_contents') && !pkwk_login($vars['pass'])) {
                // enable only administrator & password error
                $retvars['body'] = "<p><strong>{$_msg_invalidpass}</strong></p>\n";
                $retvars['body'] .= plugin_mceedit_edit_form($page, $vars['msg'], $vars['digest'], FALSE);
            } else {
                page_write($page, $postdata, $notimestamp);
                pkwk_headers_sent();
                if ($vars['refpage'] != '') {
                    if ($vars['id'] != '') {
                        header('Location: ' . get_script_uri() . '?' . rawurlencode($vars['refpage'])) . '#' . rawurlencode($vars['id']);
                    } else {
                        header('Location: ' . get_script_uri() . '?' . rawurlencode($vars['refpage']));
                    }
                } else {
                    if ($vars['id'] != '') {
                        header('Location: ' . get_script_uri() . '?' . rawurlencode($page)) . '#' . rawurlencode($vars['id']);
                    } else {
                        header('Location: ' . get_script_uri() . '?' . rawurlencode($page));
                    }
                }
                exit;
            }
        } else {
            $_title_deleted = _(' $1 was deleted');
            page_write($page, $postdata);
            $retvars['msg'] = $_title_deleted;
            $retvars['body'] = str_replace('$1', htmlspecialchars($page), $_title_deleted);
            if ($trackback) {
                tb_delete($page);
            }
        }
    }
    return $retvars;
}
function plugin_csv2newpage_write($ary, $base, $postdata, $config)
{
    global $vars, $now, $num;
    $name = empty($ary['_name']) ? '' : $ary['_name'];
    if (!empty($ary['_page'])) {
        $page = $real = $ary['_page'];
        $page = $base . '/' . $page;
    } else {
        $real = is_pagename($name) ? $name : ++$num;
        $page = get_fullname('./' . $real, $base);
    }
    if (!is_pagename($page)) {
        $page = $base;
    }
    while (is_page($page)) {
        $real = ++$num;
        $page = $base . '/' . $real;
    }
    // 規定のデータ
    $_post = array_merge($ary, $vars, $_FILES);
    $_post['_date'] = $now;
    $_post['_page'] = $page;
    $_post['_name'] = $name;
    $_post['_real'] = $real;
    // $_post['_refer'] = $_post['refer'];
    if (!exist_plugin('tracker')) {
        return array('msg' => 'plugin not found', 'body' => 'The tracker plugin is not found.');
    }
    $fields = plugin_tracker_get_fields($base, $page, $config);
    foreach ($fields as $key => $class) {
        if (array_key_exists($key, $_post)) {
            $val = $class->format_value($_post[$key]);
        } else {
            $val = $class->default_value;
        }
        $postdata = str_replace('[' . $key . ']', $val, $postdata);
    }
    // 書き込み
    page_write($page, $postdata);
    return $page;
}
Esempio n. 21
0
function plugin_bugtrack_write($base, $pagename, $summary, $name, $priority, $state, $category, $version, $body)
{
    global $post;
    $base = strip_bracket($base);
    $pagename = strip_bracket($pagename);
    $postdata = plugin_bugtrack_template($base, $summary, $name, $priority, $state, $category, $version, $body);
    $id = $jump = 1;
    $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $id);
    while (is_page($page)) {
        $id = $jump;
        $jump += 50;
        $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $jump);
    }
    $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, $id);
    while (is_page($page)) {
        $page = $base . '/' . sprintf(PLUGIN_BUGTRACK_NUMBER_FORMAT, ++$id);
    }
    if ($pagename == '') {
        page_write($page, $postdata);
    } else {
        $pagename = get_fullname($pagename, $base);
        if (is_page($pagename) || !is_pagename($pagename)) {
            $pagename = $page;
            // Set default
        } else {
            page_write($page, 'move to [[' . $pagename . ']]');
        }
        page_write($pagename, $postdata);
    }
    return $page;
}
Esempio n. 22
0
function plugin_edit_write()
{
    global $post, $vars, $trackback;
    global $notimeupdate, $do_update_diff_table;
    global $use_trans_sid_address;
    //	global $_title_collided, $_msg_collided_auto, $_msg_collided, $_title_deleted;
    //	global $_msg_invalidpass;
    $_title_deleted = _(' $1 was deleted');
    $_msg_invalidpass = _('Invalid password.');
    $page = isset($vars['page']) ? $vars['page'] : '';
    $add = isset($vars['add']) ? $vars['add'] : '';
    $digest = isset($vars['digest']) ? $vars['digest'] : '';
    $partid = isset($vars['id']) ? $vars['id'] : '';
    $notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] != '';
    // Check Validate and Ticket
    if ($notimestamp && !is_page($page)) {
        return plugin_edit_honeypot();
    }
    // SPAM Check (Client(Browser)-Server Ticket Check)
    if (isset($post['encode_hint']) && $post['encode_hint'] != PKWK_ENCODING_HINT) {
        return plugin_edit_honeypot();
    }
    if (!isset($post['encode_hint']) && PKWK_ENCODING_HINT != '') {
        return plugin_edit_honeypot();
    }
    // Validate
    if (is_spampost(array('msg'))) {
        return plugin_edit_honeypot();
    }
    // Paragraph edit mode
    if ($partid) {
        $source = preg_split('/([^\\n]*\\n)/', $vars['original'], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        if (plugin_edit_parts($partid, $source, $vars['msg']) !== FALSE) {
            $vars['msg'] = join('', $source);
        } else {
            $vars['msg'] = rtrim($vars['original']) . "\n\n" . $vars['msg'];
        }
    }
    // Delete "#freeze" command for form edit.
    $vars['msg'] = preg_replace('/^#freeze\\s*$/im', '', $vars['msg']);
    $msg =& $vars['msg'];
    // Reference
    $retvars = array();
    // Collision Detection
    $oldpagesrc = get_source($page, TRUE, TRUE);
    $oldpagemd5 = md5($oldpagesrc);
    if ($digest != $oldpagemd5) {
        $vars['digest'] = $oldpagemd5;
        // Reset
        $original = isset($vars['original']) ? $vars['original'] : '';
        list($postdata_input, $auto) = do_update_diff($oldpagesrc, $msg, $original);
        $_msg_collided_auto = _('It seems that someone has already updated this page while you were editing it.<br />') . _('The collision has been corrected automatically, but there may still be some problems with the page.<br />') . _('To confirm the changes to the page, press [Update].<br />');
        $_msg_collided = _('It seems that someone has already updated this page while you were editing it.<br />') . _(' + is placed at the beginning of a line that was newly added.<br />') . _(' ! is placed at the beginning of a line that has possibly been updated.<br />') . _(' Edit those lines, and submit again.');
        $retvars['msg'] = _('On updating  $1, a collision has occurred.');
        $retvars['body'] = ($auto ? $_msg_collided_auto : $_msg_collided) . "\n";
        $retvars['body'] .= $do_update_diff_table;
        unset($vars['id']);
        // Change edit all-text of pages(from para-edit)
        $retvars['body'] .= edit_form($page, $postdata_input, $oldpagemd5, FALSE);
        return $retvars;
    }
    // Action?
    if ($add) {
        // Add
        if (isset($vars['add_top']) && $vars['add_top']) {
            $postdata = $msg . "\n\n" . @join('', get_source($page));
        } else {
            $postdata = @join('', get_source($page)) . "\n\n" . $msg;
        }
    } else {
        // Edit or Remove
        $postdata =& $msg;
        // Reference
    }
    // NULL POSTING, OR removing existing page
    if ($postdata == '') {
        page_write($page, $postdata);
        $retvars['msg'] = $_title_deleted;
        $retvars['body'] = str_replace('$1', htmlspecialchars($page), $_title_deleted);
        if ($trackback) {
            tb_delete($page);
        }
        return $retvars;
    }
    // $notimeupdate: Checkbox 'Do not change timestamp'
    //	$notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] != '';
    //	if ($notimeupdate > 1 && $notimestamp && ! pkwk_login($vars['pass'])) {
    if ($notimeupdate > 1 && $notimestamp && auth::check_role('role_adm_contents') && !pkwk_login($vars['pass'])) {
        // Enable only administrator & password error
        $retvars['body'] = '<p><strong>' . $_msg_invalidpass . '</strong></p>' . "\n";
        $retvars['body'] .= edit_form($page, $msg, $digest, FALSE);
        return $retvars;
    }
    page_write($page, $postdata, $notimestamp);
    pkwk_headers_sent();
    if (isset($vars['refpage']) && $vars['refpage'] != '') {
        if ($partid) {
            header('Location: ' . get_page_location_uri($vars['refpage'], '', rawurlencode($partid)));
        } else {
            header('Location: ' . get_page_location_uri($vars['refpage']));
        }
    } else {
        if ($partid) {
            header('Location: ' . get_page_location_uri($page, '', rawurlencode($partid)));
        } else {
            header('Location: ' . get_page_location_uri($page));
        }
    }
    exit;
}
Esempio n. 23
0
function plugin_tracker_action()
{
    global $post, $vars, $now;
    //	if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
    if (auth::check_role('readonly')) {
        die_message(_('PKWK_READONLY prohibits editing'));
    }
    if (auth::is_check_role(PKWK_CREATE_PAGE)) {
        die_message(_('PKWK_CREATE_PAGE prohibits editing'));
    }
    $base = isset($post['_base']) ? $post['_base'] : '';
    $refer = isset($post['_refer']) ? $post['_refer'] : '';
    $createProxy = isset($post['_createProxy']) ? $post['_createProxy'] : '';
    // $page name to add will be decided here
    $num = 0;
    $name = isset($post['_name']) ? $post['_name'] : '';
    if (isset($post['_page'])) {
        $real = $page = $post['_page'];
    } else {
        $real = is_pagename($name) ? $name : ++$num;
        $page = get_fullname('./' . $real, $base);
    }
    if (!is_pagename($page)) {
        $page = $base;
    }
    while (is_page($page)) {
        $real = ++$num;
        $page = $base . '/' . $real;
    }
    $config = isset($post['_config']) ? $post['_config'] : '';
    $createProxy = isset($post['_createProxy']) ? $post['_createProxy'] : '';
    // Petit SPAM Check (Client(Browser)-Server Ticket Check)
    $spam = FALSE;
    if (function_exists('pkwk_session_start') && pkwk_session_start() != 0) {
        $s_tracker = md5(get_ticket() . $config_name);
        error_log("\$s_tracker: " . $s_tracker);
        error_log("\$_SESSION['tracker']: " . $_SESSION['tracker']);
        //		if ($_SESSION['tracker'] != $s_tracker) {
        //			$spam = TRUE;
        //		}
    } else {
        if (isset($post['encode_hint']) && $post['encode_hint'] != '') {
            if (PKWK_ENCODING_HINT != $post['encode_hint']) {
                $spam = TRUE;
            }
        } else {
            if (PKWK_ENCODING_HINT != '') {
                $spam = TRUE;
            }
        }
        if (is_spampost(array('body'), PLUGIN_TRACKER_REJECT_SPAMCOUNT)) {
            $spam = TRUE;
        }
    }
    if ($spam) {
        honeypot_write();
        return array('msg' => 'cannot write', 'body' => '<p>prohibits editing</p>');
    }
    // TODO: Why here
    // Default
    $_post = array_merge($post, $_FILES);
    $_post['_date'] = $now;
    $_post['_page'] = $page;
    $_post['_name'] = $name;
    $_post['_real'] = $real;
    // $_post['_refer'] = $_post['refer'];
    // TODO: Why here => See BugTrack/662
    // Creating an empty page, before attaching files
    pkwk_touch_file(get_filename($page));
    $from = $to = array();
    $tracker_form =& new Tracker_form();
    if (!$tracker_form->init($base, $refer, $config)) {
        return array('msg' => 'Cannot write', 'body' => htmlspecialchars($tracker_form->error));
    }
    // Load $template
    $template_page = $tracker_form->config->page . '/' . PLUGIN_TRACKER_DEFAULT_PAGE;
    $template = plugin_tracker_get_source($template_page);
    if ($template === FALSE || empty($template)) {
        return array('msg' => 'Cannot write', 'body' => 'Page template (' . htmlspecialchars($template_page) . ') not found');
    }
    if (!$tracker_form->initFields(plugin_tracker_field_pickup(implode('', $template)))) {
        return array('msg' => 'Cannot write', 'body' => htmlspecialchars($tracker_form->error));
    }
    $fields = $tracker_form->fields;
    unset($tracker_form);
    foreach (array_keys($fields) as $field) {
        $from[] = '[' . $field . ']';
        $to[] = isset($_post[$field]) ? $fields[$field]->format_value($_post[$field]) : '';
        unset($fields[$field]);
    }
    // Repalace every [$field]s (found inside $template) to real values
    $subject = $escape = array();
    foreach (array_keys($template) as $linenum) {
        if (trim($template[$linenum]) == '') {
            continue;
        }
        // Escape some TextFormattingRules
        $letter = $template[$linenum][0];
        if ($letter == '|' || $letter == ':') {
            $escape['|'][$linenum] = $template[$linenum];
        } else {
            if ($letter == ',') {
                $escape[','][$linenum] = $template[$linenum];
            } else {
                // TODO: Escape "\n" except multiline-allowed fields
                $subject[$linenum] = $template[$linenum];
            }
        }
    }
    foreach (str_replace($from, $to, $subject) as $linenum => $line) {
        $template[$linenum] = $line;
    }
    if ($escape) {
        // Escape for some TextFormattingRules
        foreach (array_keys($escape) as $hint) {
            $to_e = plugin_tracker_escape($to, $hint);
            foreach (str_replace($from, $to_e, $escape[$hint]) as $linenum => $line) {
                $template[$linenum] = $line;
            }
        }
        unset($to_e);
    }
    unset($from, $to);
    // Write $template, without touch
    page_write($page, join('', $template));
    // Create proxy page
    if ($createProxy && ($proxyPage = isset($_post[$createProxy]) ? $_post[$createProxy] : '')) {
        page_write($proxyPage, '#include(' . $page . ',notitle)');
    }
    pkwk_headers_sent();
    header('Location: ' . get_page_location_uri($page));
    exit;
}
function plugin_weblog_category_maketag($prefix, $category)
{
    $base = $prefix . "/";
    $base_name = add_bracket($prefix);
    $cats = explode(",", $category);
    foreach ($cats as $cat) {
        if ($cat) {
            if ($base_name && !is_page($base_name)) {
                page_write($base_name, "#norelated\n***Category lists of ''" . substr(strip_bracket($base_name), 1) . "''\n#ls2(,pagename,notemplate,relatedcount)\n");
                page_write(add_bracket($base . "template"), "***Category: [[\$1]]\n|T:100% TC:0 SC:0 :TOP|SC:0 :TOP|c\n|#related|****Sub Categorys->\n#ls2(,pagename,notemplate,relatedcount)|\n");
                //}
            }
            $page_names = explode("/", $cat);
            if (count($page_names) > 1) {
                $_cat = "";
                $cats = array();
                foreach ($page_names as $page_name) {
                    $_cat .= $page_name;
                    $cats[] = "[[{$page_name}>{$base}{$_cat}]]";
                    $_cat .= "/";
                }
                $ret .= "[ " . join('/', $cats) . " ]";
            } else {
                $ret .= "[ [[{$cat}>{$base}{$cat}]] ]";
            }
        }
    }
    return "&weblog_field(__CATEGORY,{$prefix}){{$category}};" . $ret;
}
Esempio n. 25
0
function plugin_rename_proceed($pages, $files, $exists)
{
    global $now, $_rename_messages;
    if (plugin_rename_getvar('exist') == '') {
        foreach ($exists as $key => $arr) {
            unset($files[$key]);
        }
    }
    set_time_limit(0);
    foreach ($files as $page => $arr) {
        foreach ($arr as $old => $new) {
            if (isset($exists[$page][$old]) && $exists[$page][$old]) {
                unlink($new);
            }
            rename($old, $new);
            // linkデータベースを更新する BugTrack/327 arino
            links_update($old);
            links_update($new);
        }
    }
    $postdata = get_source(PLUGIN_RENAME_LOGPAGE);
    $postdata[] = '*' . $now . "\n";
    if (plugin_rename_getvar('method') == 'regex') {
        $postdata[] = '-' . $_rename_messages['msg_regex'] . "\n";
        $postdata[] = '--From:[[' . plugin_rename_getvar('src') . ']]' . "\n";
        $postdata[] = '--To:[[' . plugin_rename_getvar('dst') . ']]' . "\n";
    } else {
        $postdata[] = '-' . $_rename_messages['msg_page'] . "\n";
        $postdata[] = '--From:[[' . plugin_rename_getvar('refer') . ']]' . "\n";
        $postdata[] = '--To:[[' . plugin_rename_getvar('page') . ']]' . "\n";
    }
    if (!empty($exists)) {
        $postdata[] = "\n" . $_rename_messages['msg_result'] . "\n";
        foreach ($exists as $page => $arr) {
            $postdata[] = '-' . decode($page) . $_rename_messages['msg_arrow'] . decode($pages[$page]) . "\n";
            foreach ($arr as $ofile => $nfile) {
                $postdata[] = '--' . $ofile . $_rename_messages['msg_arrow'] . $nfile . "\n";
            }
        }
        $postdata[] = '----' . "\n";
    }
    foreach ($pages as $old => $new) {
        $postdata[] = '-' . decode($old) . $_rename_messages['msg_arrow'] . decode($new) . "\n";
    }
    // 更新の衝突はチェックしない。
    // ファイルの書き込み
    page_write(PLUGIN_RENAME_LOGPAGE, join('', $postdata));
    //リダイレクト
    $page = plugin_rename_getvar('page');
    if ($page == '') {
        $page = PLUGIN_RENAME_LOGPAGE;
    }
    pkwk_headers_sent();
    header('Location: ' . get_page_location_uri($page));
    exit;
}
Esempio n. 26
0
function plugin_comment_action()
{
    global $script, $vars, $now;
    $qm = get_qm();
    if (PKWK_READONLY) {
        die_message($qm->m['fmt_err_pkwk_readonly']);
    }
    if (!isset($vars['msg'])) {
        return array('msg' => '', 'body' => '');
    }
    // Do nothing
    $vars['msg'] = str_replace("\n", '', $vars['msg']);
    // Cut LFs
    $head = '';
    $match = array();
    if (preg_match('/^(-{1,2})-*\\s*(.*)/', $vars['msg'], $match)) {
        $head =& $match[1];
        $vars['msg'] =& $match[2];
    }
    if ($vars['msg'] == '') {
        return array('msg' => '', 'body' => '');
    }
    // Do nothing
    $comment = str_replace('$msg', $vars['msg'], PLUGIN_COMMENT_FORMAT_MSG);
    if (isset($vars['name']) || $vars['nodate'] != '1') {
        $_name = !isset($vars['name']) || $vars['name'] == '' ? $qm->m['plg_comment']['no_name'] : $vars['name'];
        $_name = $_name == '' ? '' : str_replace('$name', $_name, PLUGIN_COMMENT_FORMAT_NAME);
        $_now = $vars['nodate'] == '1' ? '' : str_replace('$now', $now, PLUGIN_COMMENT_FORMAT_NOW);
        $comment = str_replace("MSG", $comment, PLUGIN_COMMENT_FORMAT_STRING);
        $comment = str_replace("NAME", $_name, $comment);
        $comment = str_replace("NOW", $_now, $comment);
    }
    $comment = '-' . $head . ' ' . $comment;
    $postdata = '';
    $comment_no = 0;
    $above = isset($vars['above']) && $vars['above'] == '1';
    foreach (get_source($vars['refer']) as $line) {
        if (!$above) {
            $postdata .= $line;
        }
        if (preg_match('/^#comment/i', $line) && $comment_no++ == $vars['comment_no']) {
            if ($above) {
                $postdata = rtrim($postdata) . "\n" . $comment . "\n" . "\n";
                // Insert one blank line above #commment, to avoid indentation
            } else {
                $postdata = rtrim($postdata) . "\n" . $comment . "\n";
                // Insert one blank line below #commment
            }
        }
        if ($above) {
            $postdata .= $line;
        }
    }
    $title = $qm->m['fmt_title_updated'];
    $body = '';
    if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
        $title = $qm->m['plg_comment']['title_collided'];
        $body = $qm->m['plg_comment']['wng_collided'] . make_pagelink($vars['refer']);
    }
    page_write($vars['refer'], $postdata);
    $retvars['msg'] = $title;
    $retvars['body'] = $body;
    $vars['page'] = $vars['refer'];
    return $retvars;
}
 function fixed_anchor()
 {
     $pages = $this->get_pages();
     $done = array();
     foreach ($pages as $page) {
         $do = false;
         $lines = get_source($page);
         foreach ($lines as $i => $line) {
             // multiline plugin. refer lib/convert_html
             if (defined('PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK') && PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK === 0) {
                 $matches = array();
                 if ($multiline < 2) {
                     if (preg_match('/^#([^\\(\\{]+)(?:\\(([^\\r]*)\\))?(\\{*)/', $line, $matches)) {
                         $multiline = strlen($matches[3]);
                     }
                 } else {
                     if (preg_match('/^\\}{' . $multiline . '}$/', $line, $matches)) {
                         $multiline = 0;
                     }
                     continue;
                 }
             }
             if (preg_match($this->def_headline, $line, $matches)) {
                 $anchor = make_heading($line, FALSE);
                 if ($anchor === '') {
                     $do = true;
                     break;
                 }
             }
         }
         if ($do) {
             $source = join('', $lines);
             page_write($page, $source, true);
             // ->make_str_rules -> generate_fixed_heading_ancher_id
             // chown also
             $done[] = $page;
         }
     }
     $body = '<p>';
     $body .= '<b>Created fixed_heading anchors for followings:</b><br />';
     foreach ($done as $page) {
         $link = make_pagelink($page);
         $body .= $link . "<br />\n";
     }
     $body .= '</p>';
     return $body;
 }
Esempio n. 28
0
function plugin_article_action()
{
    global $script, $post, $vars, $cols, $rows, $now;
    global $_plugin_article_mailto;
    $qm = get_qm();
    if (PKWK_READONLY) {
        die_message($qm->m['fmt_err_pkwk_readonly']);
    }
    if ($post['msg'] == '') {
        return array('msg' => '', 'body' => '');
    }
    $name = $post['name'] == '' ? $qm->m['fmt_no_name'] : $post['name'];
    $name = $name == '' ? '' : str_replace('$name', $name, PLUGIN_ARTICLE_NAME_FORMAT);
    $subject = $post['subject'] == '' ? $qm->m['fmt_no_subject'] : $post['subject'];
    $subject = $subject == '' ? '' : str_replace('$subject', $subject, PLUGIN_ARTICLE_SUBJECT_FORMAT);
    $article = $subject . "\n" . $qm->replace('plg_article.post_format', $name, $now) . "\n\n";
    $msg = rtrim($post['msg']);
    if (PLUGIN_ARTICLE_AUTO_BR) {
        //改行の取り扱いはけっこう厄介。特にURLが絡んだときは…
        //コメント行、整形済み行には~をつけないように arino
        //		$msg = join("\n", preg_replace('/^(?!\/\/)(?!\s)(.*)$/', '$1~', explode("\n", $msg))); // 改行の直接入力対応のため
    }
    $article .= $msg . "\n" . $qm->m['plg_article']['note_comment'] . "\n" . "*** " . $qm->m['plg_article']['comment_header'];
    $article = wikiescape($article);
    if (PLUGIN_ARTICLE_COMMENT) {
        $article .= "\n\n" . '#comment2' . "\n";
    }
    $postdata = '';
    $postdata_old = get_source($post['refer']);
    $article_no = 0;
    foreach ($postdata_old as $line) {
        if (!PLUGIN_ARTICLE_INS) {
            $postdata .= $line;
        }
        if (preg_match('/^#article/i', $line)) {
            if ($article_no == $post['article_no'] && $post['msg'] != '') {
                $postdata .= $article . "\n";
            }
            ++$article_no;
        }
        if (PLUGIN_ARTICLE_INS) {
            $postdata .= $line;
        }
    }
    $postdata_input = $article . "\n";
    $body = '';
    if (md5(@join('', get_source($post['refer']))) != $post['digest']) {
        $title = $qm->m['fmt_title_collided'];
        $body = $qm->m['fmt_collided'] . "\n";
        $s_refer = htmlspecialchars($post['refer']);
        $s_digest = htmlspecialchars($post['digest']);
        $s_postdata = htmlspecialchars($postdata_input);
        $body .= <<<EOD
<form action="{$script}?cmd=preview" method="post">
 <div>
  <input type="hidden" name="refer" value="{$s_refer}" />
  <input type="hidden" name="digest" value="{$s_digest}" />
  <textarea name="msg" rows="{$rows}" cols="{$cols}" id="textarea">{$s_postdata}</textarea><br />
 </div>
</form>
EOD;
    } else {
        //		page_write($post['refer'], trim($postdata));
        if ($vars['authcode_master'] === $vars['authcode']) {
            page_write($vars['refer'], $postdata);
        } else {
            $vars['article_error'] = 'error!!!';
        }
        // 投稿内容のメール自動送信
        if (PLUGIN_ARTICLE_MAIL_AUTO_SEND) {
            $mailaddress = implode(',', $_plugin_article_mailto);
            $mailsubject = PLUGIN_ARTICLE_MAIL_SUBJECT_PREFIX . ' ' . str_replace('**', '', $subject);
            if ($post['name']) {
                $mailsubject .= '/' . $post['name'];
            }
            $mailsubject = mb_encode_mimeheader($mailsubject);
            $mailbody = $post['msg'];
            $mailbody .= "\n\n" . '---' . "\n";
            $mailbody .= $qm->replace('plg_article.sender_format', $post['name'], $now);
            $mailbody .= $qm->m['plg_article']['mail_page'] . $post['refer'] . "\n";
            $mailbody .= '  URL: ' . $script . '?' . rawurlencode($post['refer']) . "\n";
            $mailbody = mb_convert_encoding($mailbody, 'JIS');
            $mailaddheader = 'From: ' . PLUGIN_ARTICLE_MAIL_FROM;
            mail($mailaddress, $mailsubject, $mailbody, $mailaddheader);
        }
        $title = $qm->m['fmt_title_updated'];
    }
    $retvars['msg'] = $title;
    $retvars['body'] = $body;
    $post['page'] = $post['refer'];
    $vars['page'] = $post['refer'];
    return $retvars;
}
Esempio n. 29
0
 function write()
 {
     page_write($this->page, $this->toString());
 }
Esempio n. 30
0
function plugin_edit_write()
{
    global $vars, $trackback;
    global $_title_collided, $_msg_collided_auto, $_msg_collided, $_title_deleted;
    global $notimeupdate, $_msg_invalidpass, $do_update_diff_table;
    $page = isset($vars['page']) ? $vars['page'] : '';
    $add = isset($vars['add']) ? $vars['add'] : '';
    $digest = isset($vars['digest']) ? $vars['digest'] : '';
    $vars['msg'] = preg_replace(PLUGIN_EDIT_FREEZE_REGEX, '', $vars['msg']);
    $msg =& $vars['msg'];
    // Reference
    $retvars = array();
    // Collision Detection
    $oldpagesrc = join('', get_source($page));
    $oldpagemd5 = md5($oldpagesrc);
    if ($digest != $oldpagemd5) {
        $vars['digest'] = $oldpagemd5;
        // Reset
        $original = isset($vars['original']) ? $vars['original'] : '';
        list($postdata_input, $auto) = do_update_diff($oldpagesrc, $msg, $original);
        $retvars['msg'] = $_title_collided;
        $retvars['body'] = ($auto ? $_msg_collided_auto : $_msg_collided) . "\n";
        $retvars['body'] .= $do_update_diff_table;
        $retvars['body'] .= edit_form($page, $postdata_input, $oldpagemd5, FALSE);
        return $retvars;
    }
    // Action?
    if ($add) {
        // Add
        if (isset($vars['add_top']) && $vars['add_top']) {
            $postdata = $msg . "\n\n" . @join('', get_source($page));
        } else {
            $postdata = @join('', get_source($page)) . "\n\n" . $msg;
        }
    } else {
        // Edit or Remove
        $postdata =& $msg;
        // Reference
    }
    // NULL POSTING, OR removing existing page
    if ($postdata == '') {
        page_write($page, $postdata);
        $retvars['msg'] = $_title_deleted;
        $retvars['body'] = str_replace('$1', htmlspecialchars($page), $_title_deleted);
        if ($trackback) {
            tb_delete($page);
        }
        return $retvars;
    }
    // $notimeupdate: Checkbox 'Do not change timestamp'
    $notimestamp = isset($vars['notimestamp']) && $vars['notimestamp'] != '';
    if ($notimeupdate > 1 && $notimestamp && !pkwk_login($vars['pass'])) {
        // Enable only administrator & password error
        $retvars['body'] = '<p><strong>' . $_msg_invalidpass . '</strong></p>' . "\n";
        $retvars['body'] .= edit_form($page, $msg, $digest, FALSE);
        return $retvars;
    }
    page_write($page, $postdata, $notimeupdate != 0 && $notimestamp);
    pkwk_headers_sent();
    header('Location: ' . get_script_uri() . '?' . rawurlencode($page));
    exit;
}