summaryrefslogtreecommitdiff
path: root/inc/pageutils.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/pageutils.php')
-rw-r--r--inc/pageutils.php111
1 files changed, 100 insertions, 11 deletions
diff --git a/inc/pageutils.php b/inc/pageutils.php
index 8474c5697..49c00d36f 100644
--- a/inc/pageutils.php
+++ b/inc/pageutils.php
@@ -17,6 +17,10 @@
* If the second parameter is true (default) the ID is cleaned.
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $param the $_REQUEST variable name, default 'id'
+ * @param bool $clean if true, ID is cleaned
+ * @return mixed|string
*/
function getID($param='id',$clean=true){
/** @var Input $INPUT */
@@ -146,6 +150,9 @@ function cleanID($raw_id,$ascii=false){
* Return namespacepart of a wiki ID
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $id
+ * @return string|bool the namespace part or false if the given ID has no namespace (root)
*/
function getNS($id){
$pos = strrpos((string)$id,':');
@@ -159,6 +166,9 @@ function getNS($id){
* Returns the ID without the namespace
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $id
+ * @return string
*/
function noNS($id) {
$pos = strrpos($id, ':');
@@ -173,6 +183,9 @@ function noNS($id) {
* Returns the current namespace
*
* @author Nathan Fritz <fritzn@crown.edu>
+ *
+ * @param string $id
+ * @return string
*/
function curNS($id) {
return noNS(getNS($id));
@@ -182,6 +195,9 @@ function curNS($id) {
* Returns the ID without the namespace or current namespace for 'start' pages
*
* @author Nathan Fritz <fritzn@crown.edu>
+ *
+ * @param string $id
+ * @return string
*/
function noNSorNS($id) {
global $conf;
@@ -202,6 +218,7 @@ function noNSorNS($id) {
* @param string $title The headline title
* @param array|bool $check Existing IDs (title => number)
* @return string the title
+ *
* @author Andreas Gohr <andi@splitbrain.org>
*/
function sectionID($title,&$check) {
@@ -232,8 +249,19 @@ function sectionID($title,&$check) {
* parameters as for wikiFN
*
* @author Chris Smith <chris@jalakai.co.uk>
+ *
+ * @param string $id page id
+ * @param string|int $rev empty or revision timestamp
+ * @param bool $clean flag indicating that $id should be cleaned (see wikiFN as well)
+ * @return bool exists?
*/
-function page_exists($id,$rev='',$clean=true) {
+function page_exists($id,$rev='',$clean=true, $date_at=false) {
+ if($rev !== '' && $date_at) {
+ $pagelog = new PageChangeLog($id);
+ $pagelog_rev = $pagelog->getLastRevisionAt($rev);
+ if($pagelog_rev !== false)
+ $rev = $pagelog_rev;
+ }
return @file_exists(wikiFN($id,$rev,$clean));
}
@@ -290,6 +318,9 @@ function wikiFN($raw_id,$rev='',$clean=true){
* Returns the full path to the file for locking the page while editing.
*
* @author Ben Coburn <btcoburn@silicodon.net>
+ *
+ * @param string $id page id
+ * @return string full path
*/
function wikiLockFN($id) {
global $conf;
@@ -301,6 +332,10 @@ function wikiLockFN($id) {
* returns the full path to the meta file specified by ID and extension
*
* @author Steven Danz <steven-danz@kc.rr.com>
+ *
+ * @param string $id page id
+ * @param string $ext file extension
+ * @return string full path
*/
function metaFN($id,$ext){
global $conf;
@@ -314,6 +349,10 @@ function metaFN($id,$ext){
* returns the full path to the media's meta file specified by ID and extension
*
* @author Kate Arzamastseva <pshns@ukr.net>
+ *
+ * @param string $id media id
+ * @param string $ext extension of media
+ * @return string
*/
function mediaMetaFN($id,$ext){
global $conf;
@@ -328,6 +367,9 @@ function mediaMetaFN($id,$ext){
*
* @author Esther Brunner <esther@kaffeehaus.ch>
* @author Michael Hamann <michael@content-space.de>
+ *
+ * @param string $id page id
+ * @return array
*/
function metaFiles($id){
$basename = metaFN($id, '');
@@ -343,6 +385,10 @@ function metaFiles($id){
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Kate Arzamastseva <pshns@ukr.net>
+ *
+ * @param string $id media id
+ * @param string|int $rev empty string or revision timestamp
+ * @return string full path
*/
function mediaFN($id, $rev=''){
global $conf;
@@ -365,6 +411,7 @@ function mediaFN($id, $rev=''){
* @param string $id The id of the local file
* @param string $ext The file extension (usually txt)
* @return string full filepath to localized file
+ *
* @author Andreas Gohr <andi@splitbrain.org>
*/
function localeFN($id,$ext='txt'){
@@ -390,6 +437,11 @@ function localeFN($id,$ext='txt'){
* http://www.php.net/manual/en/function.realpath.php#57016
*
* @author <bart at mediawave dot nl>
+ *
+ * @param string $ns namespace which is context of id
+ * @param string $id relative id
+ * @param bool $clean flag indicating that id should be cleaned
+ * @return mixed|string
*/
function resolve_id($ns,$id,$clean=true){
global $conf;
@@ -435,10 +487,22 @@ function resolve_id($ns,$id,$clean=true){
* Returns a full media id
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $ns namespace which is context of id
+ * @param string &$page (reference) relative media id, updated to resolved id
+ * @param bool &$exists (reference) updated with existance of media
*/
-function resolve_mediaid($ns,&$page,&$exists){
+function resolve_mediaid($ns,&$page,&$exists,$rev='',$date_at=false){
$page = resolve_id($ns,$page);
- $file = mediaFN($page);
+ if($rev !== '' && $date_at){
+ $medialog = new MediaChangeLog($page);
+ $medialog_rev = $medialog->getLastRevisionAt($rev);
+ if($medialog_rev !== false) {
+ $rev = $medialog_rev;
+ }
+ }
+
+ $file = mediaFN($page,$rev);
$exists = @file_exists($file);
}
@@ -446,8 +510,12 @@ function resolve_mediaid($ns,&$page,&$exists){
* Returns a full page id
*
* @author Andreas Gohr <andi@splitbrain.org>
+ *
+ * @param string $ns namespace which is context of id
+ * @param string &$page (reference) relative page id, updated to resolved id
+ * @param bool &$exists (reference) updated with existance of media
*/
-function resolve_pageid($ns,&$page,&$exists){
+function resolve_pageid($ns,&$page,&$exists,$rev='',$date_at=false ){
global $conf;
global $ID;
$exists = false;
@@ -467,20 +535,26 @@ function resolve_pageid($ns,&$page,&$exists){
$page = resolve_id($ns,$page,false); // resolve but don't clean, yet
// get filename (calls clean itself)
- $file = wikiFN($page);
+ if($rev !== '' && $date_at) {
+ $pagelog = new PageChangeLog($page);
+ $pagelog_rev = $pagelog->getLastRevisionAt($rev);
+ if($pagelog_rev !== false)//something found
+ $rev = $pagelog_rev;
+ }
+ $file = wikiFN($page,$rev);
// if ends with colon or slash we have a namespace link
if(in_array(substr($page,-1), array(':', ';')) ||
($conf['useslash'] && substr($page,-1) == '/')){
- if(page_exists($page.$conf['start'])){
+ if(page_exists($page.$conf['start'],$rev,true,$date_at)){
// start page inside namespace
$page = $page.$conf['start'];
$exists = true;
- }elseif(page_exists($page.noNS(cleanID($page)))){
+ }elseif(page_exists($page.noNS(cleanID($page)),$rev,true,$date_at)){
// page named like the NS inside the NS
$page = $page.noNS(cleanID($page));
$exists = true;
- }elseif(page_exists($page)){
+ }elseif(page_exists($page,$rev,true,$date_at)){
// page like namespace exists
$page = $page;
$exists = true;
@@ -497,7 +571,7 @@ function resolve_pageid($ns,&$page,&$exists){
}else{
$try = $page.'s';
}
- if(page_exists($try)){
+ if(page_exists($try,$rev,true,$date_at)){
$page = $try;
$exists = true;
}
@@ -537,6 +611,9 @@ function getCacheName($data,$ext=''){
* Checks a pageid against $conf['hidepages']
*
* @author Andreas Gohr <gohr@cosmocode.de>
+ *
+ * @param string $id page id
+ * @return bool
*/
function isHiddenPage($id){
$data = array(
@@ -550,7 +627,7 @@ function isHiddenPage($id){
/**
* callback checks if page is hidden
*
- * @param array $data event data see isHiddenPage()
+ * @param array $data event data - see isHiddenPage()
*/
function _isHiddenPage(&$data) {
global $conf;
@@ -569,6 +646,9 @@ function _isHiddenPage(&$data) {
* Reverse of isHiddenPage
*
* @author Andreas Gohr <gohr@cosmocode.de>
+ *
+ * @param string $id page id
+ * @return bool
*/
function isVisiblePage($id){
return !isHiddenPage($id);
@@ -581,8 +661,10 @@ function isVisiblePage($id){
* “*”. Output is escaped.
*
* @author Adrian Lang <lang@cosmocode.de>
+ *
+ * @param string $id page id
+ * @return string
*/
-
function prettyprint_id($id) {
if (!$id || $id === ':') {
return '*';
@@ -605,6 +687,10 @@ function prettyprint_id($id) {
*
* @author Andreas Gohr <andi@splitbrain.org>
* @see urlencode
+ *
+ * @param string $file file name
+ * @param bool $safe if true, only encoded when non ASCII characters detected
+ * @return string
*/
function utf8_encodeFN($file,$safe=true){
global $conf;
@@ -630,6 +716,9 @@ function utf8_encodeFN($file,$safe=true){
*
* @author Andreas Gohr <andi@splitbrain.org>
* @see urldecode
+ *
+ * @param string $file file name
+ * @return string
*/
function utf8_decodeFN($file){
global $conf;