Example #1
0
function plugin_read_action()
{
    global $vars, $_title_invalidwn, $_msg_invalidiwn;
    $page = isset($vars['page']) ? $vars['page'] : '';
    if (is_page($page)) {
        // ページを表示
        check_readable($page, true, true);
        header_lastmod($page);
        return array('msg' => '', 'body' => '');
        // } else if (! PKWK_SAFE_MODE && is_interwiki($page)) {
    } else {
        if (!auth::check_role('safemode') && is_interwiki($page)) {
            return do_plugin_action('interwiki');
            // InterWikiNameを処理
        } else {
            if (is_pagename($page)) {
                $realpages = get_autoaliases($page);
                if (count($realpages) == 1) {
                    $realpage = $realpages[0];
                    if (is_page($realpage)) {
                        header('HTTP/1.0 301 Moved Permanently');
                        header('Location: ' . get_page_location_uri($realpage));
                        return;
                    } elseif (is_url($realpage)) {
                        header('HTTP/1.0 301 Moved Permanently');
                        header('Location: ' . $realpage);
                        return;
                    } elseif (is_interwiki($realpage)) {
                        header('HTTP/1.0 301 Moved Permanently');
                        $vars['page'] = $realpage;
                        return do_plugin_action('interwiki');
                        // header('Location');
                    } else {
                        // 存在しない場合、直接編集フォームに飛ばす // To avoid infinite loop
                        header('Location: ' . get_location_uri('edit', $realpage));
                        return;
                    }
                } elseif (count($realpages) >= 2) {
                    $body = '<p>';
                    $body .= _('This pagename is an alias to') . '<br />';
                    $link = '';
                    foreach ($realpages as $realpage) {
                        $link .= '[[' . $realpage . '>' . $realpage . ']]&br;';
                    }
                    $body .= make_link($link);
                    $body .= '</p>';
                    return array('msg' => _('Redirect'), 'body' => $body);
                }
                $vars['cmd'] = 'edit';
                return do_plugin_action('edit');
                // 存在しないので、編集フォームを表示
            } else {
                // 無効なページ名
                return array('msg' => $_title_invalidwn, 'body' => str_replace('$1', htmlspecialchars($page), str_replace('$2', 'WikiName', $_msg_invalidiwn)));
            }
        }
    }
}
Example #2
0
function page_write($page, $postdata, $notimestamp = FALSE)
{
    global $trackback, $autoalias, $aliaspage;
    global $autoglossary, $glossarypage;
    global $use_spam_check;
    // if (PKWK_READONLY) return; // Do nothing
    if (auth::check_role('readonly')) {
        return;
    }
    // Do nothing
    if (is_page($page)) {
        $oldpostdata = get_source($page, TRUE, TRUE);
    } else {
        if (auth::is_check_role(PKWK_CREATE_PAGE)) {
            die_message(_('PKWK_CREATE_PAGE prohibits editing'));
        }
        $oldpostdata = '';
    }
    $postdata = make_str_rules($postdata);
    // Create and write diff
    $diffdata = do_diff($oldpostdata, $postdata);
    $role_adm_contents = auth::check_role('role_adm_contents');
    $links = array();
    if ($trackback > 1 || $role_adm_contents && $use_spam_check['page_contents']) {
        $links = get_this_time_links($postdata, $diffdata);
    }
    // Blocking SPAM
    if ($role_adm_contents) {
        if ($use_spam_check['page_remote_addr'] && SpamCheck($_SERVER['REMOTE_ADDR'], 'ip')) {
            die_message('Writing was limited by IPBL (Blocking SPAM).');
        }
        if ($use_spam_check['page_contents'] && SpamCheck($links)) {
            die_message('Writing was limited by DNSBL (Blocking SPAM).');
        }
        if ($use_spam_check['page_write_proxy'] && is_proxy()) {
            die_message('Writing was limited by PROXY (Blocking SPAM).');
        }
    }
    // Logging postdata
    postdata_write();
    // Create diff text
    file_write(DIFF_DIR, $page, $diffdata);
    // Create backup
    make_backup($page, $postdata == '');
    // Is $postdata null?
    // Create wiki text
    file_write(DATA_DIR, $page, $postdata, $notimestamp);
    if (function_exists('senna_update')) {
        senna_update($page, $oldpostdata, $postdata);
    }
    if ($trackback > 1) {
        // TrackBack Ping
        tb_send($page, $links);
    }
    unset($oldpostdata, $diffdata, $links);
    links_update($page);
    // Update autoalias.dat (AutoAliasName)
    if ($autoalias && $page == $aliaspage) {
        $aliases = get_autoaliases();
        if (empty($aliases)) {
            // Remove
            @unlink(CACHE_DIR . PKWK_AUTOALIAS_REGEX_CACHE);
        } else {
            // Create or Update
            autolink_pattern_write(CACHE_DIR . PKWK_AUTOALIAS_REGEX_CACHE, get_autolink_pattern(array_keys($aliases), $autoalias));
        }
    }
    // Update glossary.dat (AutoGlossary)
    if ($autoglossary && $page == $glossarypage) {
        $words = get_autoglossaries();
        if (empty($words)) {
            // Remove
            @unlink(CACHE_DIR . PKWK_GLOSSARY_REGEX_CACHE);
        } else {
            // Create or Update
            autolink_pattern_write(CACHE_DIR . PKWK_GLOSSARY_REGEX_CACHE, get_glossary_pattern(array_keys($words), $autoglossary));
        }
    }
    log_write('update', $page);
}
Example #3
0
function links_init()
{
    global $whatsnew;
    // if (PKWK_READONLY) return; // Do nothing
    if (auth::check_role('readonly')) {
        return;
    }
    // Do nothing
    if (ini_get('safe_mode') == '0') {
        set_time_limit(0);
    }
    // Init database
    foreach (get_existfiles(CACHE_DIR, '.ref') as $cache) {
        unlink($cache);
    }
    foreach (get_existfiles(CACHE_DIR, '.rel') as $cache) {
        unlink($cache);
    }
    $ref = array();
    // 参照元
    foreach (get_existpages() as $page) {
        if ($page == $whatsnew) {
            continue;
        }
        $rel = array();
        // 参照先
        $links = links_get_objects($page);
        foreach ($links as $_obj) {
            if (!isset($_obj->type) || $_obj->type != 'pagename' || $_obj->name == $page || $_obj->name == '') {
                continue;
            }
            if (is_a($_obj, 'Link_autoalias')) {
                $_aliases = get_autoaliases($_obj->name);
                foreach ($_aliases as $_alias) {
                    if (is_pagename($_alias)) {
                        $rel[] = $_alias;
                    }
                }
            } else {
                $rel[] = $_obj->name;
            }
        }
        $rel = array_unique($rel);
        foreach ($rel as $_name) {
            if (!isset($ref[$_name][$page])) {
                $ref[$_name][$page] = 1;
            }
            if (!is_a($_obj, 'Link_autolink')) {
                $ref[$_name][$page] = 0;
            }
        }
        if (!empty($rel)) {
            $fp = fopen(CACHE_DIR . encode($page) . '.rel', 'w') or die_message('cannot write ' . htmlspecialchars(CACHE_DIR . encode($page) . '.rel'));
            fputs($fp, join("\t", $rel));
            fclose($fp);
        }
    }
    foreach ($ref as $page => $arr) {
        $fp = fopen(CACHE_DIR . encode($page) . '.ref', 'w') or die_message('cannot write ' . htmlspecialchars(CACHE_DIR . encode($page) . '.ref'));
        foreach ($arr as $ref_page => $ref_auto) {
            fputs($fp, $ref_page . "\t" . $ref_auto . "\n");
        }
        fclose($fp);
    }
}
Example #4
0
 function toString()
 {
     $this->aliases = get_autoaliases($this->name);
     if (!empty($this->aliases)) {
         $link = '[[' . $this->name . ']]';
         return make_link($link);
     }
     return '';
 }
 /**
  * Get dump url
  *
  * @param string $page pagename
  * @param string $source source path used to compute relative path
  * @return string 
  */
 function get_dump_url($page, $source)
 {
     if (is_callable('get_autoaliases')) {
         // support lower versions
         $real = get_autoaliases($page);
         if (is_array($real)) {
             // plus
             if (count($real) === 1) {
                 $page = $real[0];
             } elseif (count($real) >= 2) {
                 // can not replace url to html address
                 return null;
             }
         } elseif (is_string($real)) {
             // org or old plus
             if ($real !== '') {
                 $page = $real;
             }
         }
     }
     if ($page == $GLOBALS['defaultpage']) {
         $url = $this->CONF['TOPURL'];
     } else {
         $filename = $this->get_dump_filename($page);
         switch ($this->CONF['href_urlstyle']) {
             case 'absolute':
                 $url = $this->CONF['TOPURL'] . $filename;
                 break;
             case 'relative':
                 $url = $filename;
                 $url = get_relative_path($source, $url);
             default:
                 break;
         }
     }
     return $url;
 }