summaryrefslogtreecommitdiff
path: root/lib/exe
diff options
context:
space:
mode:
Diffstat (limited to 'lib/exe')
-rw-r--r--lib/exe/ajax.php1
-rw-r--r--lib/exe/fetch.php130
-rw-r--r--lib/exe/indexer.php5
-rw-r--r--lib/exe/js.php4
-rw-r--r--lib/exe/xmlrpc.php47
5 files changed, 133 insertions, 54 deletions
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php
index 22de2f0f0..4c74709b8 100644
--- a/lib/exe/ajax.php
+++ b/lib/exe/ajax.php
@@ -298,6 +298,7 @@ function ajax_linkwiz(){
'listdirs' => true,
'pagesonly' => true,
'firsthead' => true,
+ 'sneakyacl' => $conf['sneaky_index'],
);
if($id) $opts['filematch'] = '^.*\/'.$id;
if($id) $opts['dirmatch'] = '^.*\/'.$id;
diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php
index 78de3188b..680fd9ae4 100644
--- a/lib/exe/fetch.php
+++ b/lib/exe/fetch.php
@@ -27,72 +27,59 @@
$DL = true;
}
- //media to local file
- if(preg_match('#^(https?)://#i',$MEDIA)){
- //check hash
- if(substr(md5(auth_cookiesalt().$MEDIA),0,6) != $_REQUEST['hash']){
- header("HTTP/1.0 412 Precondition Failed");
- print 'Precondition Failed';
- exit;
- }
- //handle external images
- if(strncmp($MIME,'image/',6) == 0) $FILE = media_get_from_URL($MEDIA,$EXT,$CACHE);
- if(!$FILE){
- //download failed - redirect to original URL
- header('Location: '.$MEDIA);
- exit;
+ // check for permissions, preconditions and cache external files
+ list($STATUS, $STATUSMESSAGE) = checkFileStatus($MEDIA, $FILE);
+
+ // prepare data for plugin events
+ $data = array('media' => $MEDIA,
+ 'file' => $FILE,
+ 'orig' => $FILE,
+ 'mime' => $MIME,
+ 'download' => $DL,
+ 'cache' => $CACHE,
+ 'ext' => $EXT,
+ 'width' => $WIDTH,
+ 'height' => $HEIGHT,
+ 'status' => $STATUS,
+ 'statusmessage' => $STATUSMESSAGE,
+ );
+
+ // handle the file status
+ $evt = new Doku_Event('FETCH_MEDIA_STATUS', $data);
+ if ( $evt->advise_before() ) {
+ // redirects
+ if($data['status'] > 300 && $data['status'] <= 304){
+ send_redirect($data['statusmessage']);
}
- }else{
- $MEDIA = cleanID($MEDIA);
- if(empty($MEDIA)){
- header("HTTP/1.0 400 Bad Request");
- print 'Bad request';
- exit;
+ // send any non 200 status
+ if($data['status'] != 200){
+ header('HTTP/1.0 ' . $data['status'] . ' ' . $data['statusmessage']);
}
-
- //check permissions (namespace only)
- if(auth_quickaclcheck(getNS($MEDIA).':X') < AUTH_READ){
- header("HTTP/1.0 401 Unauthorized");
- //fixme add some image for imagefiles
- print 'Unauthorized';
+ // die on errors
+ if($data['status'] > 203){
+ print $data['statusmessage'];
exit;
}
- $FILE = mediaFN($MEDIA);
}
-
- //check file existance
- if(!@file_exists($FILE)){
- header("HTTP/1.0 404 Not Found");
- //FIXME add some default broken image
- print 'Not Found';
- exit;
- }
-
- $ORIG = $FILE;
+ $evt->advise_after();
+ unset($evt);
//handle image resizing/cropping
if((substr($MIME,0,5) == 'image') && $WIDTH){
if($HEIGHT){
- $FILE = media_crop_image($FILE,$EXT,$WIDTH,$HEIGHT);
+ $data['file'] = $FILE = media_crop_image($data['file'],$EXT,$WIDTH,$HEIGHT);
}else{
- $FILE = media_resize_image($FILE,$EXT,$WIDTH,$HEIGHT);
+ $data['file'] = $FILE = media_resize_image($data['file'],$EXT,$WIDTH,$HEIGHT);
}
}
// finally send the file to the client
- $data = array('file' => $FILE,
- 'mime' => $MIME,
- 'download' => $DL,
- 'cache' => $CACHE,
- 'orig' => $ORIG,
- 'ext' => $EXT,
- 'width' => $WIDTH,
- 'height' => $HEIGHT);
-
$evt = new Doku_Event('MEDIA_SENDFILE', $data);
if ($evt->advise_before()) {
sendFile($data['file'],$data['mime'],$data['download'],$data['cache']);
}
+ // Do something after the download finished.
+ $evt->advise_after();
/* ------------------------------------------------------------------------ */
@@ -150,6 +137,53 @@ function sendFile($file,$mime,$dl,$cache){
}
/**
+ * Check for media for preconditions and return correct status code
+ *
+ * READ: MEDIA, MIME, EXT, CACHE
+ * WRITE: MEDIA, FILE, array( STATUS, STATUSMESSAGE )
+ *
+ * @author Gerry Weissbach <gerry.w@gammaproduction.de>
+ * @param $media reference to the media id
+ * @param $file reference to the file variable
+ * @returns array(STATUS, STATUSMESSAGE)
+ */
+function checkFileStatus(&$media, &$file) {
+ global $MIME, $EXT, $CACHE;
+
+ //media to local file
+ if(preg_match('#^(https?)://#i',$media)){
+ //check hash
+ if(substr(md5(auth_cookiesalt().$media),0,6) != $_REQUEST['hash']){
+ return array( 412, 'Precondition Failed');
+ }
+ //handle external images
+ if(strncmp($MIME,'image/',6) == 0) $file = media_get_from_URL($media,$EXT,$CACHE);
+ if(!$file){
+ //download failed - redirect to original URL
+ return array( 302, $media );
+ }
+ }else{
+ $media = cleanID($media);
+ if(empty($media)){
+ return array( 400, 'Bad request' );
+ }
+
+ //check permissions (namespace only)
+ if(auth_quickaclcheck(getNS($media).':X') < AUTH_READ){
+ return array( 403, 'Forbidden' );
+ }
+ $file = mediaFN($media);
+ }
+
+ //check file existance
+ if(!@file_exists($file)){
+ return array( 404, 'Not Found' );
+ }
+
+ return array(200, null);
+}
+
+/**
* Returns the wanted cachetime in seconds
*
* Resolves named constants
diff --git a/lib/exe/indexer.php b/lib/exe/indexer.php
index 828834c86..eb5670005 100644
--- a/lib/exe/indexer.php
+++ b/lib/exe/indexer.php
@@ -356,8 +356,9 @@ function sendDigest() {
foreach($users as $data) {
list($user, $style, $lastupdate) = $data;
$lastupdate = (int) $lastupdate;
- if ($lastupdate + $conf['subscribe_interval'] > time()) {
- // Less than a day passed since last update.
+ if ($lastupdate + $conf['subscribe_time'] > time()) {
+ // Less than the configured time period passed since last
+ // update.
continue;
}
diff --git a/lib/exe/js.php b/lib/exe/js.php
index 044342187..0eb43b246 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -108,7 +108,9 @@ function js_out(){
js_runonstart("initSizeCtl('size__ctl','wiki__text')");
js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)");
js_runonstart("initChangeCheck('".js_escape($lang['notsavedyet'])."')");
- js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].")");
+ if($conf['locktime'] != 0){
+ js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].")");
+ }
js_runonstart('scrollToMarker()');
js_runonstart('focusMarker()');
diff --git a/lib/exe/xmlrpc.php b/lib/exe/xmlrpc.php
index fb6b79cf3..670ab5d7e 100644
--- a/lib/exe/xmlrpc.php
+++ b/lib/exe/xmlrpc.php
@@ -7,7 +7,7 @@ if(isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
/**
* Increased whenever the API is changed
*/
-define('DOKU_XMLRPC_API_VERSION',2);
+define('DOKU_XMLRPC_API_VERSION',3);
require_once(DOKU_INC.'inc/init.php');
session_write_close(); //close session
@@ -114,6 +114,13 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer {
);
$this->addCallback(
+ 'dokuwiki.search',
+ 'this:search',
+ array('struct','string'),
+ 'Perform a fulltext search and return a list of matching pages'
+ );
+
+ $this->addCallback(
'dokuwiki.getTime',
'time',
array('int'),
@@ -278,8 +285,7 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer {
}
$text = rawWiki($id,$rev);
if(!$text) {
- $data = array($id);
- return trigger_event('HTML_PAGE_FROMTEMPLATE',$data,'pageTemplate',true);
+ return pageTemplate($id);
} else {
return $text;
}
@@ -379,6 +385,41 @@ class dokuwiki_xmlrpc_server extends IXR_IntrospectionServer {
}
/**
+ * List all pages in the given namespace (and below)
+ */
+ function search($query){
+ require_once(DOKU_INC.'inc/fulltext.php');
+
+ $regex = '';
+ $data = ft_pageSearch($query,$regex);
+ $pages = array();
+
+ // prepare additional data
+ $idx = 0;
+ foreach($data as $id => $score){
+ $file = wikiFN($id);
+
+ if($idx < FT_SNIPPET_NUMBER){
+ $snippet = ft_snippet($id,$regex);
+ $idx++;
+ }else{
+ $snippet = '';
+ }
+
+ $pages[] = array(
+ 'id' => $id,
+ 'score' => $score,
+ 'rev' => filemtime($file),
+ 'mtime' => filemtime($file),
+ 'size' => filesize($file),
+ 'snippet' => $snippet,
+ );
+ }
+ return $data;
+ }
+
+
+ /**
* List all media files.
*
* Available options are 'recursive' for also including the subnamespaces