diff --git a/_test/tests/inc/common_basicinfo.test.php b/_test/tests/inc/common_basicinfo.test.php new file mode 100644 index 0000000000000000000000000000000000000000..0369474c96a499f353bec4f1f731a33192cf48b0 --- /dev/null +++ b/_test/tests/inc/common_basicinfo.test.php @@ -0,0 +1,64 @@ +<?php + +class common_infofunctions_test extends DokuWikiTest { + + function setup(){ + parent::setup(); + + global $USERINFO; + $USERINFO = array( + 'pass' => '179ad45c6ce2cb97cf1029e212046e81', + 'name' => 'Arthur Dent', + 'mail' => 'arthur@example.com', + 'grps' => array ('admin','user'), + ); + $_SERVER['REMOTE_USER'] = 'testuser'; + $_SERVER['REMOTE_ADDR'] = '1.2.3.4'; + } + + function _get_info() { + global $USERINFO; + $info = array ( + 'isadmin' => true, + 'ismanager' => true, + 'userinfo' => $USERINFO, + 'perm' => 255, + 'namespace' => false, + 'ismobile' => false, + 'client' => 'testuser', + ); + + return $info; + } + + /** + * Its important to have the correct set of keys. + * Other functions provide the values + */ + function test_basicinfo(){ + // test with REMOTE_USER set and the user an admin user + $info = $this->_get_info(); + $this->assertEquals(basicinfo($ID,true),$info); + + // with $httpclient parameter set to false + unset($info['ismobile']); + $this->assertEquals(basicinfo($ID,false),$info); + + // with anonymous user + unset($_SERVER['REMOTE_USER']); + global $USERINFO; $USERINFO = array(); + + $info = array( + 'isadmin' => false, + 'ismanager' => false, + 'perm' => 8, + 'namespace' => false, + 'ismobile' => false, + 'client' => '1.2.3.4', + ); + $this->assertEquals(basicinfo($ID,true),$info); + } + +} + +//Setup VIM: ex: et ts=4 : diff --git a/_test/tests/inc/common_mediainfo.test.php b/_test/tests/inc/common_mediainfo.test.php new file mode 100644 index 0000000000000000000000000000000000000000..0e67fbcd909f46a62f18f1c76f7c8fa50c207a17 --- /dev/null +++ b/_test/tests/inc/common_mediainfo.test.php @@ -0,0 +1,49 @@ +<?php + +class common_basicinfo_test extends DokuWikiTest { + + function setup(){ + parent::setup(); + + global $USERINFO; + $USERINFO = array( + 'pass' => '179ad45c6ce2cb97cf1029e212046e81', + 'name' => 'Arthur Dent', + 'mail' => 'arthur@example.com', + 'grps' => array ('admin','user'), + ); + $_SERVER['REMOTE_USER'] = 'testuser'; + $_SERVER['REMOTE_ADDR'] = '1.2.3.4'; + } + + function _get_info() { + global $USERINFO; + $info = array ( + 'isadmin' => true, + 'ismanager' => true, + 'userinfo' => $USERINFO, + 'perm' => 255, + 'namespace' => false, + 'ismobile' => false, + 'client' => 'testuser', + ); + + return $info; + } + + /** + * We're interested in the extra keys for $INFO when its a media request + */ + function test_mediainfo(){ + global $NS, $IMG; + $NS = ''; + $IMG = 'testimage.png'; + + $info = $this->_get_info(); + $info['image'] = 'testimage.png'; + + $this->assertEquals(mediainfo(),$info); + } +} + +//Setup VIM: ex: et ts=4 : diff --git a/inc/common.php b/inc/common.php index 760a9f6dc7febab2f9521646b9c356a75594b74c..b292fb75ee0db954f8101b3bb2f65c30c1067bff 100644 --- a/inc/common.php +++ b/inc/common.php @@ -86,32 +86,20 @@ function formSecurityToken($print = true) { } /** - * Return info about the current document as associative - * array. + * Determine basic information for a request of $id * * @author Andreas Gohr <andi@splitbrain.org> + * @author Chris Smith <chris@jalakai.co.uk> */ -function pageinfo() { - global $ID; - global $REV; - global $RANGE; +function basicinfo($id, $htmlClient=true){ global $USERINFO; - global $lang; - - // include ID & REV not redundant, as some parts of DokuWiki may temporarily change $ID, e.g. p_wiki_xhtml - // FIXME ... perhaps it would be better to ensure the temporary changes weren't necessary - $info['id'] = $ID; - $info['rev'] = $REV; // set info about manager/admin status. $info['isadmin'] = false; $info['ismanager'] = false; if(isset($_SERVER['REMOTE_USER'])) { - $sub = new Subscription(); - $info['userinfo'] = $USERINFO; - $info['perm'] = auth_quickaclcheck($ID); - $info['subscribed'] = $sub->user_subscription(); + $info['perm'] = auth_quickaclcheck($id); $info['client'] = $_SERVER['REMOTE_USER']; if($info['perm'] == AUTH_ADMIN) { @@ -127,12 +115,46 @@ function pageinfo() { } } else { - $info['perm'] = auth_aclcheck($ID, '', null); - $info['subscribed'] = false; + $info['perm'] = auth_aclcheck($id, '', null); $info['client'] = clientIP(true); } - $info['namespace'] = getNS($ID); + $info['namespace'] = getNS($id); + + // mobile detection + if ($htmlClient) { + $info['ismobile'] = clientismobile(); + } + + return $info; + } + +/** + * Return info about the current document as associative + * array. + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function pageinfo() { + global $ID; + global $REV; + global $RANGE; + global $lang; + + $info = basicinfo($ID); + + // include ID & REV not redundant, as some parts of DokuWiki may temporarily change $ID, e.g. p_wiki_xhtml + // FIXME ... perhaps it would be better to ensure the temporary changes weren't necessary + $info['id'] = $ID; + $info['rev'] = $REV; + + if(isset($_SERVER['REMOTE_USER'])) { + $sub = new Subscription(); + $info['subscribed'] = $sub->user_subscription(); + } else { + $info['subscribed'] = false; + } + $info['locked'] = checklock($ID); $info['filepath'] = fullpath(wikiFN($ID)); $info['exists'] = @file_exists($info['filepath']); @@ -210,8 +232,18 @@ function pageinfo() { } } - // mobile detection - $info['ismobile'] = clientismobile(); + return $info; +} + +/** + * Return information about the current media item as an associative array. + */ +function mediainfo(){ + global $NS; + global $IMG; + + $info = basicinfo("$NS:*"); + $info['image'] = $IMG; return $info; } diff --git a/lib/exe/detail.php b/lib/exe/detail.php index db635c016180bbb8f31d997f57967b190197db18..7008b126f68801939c3950132deeb30b4b3c039b 100644 --- a/lib/exe/detail.php +++ b/lib/exe/detail.php @@ -2,13 +2,18 @@ if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/../../'); define('DOKU_MEDIADETAIL',1); require_once(DOKU_INC.'inc/init.php'); -trigger_event('DETAIL_STARTED', $tmp=array()); -//close session -session_write_close(); $IMG = getID('media'); $ID = cleanID($INPUT->str('id')); +// this makes some general infos available as well as the info about the +// "parent" page +$INFO = array_merge(pageinfo(),mediainfo()); +trigger_event('DETAIL_STARTED', $tmp=array()); + +//close session +session_write_close(); + if($conf['allowdebug'] && $INPUT->has('debug')){ print '<pre>'; foreach(explode(' ','basedir userewrite baseurl useslash') as $x){ @@ -39,10 +44,6 @@ if($AUTH >= AUTH_READ){ $ERROR = p_locale_xhtml('denied'); } -// this makes some general infos available as well as the info about the -// "parent" page -$INFO = pageinfo(); - //start output and load template header('Content-Type: text/html; charset=utf-8'); include(template('detail.php')); diff --git a/lib/exe/mediamanager.php b/lib/exe/mediamanager.php index 53d438321288c8d1d1bb7d5e0e8fc5c882ee1e8d..66e5ddc829918afad8f46d0bf856422356ff81c7 100644 --- a/lib/exe/mediamanager.php +++ b/lib/exe/mediamanager.php @@ -7,15 +7,12 @@ require_once(DOKU_INC.'inc/init.php'); - trigger_event('MEDIAMANAGER_STARTED',$tmp=array()); - session_write_close(); //close session - global $INPUT; // handle passed message if($INPUT->str('msg1')) msg(hsc($INPUT->str('msg1')),1); if($INPUT->str('err')) msg(hsc($INPUT->str('err')),-1); - + global $DEL; // get namespace to display (either direct or from deletion order) if($INPUT->str('delete')){ $DEL = cleanID($INPUT->str('delete')); @@ -29,10 +26,15 @@ $NS = getNS($IMG); }else{ $NS = cleanID($INPUT->str('ns')); + $IMG = null; } - // check auth - $AUTH = auth_quickaclcheck("$NS:*"); + global $INFO; + $INFO = !empty($INFO) ? array_merge($INFO, mediainfo()) : mediainfo(); + $AUTH = $INFO['perm']; // shortcut for historical reasons + + trigger_event('MEDIAMANAGER_STARTED',$tmp=array()); + session_write_close(); //close session // do not display the manager if user does not have read access if($AUTH < AUTH_READ && !$fullscreen) { @@ -52,7 +54,7 @@ exit; } - // give info on PHP catched upload errors + // give info on PHP caught upload errors if($_FILES['upload']['error']){ switch($_FILES['upload']['error']){ case 1: