3 * AJAX call handler for tagindex admin plugin
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Gina Häußge, Michael Klier <dokuwiki@chimeric.de>
7 * @author Andreas Gohr <andi@splitbrain.org>
10 //fix for Opera XMLHttpRequests
11 if(!count($_POST) && $HTTP_RAW_POST_DATA) {
12 parse_str($HTTP_RAW_POST_DATA, $_POST);
15 if (!defined('DOKU_INC'))
16 define('DOKU_INC', realpath(dirname(__FILE__
) . '/../../../') . '/');
21 require_once(DOKU_INC
.'inc/init.php');
22 require_once(DOKU_INC
.'inc/common.php');
23 require_once(DOKU_INC
.'inc/pageutils.php');
24 require_once(DOKU_INC
.'inc/auth.php');
25 require_once(DOKU_INC
.'inc/search.php');
26 require_once(DOKU_INC
.'inc/indexer.php');
29 session_write_close();
31 header('Content-Type: text/plain; charset=utf-8');
33 if (!auth_isadmin()) {
34 die('for admins only');
37 //clear all index files
38 if (@file_exists
($conf['indexdir'].'/page.idx')) { // new word length based index
39 $tag_idx = $conf['indexdir'].'/topic.idx';
41 $tag_idx = $conf['cachedir'].'/topic.idx';
44 $tag_helper =& plugin_load('helper', 'tag');
46 //call the requested function
47 $call = 'ajax_'.$_POST['call'];
48 if(function_exists($call)) {
51 print "The called function '".htmlspecialchars($call)."' does not exist!";
57 * @author Andreas Gohr <andi@splitbrain.org>
59 function ajax_pagelist() {
63 search($pages, $conf['datadir'], 'search_allpages', array());
65 foreach($pages as $page) {
66 print $page['id']."\n";
71 * Clear all index files
73 function ajax_clearindex() {
78 @ignore_user_abort
(true);
80 // try to aquire a lock
81 $lock = $conf['lockdir'].'/_tagindexer.lock';
82 while(!@mkdir
($lock)) {
83 if(time()-@filemtime
($lock) > 60*5) {
84 // looks like a stale lock - remove it
87 print 'tagindexer is locked.';
93 io_saveFile($tag_idx,'');
102 * Index the given page's tags
104 function ajax_indexpage() {
108 if(!$_POST['page']) {
114 @ignore_user_abort
(true);
116 // try to aquire a lock
117 $lock = $conf['lockdir'].'/_tagindexer.lock';
118 while(!@mkdir
($lock)) {
119 if(time()-@filemtime
($lock) > 60*5) {
120 // looks like a stale lock - remove it
123 print 'tagindexer is locked.';
131 'id' => $_POST['page'],
134 $tag_helper->_generateTagData($page);
141 // vim:ts=4:sw=4:et:enc=utf-8: