From e68c51bac31594213f669a7700b21ac8b87df959 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Tue, 23 Aug 2005 18:34:50 +0200
Subject: [PATCH] added missing indexer file

darcs-hash:20050823163450-7ad00-5ed5b87ee1898281090bb3170498866dbc18cb24.gz
---
 inc/template.php    |  3 ++-
 lib/exe/indexer.php | 55 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 lib/exe/indexer.php

diff --git a/inc/template.php b/inc/template.php
index a17d16f56..be1ffd6d4 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -877,7 +877,8 @@ function tpl_img($maxwidth=900,$maxheight=700){
 function tpl_indexerWebBug(){
   global $ID;
   $p = array();
-  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.urlencode($ID);
+  $p['src']    = DOKU_BASE.'lib/exe/indexer.php?id='.urlencode($ID).
+                 '&'.time();
   $p['width']  = 1;
   $p['height'] = 1;
   $p['alt']    = '';
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php
new file mode 100644
index 000000000..fe9562d08
--- /dev/null
+++ b/lib/exe/indexer.php
@@ -0,0 +1,55 @@
+<?php
+/**
+ * DokuWiki indexer
+ *
+ * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
+ * @author     Andreas Gohr <andi@splitbrain.org>
+ */
+
+if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
+require_once(DOKU_INC.'inc/init.php');
+require_once(DOKU_INC.'inc/indexer.php');
+//close session
+session_write_close();
+
+
+$ID = cleanID($_REQUEST['id']);
+if(!$ID) sendGIF();
+
+// check if indexing needed
+$last = @filemtime(metaFN($ID,'.indexed'));
+if($last > @filemtime(wikiFN($ID))) sendGIF();
+
+// keep running
+@ignore_user_abort(true);
+
+// try to aquire a lock
+$lock = $conf['lockdir'].'/_indexer.lock';
+while(!@mkdir($lock)){
+    if(time()-@filemtime($lock) > 60*5){
+        // looks like a stale lock - remove it
+        @rmdir($lock);
+    }else{
+        sendGIF();
+    }
+}
+
+// do the work
+idx_addPage($ID);
+
+// we're finished
+io_saveFile(metaFN($id,'.indexed'),'');
+@rmdir($lock);
+sendGIF();
+
+/**
+ * Just send a 1x1 pixel blank gif to the browser and exit
+ */
+function sendGIF(){
+    header('Content-Type: image/gif');
+    print base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7');
+    exit;
+}
+
+//Setup VIM: ex: et ts=4 enc=utf-8 :
+?>
-- 
GitLab