From 912bd308e5c7e5325870f060c8de483606f26483 Mon Sep 17 00:00:00 2001
From: Matthias Schulte
Date: Tue, 3 Jul 2012 16:30:01 +0200
Subject: [PATCH 01/44] Restructuring / added helper.php
---
helper.php | 270 +++++++++++++++++++++++++++++++++++++++++
plugin.info.txt | 7 ++
syntax.php | 310 +++---------------------------------------------
3 files changed, 296 insertions(+), 291 deletions(-)
create mode 100644 helper.php
create mode 100644 plugin.info.txt
diff --git a/helper.php b/helper.php
new file mode 100644
index 0000000..706a2c6
--- /dev/null
+++ b/helper.php
@@ -0,0 +1,270 @@
+
+ * @author Andy Webber
+ * @author Federico Ariel Castagnini
+ * @author Cyrille37
+ * @author Matthias Schulte
+ */
+// must be run within Dokuwiki
+if(!defined('DOKU_INC')) die();
+if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
+
+require_once(DOKU_INC.'inc/search.php');
+
+define('DEBUG', 0);
+
+class helper_plugin_orphanswanted extends DokuWiki_Plugin {
+
+ function orph_callback_search_wanted(&$data, $base, $file, $type, $lvl, $opts) {
+
+ if($type == 'd') {
+ return true; // recurse all directories, but we don't store namespaces
+ }
+
+ if(!preg_match("/.*\.txt$/", $file)) {
+ // Ignore everything but TXT
+ return true;
+ }
+
+ // search the body of the file for links
+ // dae mod
+ // orph_Check_InternalLinks(&$data,$base,$file,$type,$lvl,$opts);
+ $this->orph_Check_InternalLinks($data,$base,$file,$type,$lvl,$opts);
+
+ // get id of this file
+ $id = pathID($file);
+
+ //check ACL
+ if(auth_quickaclcheck($id) < AUTH_READ) {
+ return false;
+ }
+
+ // try to avoid making duplicate entries for forms and pages
+ $item = &$data["$id"];
+
+ if(isset($item)) {
+ // This item already has a member in the array
+ // Note that the file search found it
+ $item['exists'] = true;
+ } else {
+ // Create a new entry
+ $data["$id"]=array('exists' => true, 'links' => 0);
+ }
+ return true;
+ }
+
+ function orph_handle_link(&$data, $link) {
+ if(isset($data[$link])) {
+ // This item already has a member in the array
+ // Note that the file search found it
+ $data[$link]['links'] ++ ; // count the link
+ } else {
+ // Create a new entry
+ $data[$link] = array(
+ 'exists' => false, // Only found a link, not the file
+ 'links' => 1
+ );
+ // echo " \n";
+ }
+ if (DEBUG) echo "-- New count for link " . $link . ": " . $data[$link]['links'] . "
\n";
+ }
+
+
+ /**
+ * Search for internal wiki links in page $file
+ */
+ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts )
+ {
+ global $conf;
+ define('LINK_PATTERN', '%\[\[([^\]|#]*)(#[^\]|]*)?\|?([^\]]*)]]%');
+
+ if(!preg_match("/.*\.txt$/", $file)) {
+ return;
+ }
+
+ $currentID = pathID($file);
+ $currentNS = getNS($currentID);
+
+ if(DEBUG) echo sprintf("%s: %s
\n", $file, $currentID);
+
+ // echo " \n";
+ $body = @file_get_contents($conf['datadir'] . $file);
+
+ // ignores entries in , %%, and emails with @
+ foreach( array(
+ '/.*?<\/nowiki>/',
+ '/%%.*?%%/',
+ '/.*?<\/code>/'
+ )
+ as $ignored )
+ {
+ $body = preg_replace($ignored, '', $body);
+ }
+
+ $links = array();
+ preg_match_all( LINK_PATTERN, $body, $links );
+
+ foreach($links[1] as $link) {
+ if(DEBUG) echo sprintf("--- Checking %s
\n", $link);
+
+ if( (0 < strlen(ltrim($link)))
+ and ! preg_match('/^[a-zA-Z0-9\.]+>{1}.*$/u',$link) // Interwiki
+ and ! preg_match('/^\\\\\\\\[\w.:?\-;,]+?\\\\/u',$link) // Windows Share
+ and ! preg_match('#^([a-z0-9\-\.+]+?)://#i',$link) // external link (accepts all protocols)
+ and ! preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$link) // E-Mail (pattern above is defined in inc/mail.php)
+ and ! preg_match('!^#.+!',$link) // inside page link (html anchor)
+ ) {
+ $pageExists = false;
+ resolve_pageid($currentNS, $link, $pageExists );
+ if (DEBUG) echo sprintf("---- link='%s' %s ", $link, $pageExists?'EXISTS':'MISS');
+
+ if(((strlen(ltrim($link)) > 0) // there IS an id?
+ and !auth_quickaclcheck($link) < AUTH_READ)) {
+ // should be visible to user
+ //echo " \n";
+
+ if(DEBUG) echo ' A_LINK' ;
+
+ $link= strtolower( $link );
+ $this->orph_handle_link($data, $link);
+ }
+ else
+ {
+ if(DEBUG) echo ' EMPTY_OR_FORBIDDEN' ;
+ }
+ } // link is not empty and is a local link?
+ else {
+ if(DEBUG) echo ' NOT_INTERNAL';
+ }
+
+ if(DEBUG) echo "
\n";
+ } // end of foreach link
+ }
+
+ // three choices
+ // $params_array used to extract excluded namespaces for report
+ // orphans = orph_report_table($data, true, false, $params_array);
+ // wanted = orph_report_table($data, false, true), $params_array;
+ // valid = orph_report_table($data, true, true, $params_array);
+
+ function orphan_pages($params_array) {
+ global $conf;
+ $result = '';
+ $data = array();
+ search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => $ns));
+ $result .= $this->orph_report_table($data, true, false,$params_array);
+
+ return $result;
+ }
+
+ function wanted_pages($params_array) {
+ global $conf;
+ $result = '';
+ $data = array();
+ search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => $ns));
+ $result .= $this->orph_report_table($data, false, true,$params_array);
+
+ return $result;
+ }
+
+ function valid_pages($params_array) {
+ global $conf;
+ $result = '';
+ $data = array();
+ search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => $ns));
+ $result .= $this->orph_report_table($data, true, true, $params_array);
+
+ return $result;
+ }
+
+ function all_pages($params_array) {
+ global $conf;
+ $result = '';
+ $data = array();
+ search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted') , array('ns' => $ns));
+
+ $result .= "
Orphans
";
+ $result .= $this->orph_report_table($data, true, false,$params_array);
+ $result .= "
Wanted
";
+ $result .= $this->orph_report_table($data, false, true,$params_array);
+ $result .= "
Valid
";
+ $result .= $this->orph_report_table($data, true, true, $params_array);
+
+
+ return $result;
+ }
+
+ function orph_report_table($data, $page_exists, $has_links, $params_array) {
+ global $conf;
+
+ $show_heading = ($page_exists && $conf['useheading']) ? true : false ;
+
+ //take off $params_array[0];
+ $exclude_array = array_slice($params_array,1);
+
+ $count = 1;
+ $output = '';
+
+ // for valid html - need to close the
that is feed before this
+ $output .= '
';
+ $output .= '| # | ID | '
+ . ($show_heading ? 'Title | ' : '' )
+ . 'Links |
'
+ ."\n" ;
+
+ arsort($data);
+
+ foreach($data as $id=>$item) {
+ if( ! (($item['exists'] == $page_exists) and (($item['links'] <> 0)== $has_links)) ) {
+ continue ;
+ }
+
+ // $id is a string, looks like this: page, namespace:page, or namespace::page
+ $match_array = explode(":", $id);
+ //remove last item in array, the page identifier
+ $match_array = array_slice($match_array, 0, -1);
+ //put it back together
+ $page_namespace = implode (":", $match_array);
+ //add a trailing :
+ $page_namespace = $page_namespace . ':';
+
+ //set it to show, unless blocked by exclusion list
+ $show_it = true;
+ foreach ($exclude_array as $exclude_item) {
+ //add a trailing : to each $item too
+ $exclude_item = $exclude_item . ":";
+ // need === to avoid boolean false
+ // strpos(haystack, needle)
+ // if exclusion is beginning of page's namespace , block it
+ if (strpos($page_namespace, $exclude_item) === 0) {
+ //there is a match, so block it
+ $show_it = false;
+ }
+ }
+
+ if($show_it) {
+ $output .= "| $count | "
+ . $id .' | '
+ . ($show_heading ? '' . hsc(p_get_first_heading($id)) .' | ' : '' )
+ . '' . $item['links']
+ . ($has_links
+ ? " : Show backlinks"
+ : ''
+ )
+ . " |
\n";
+
+ $count++;
+ }
+ }
+
+ $output .= "
\n";
+ //for valid html = need to reopen a
+ $output .= '
';
+
+ return $output;
+ }
+}
diff --git a/plugin.info.txt b/plugin.info.txt
new file mode 100644
index 0000000..8d198d6
--- /dev/null
+++ b/plugin.info.txt
@@ -0,0 +1,7 @@
+base orphanswanted
+author Doug Edmunds, Cyrille37, Federico Ariel Castagnini, Andy Webber, Matthias Schulte
+email dokuwiki@lupo49.de
+date 2012-07-03
+name orphanswanted plugin
+desc Display Orphans, Wanteds and Valid link information
+url http://dokuwiki.org/plugin:orphanswanted
diff --git a/syntax.php b/syntax.php
index 29868ca..dcda246 100644
--- a/syntax.php
+++ b/syntax.php
@@ -1,8 +1,10 @@
[!]~~ :: orphans | wanted | valid | all
* [!] :: optional. prefix each with ! e.g., !wiki!comments:currentyear
+ *
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author
* @author Andy Webber
@@ -13,154 +15,13 @@
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
-
-require_once(DOKU_INC.'inc/search.php');
-
-define('DEBUG', 0);
-
-//-------------------------------------
-
-function orph_callback_search_wanted(&$data,$base,$file,$type,$lvl,$opts) {
-
- if($type == 'd'){
- return true; // recurse all directories, but we don't store namespaces
- }
-
- if(!preg_match("/.*\.txt$/", $file)) { // Ignore everything but TXT
- return true;
- }
-
- // search the body of the file for links
- // dae mod
- // orph_Check_InternalLinks(&$data,$base,$file,$type,$lvl,$opts);
- orph_Check_InternalLinks($data,$base,$file,$type,$lvl,$opts);
-
- // get id of this file
- $id = pathID($file);
-
- //check ACL
- if(auth_quickaclcheck($id) < AUTH_READ) {
- return false;
- }
-
- // try to avoid making duplicate entries for forms and pages
- $item = &$data["$id"];
- if(isset($item)) {
- // This item already has a member in the array
- // Note that the file search found it
- $item['exists'] = true;
- } else {
- // Create a new entry
- $data["$id"]=array('exists' => true,
- 'links' => 0);
- }
- return true;
-}
-
-function orph_handle_link( &$data, $link )
-{
- if( isset($data[$link]) )
- {
- // This item already has a member in the array
- // Note that the file search found it
- $data[$link]['links'] ++ ; // count the link
- } else {
- // Create a new entry
- $data[$link] = array(
- 'exists' => false, // Only found a link, not the file
- 'links' => 1
- );
- // echo " \n";
- }
- if (DEBUG) echo "-- New count for link " . $link . ": " . $data[$link]['links'] . "
\n";
-}
-
-
-/**
- * Search for internal wiki links in page $file
- */
-function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts )
-{
- global $conf;
- define('LINK_PATTERN', '%\[\[([^\]|#]*)(#[^\]|]*)?\|?([^\]]*)]]%');
-
- if( ! preg_match("/.*\.txt$/", $file) )
- {
- return ;
- }
-
- $currentID = pathID($file);
- $currentNS = getNS($currentID);
- if(DEBUG) echo sprintf("%s: %s
\n", $file, $currentID);
-
- // echo " \n";
- $body = @file_get_contents($conf['datadir'] . $file);
-
- // ignores entries in , %%, and emails with @
- foreach( array(
- '/.*?<\/nowiki>/',
- '/%%.*?%%/',
- '/.*?<\/code>/'
- )
- as $ignored )
- {
- $body = preg_replace($ignored, '', $body);
- }
-
- $links = array();
- preg_match_all( LINK_PATTERN, $body, $links );
-
- foreach( $links[1] as $link )
- {
- if(DEBUG) echo sprintf("--- Checking %s
\n", $link);
-
- if( (0 < strlen(ltrim($link)))
- and ! preg_match('/^[a-zA-Z0-9\.]+>{1}.*$/u',$link) // Interwiki
- and ! preg_match('/^\\\\\\\\[\w.:?\-;,]+?\\\\/u',$link) // Windows Share
- and ! preg_match('#^([a-z0-9\-\.+]+?)://#i',$link) // external link (accepts all protocols)
- and ! preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$link) // E-Mail (pattern above is defined in inc/mail.php)
- and ! preg_match('!^#.+!',$link) // inside page link (html anchor)
- ) {
- $pageExists=false;
- resolve_pageid($currentNS,$link,$pageExists );
- if (DEBUG) echo sprintf("---- link='%s' %s ", $link, $pageExists?'EXISTS':'MISS');
-
- if(((strlen(ltrim($link)) > 0) // there IS an id?
- and !auth_quickaclcheck($link) < AUTH_READ)) { // should be visible to user
- //echo " \n";
-
- if(DEBUG) echo ' A_LINK' ;
-
- $link= strtolower( $link );
- orph_handle_link($data, $link);
- }
- else
- {
- if(DEBUG) echo ' EMPTY_OR_FORBIDDEN' ;
- }
- } // link is not empty and is a local link?
- else
- {
- if(DEBUG) echo ' NOT_INTERNAL';
- }
-
- if(DEBUG) echo "
\n";
- } // end of foreach link
-}
-
-
-
-// --------------------
-
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_orphanswanted extends DokuWiki_Syntax_Plugin {
- /**
- * return some info
- */
+
function getInfo(){
return array(
'author' => 'Doug Edmunds',
@@ -193,7 +54,7 @@ function getPType(){
* Where to sort in?
*/
function getSort(){
- return 990; //was 990
+ return 990; // was 990
}
@@ -201,16 +62,16 @@ function getSort(){
* Connect pattern to lexer
*/
function connectTo($mode) {
- $this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[0-9a-zA-Z_:!]+~~',$mode,'plugin_orphanswanted');
+ $this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[0-9a-zA-Z_:!]+~~', $mode, 'plugin_orphanswanted');
}
/**
* Handle the match
*/
-
function handle($match, $state, $pos, &$handler){
$match_array = array();
$match = substr($match,16,-2); //strip ~~ORPHANSWANTED: from start and ~~ from end
+
// Wolfgang 2007-08-29 suggests commenting out the next line
// $match = strtolower($match);
//create array, using ! as separator
@@ -218,6 +79,7 @@ function handle($match, $state, $pos, &$handler){
// $match_array[0] will be orphan, wanted, valid, all, or syntax error
// if there are excluded namespaces, they will be in $match_array[1] .. [x]
// this return value appears in render() as the $data param there
+
return $match_array;
}
@@ -226,8 +88,9 @@ function handle($match, $state, $pos, &$handler){
*/
function render($format, &$renderer, $data) {
global $INFO, $conf;
- if($format == 'xhtml'){
-
+ $helper = plugin_load('helper','orphanswanted');
+
+ if($format == 'xhtml') {
// user needs to add ~~NOCACHE~~ manually to page, to assure ACL rules are followed
// coding here is too late, it doesn't get parsed
// $renderer->doc .= "~~NOCACHE~~";
@@ -235,164 +98,29 @@ function render($format, &$renderer, $data) {
// $data is an array
// $data[1]..[x] are excluded namespaces, $data[0] is the report type
//handle choices
- switch ($data[0]){
+
+ switch ($data[0]) {
case 'orphans':
- $renderer->doc .= $this->orphan_pages($data);
+ $renderer->doc .= $helper->orphan_pages($data);
break;
case 'wanted':
- $renderer->doc .= $this->wanted_pages($data);
+ $renderer->doc .= $helper->wanted_pages($data);
break;
case 'valid':
- $renderer->doc .= $this->valid_pages($data);
+ $renderer->doc .= $helper->valid_pages($data);
break;
case 'all':
- $renderer->doc .= $this->all_pages($data);
+ $renderer->doc .= $helper->all_pages($data);
break;
default:
$renderer->doc .= "ORPHANSWANTED syntax error";
// $renderer->doc .= "syntax ~~ORPHANSWANTED:~~ :: orphans|wanted|valid|all Ex: ~~ORPHANSWANTED:valid~~";
}
-
- return true;
+ return true;
}
+
return false;
- }
-
-
-// three choices
-// $params_array used to extract excluded namespaces for report
-// orphans = orph_report_table($data, true, false, $params_array);
-// wanted = orph_report_table($data, false, true), $params_array;
-// valid = orph_report_table($data, true, true, $params_array);
-
-
- function orphan_pages($params_array) {
- global $conf;
- $result = '';
- $data = array();
- search($data,$conf['datadir'],'orph_callback_search_wanted',array('ns' => $ns));
- $result .= $this->orph_report_table($data, true, false,$params_array);
-
- return $result;
- }
-
- function wanted_pages($params_array) {
- global $conf;
- $result = '';
- $data = array();
- search($data,$conf['datadir'],'orph_callback_search_wanted',array('ns' => $ns));
- $result .= $this->orph_report_table($data, false, true,$params_array);
-
- return $result;
- }
-
- function valid_pages($params_array) {
- global $conf;
- $result = '';
- $data = array();
- search($data,$conf['datadir'],'orph_callback_search_wanted',array('ns' => $ns));
- $result .= $this->orph_report_table($data, true, true, $params_array);
-
- return $result;
- }
-
- function all_pages($params_array) {
- global $conf;
- $result = '';
- $data = array();
- search($data,$conf['datadir'],'orph_callback_search_wanted',array('ns' => $ns));
-
- $result .= "
Orphans
";
- $result .= $this->orph_report_table($data, true, false,$params_array);
- $result .= "
Wanted
";
- $result .= $this->orph_report_table($data, false, true,$params_array);
- $result .= "
Valid
";
- $result .= $this->orph_report_table($data, true, true, $params_array);
-
-
- return $result;
- }
-
- function orph_report_table( $data, $page_exists, $has_links, $params_array )
- {
- global $conf;
-
- $show_heading = ($page_exists && $conf['useheading']) ? true : false ;
-
- //take off $params_array[0];
- $exclude_array = array_slice($params_array,1);
-
- $count = 1;
- $output = '';
-
- // for valid html - need to close the
that is feed before this
- $output .= '
';
- $output .= '| # | ID | '
- . ($show_heading ? 'Title | ' : '' )
- . 'Links |
'
- ."\n" ;
-
- arsort($data);
-
- foreach($data as $id=>$item)
- {
-
- if( ! (($item['exists'] == $page_exists) and (($item['links'] <> 0)== $has_links)) )
- {
- continue ;
- }
-
- // $id is a string, looks like this: page, namespace:page, or namespace::page
- $match_array = explode(":", $id);
- //remove last item in array, the page identifier
- $match_array = array_slice($match_array, 0, -1);
- //put it back together
- $page_namespace = implode (":", $match_array);
- //add a trailing :
- $page_namespace = $page_namespace . ':';
-
- //set it to show, unless blocked by exclusion list
- $show_it = true;
- foreach ($exclude_array as $exclude_item)
- {
- //add a trailing : to each $item too
- $exclude_item = $exclude_item . ":";
- // need === to avoid boolean false
- // strpos(haystack, needle)
- // if exclusion is beginning of page's namespace , block it
- if (strpos($page_namespace, $exclude_item) === 0){
- //there is a match, so block it
- $show_it = false;
- }
- }
-
- if( $show_it )
- {
- $output .= "| $count | "
- . $id .' | '
- . ($show_heading ? '' . hsc(p_get_first_heading($id)) .' | ' : '' )
- . '' . $item['links']
- . ($has_links
- ? " : Show backlinks"
- : ''
- )
- . " |
\n";
-
- $count++;
- }
-
- }
-
- $output .= "
\n";
- //for valid html = need to reopen a
- $output .= '
';
-
- return $output;
- }
-
+ }
}
//Setup VIM: ex: et ts=4 enc=utf-8 :
-?>
From 40a52fb58beba69bdbb9473431e37c0ba9dc7ec2 Mon Sep 17 00:00:00 2001
From: RedRat
Date: Tue, 3 Jul 2012 16:36:30 +0200
Subject: [PATCH 02/44] Support for non-Latin letters
---
helper.php | 2 +-
syntax.php | 16 +---------------
2 files changed, 2 insertions(+), 16 deletions(-)
diff --git a/helper.php b/helper.php
index 706a2c6..bdcbc3a 100644
--- a/helper.php
+++ b/helper.php
@@ -127,7 +127,7 @@ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts )
if(DEBUG) echo ' A_LINK' ;
- $link= strtolower( $link );
+ $link= utf8_strtolower( $link );
$this->orph_handle_link($data, $link);
}
else
diff --git a/syntax.php b/syntax.php
index dcda246..fa532b3 100644
--- a/syntax.php
+++ b/syntax.php
@@ -21,20 +21,6 @@
* need to inherit from this class
*/
class syntax_plugin_orphanswanted extends DokuWiki_Syntax_Plugin {
-
- function getInfo(){
- return array(
- 'author' => 'Doug Edmunds',
- 'email' => 'dae@douglasedmunds.com',
- 'date' => @file_get_contents(dirname(__FILE__) . '/VERSION'),
- 'name' => 'OrphansWanted Plugin',
- 'desc' => 'Find orphan pages and wanted pages .
- syntax ~~ORPHANSWANTED:[!]~~ .
- :: orphans|wanted|valid|all .
- are optional, start each namespace with !' ,
- 'url' => 'http://dokuwiki.org/plugin:orphanswanted',
- );
- }
/**
* What kind of syntax are we?
@@ -62,7 +48,7 @@ function getSort(){
* Connect pattern to lexer
*/
function connectTo($mode) {
- $this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[0-9a-zA-Z_:!]+~~', $mode, 'plugin_orphanswanted');
+ $this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[\w:!]+~~', $mode, 'plugin_orphanswanted');
}
/**
From 51485800db10c7f1668d513e7be945823e424a73 Mon Sep 17 00:00:00 2001
From: Matthias Schulte
Date: Tue, 3 Jul 2012 16:48:10 +0200
Subject: [PATCH 03/44] Prevent caching of pages where the plugin is active
---
syntax.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/syntax.php b/syntax.php
index fa532b3..9732dfd 100644
--- a/syntax.php
+++ b/syntax.php
@@ -77,6 +77,9 @@ function render($format, &$renderer, $data) {
$helper = plugin_load('helper','orphanswanted');
if($format == 'xhtml') {
+ // prevent caching to ensure content is always fresh
+ $renderer->info['cache'] = false;
+
// user needs to add ~~NOCACHE~~ manually to page, to assure ACL rules are followed
// coding here is too late, it doesn't get parsed
// $renderer->doc .= "~~NOCACHE~~";
From 281aa16504d6489fe7ee6b3b2474f6fef41afe78 Mon Sep 17 00:00:00 2001
From: Matthias Schulte
Date: Tue, 3 Jul 2012 16:52:40 +0200
Subject: [PATCH 04/44] Removed obsolete comments
---
syntax.php | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/syntax.php b/syntax.php
index 9732dfd..2f54047 100644
--- a/syntax.php
+++ b/syntax.php
@@ -79,11 +79,7 @@ function render($format, &$renderer, $data) {
if($format == 'xhtml') {
// prevent caching to ensure content is always fresh
$renderer->info['cache'] = false;
-
- // user needs to add ~~NOCACHE~~ manually to page, to assure ACL rules are followed
- // coding here is too late, it doesn't get parsed
- // $renderer->doc .= "~~NOCACHE~~";
-
+
// $data is an array
// $data[1]..[x] are excluded namespaces, $data[0] is the report type
//handle choices
From 3f38e4f77826610d361dc27a335f416de43dcf17 Mon Sep 17 00:00:00 2001
From: ilium007
Date: Sun, 11 Nov 2012 23:41:03 +1000
Subject: [PATCH 05/44] Fixed issue with code and file blocks
and blocks coud contain [[]] characters that break the dokuwiki link structure. Added code to ignore contents of these blocks.
---
helper.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/helper.php b/helper.php
index bdcbc3a..22cadba 100644
--- a/helper.php
+++ b/helper.php
@@ -96,7 +96,8 @@ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts )
foreach( array(
'/.*?<\/nowiki>/',
'/%%.*?%%/',
- '/.*?<\/code>/'
+ '@]*?>.*?<\/code>@siu',
+ '@]*?>.*?<\/file>@siu'
)
as $ignored )
{
From 16ddee6c8249bb7e62cb353321a515d35ff1d887 Mon Sep 17 00:00:00 2001
From: lupo49
Date: Sun, 25 Nov 2012 15:25:04 +0100
Subject: [PATCH 06/44] helper.php: Removed superseded JS function svchk() /
Closes #5
---
helper.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/helper.php b/helper.php
index 22cadba..58122b2 100644
--- a/helper.php
+++ b/helper.php
@@ -247,8 +247,7 @@ function orph_report_table($data, $page_exists, $has_links, $params_array) {
if($show_it) {
$output .= "| $count | "
+ . "\" class=\"" . ($page_exists ? "wikilink1" : "wikilink2") . "\" >"
. $id .' | '
. ($show_heading ? '' . hsc(p_get_first_heading($id)) .' | ' : '' )
. '' . $item['links']
From 032e374cd96c041be693c83c98afc9118429a9b2 Mon Sep 17 00:00:00 2001
From: lupo49
Date: Sun, 25 Nov 2012 15:44:51 +0100
Subject: [PATCH 07/44] Skip the "Links" column inside the orphaned pages table
(Closes #4)
---
helper.php | 45 ++++++++++++++++++++++-----------------------
1 file changed, 22 insertions(+), 23 deletions(-)
diff --git a/helper.php b/helper.php
index 58122b2..f14aae7 100644
--- a/helper.php
+++ b/helper.php
@@ -155,7 +155,7 @@ function orphan_pages($params_array) {
$result = '';
$data = array();
search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => $ns));
- $result .= $this->orph_report_table($data, true, false,$params_array);
+ $result .= $this->orph_report_table($data, true, false, $params_array, 'orphan');
return $result;
}
@@ -165,7 +165,7 @@ function wanted_pages($params_array) {
$result = '';
$data = array();
search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => $ns));
- $result .= $this->orph_report_table($data, false, true,$params_array);
+ $result .= $this->orph_report_table($data, false, true, $params_array, 'wanted');
return $result;
}
@@ -175,7 +175,7 @@ function valid_pages($params_array) {
$result = '';
$data = array();
search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => $ns));
- $result .= $this->orph_report_table($data, true, true, $params_array);
+ $result .= $this->orph_report_table($data, true, true, $params_array, 'valid');
return $result;
}
@@ -187,17 +187,17 @@ function all_pages($params_array) {
search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted') , array('ns' => $ns));
$result .= " Orphans ";
- $result .= $this->orph_report_table($data, true, false,$params_array);
+ $result .= $this->orph_report_table($data, true, false, $params_array, 'orphan');
$result .= " Wanted ";
- $result .= $this->orph_report_table($data, false, true,$params_array);
+ $result .= $this->orph_report_table($data, false, true, $params_array, 'wanted');
$result .= " Valid ";
- $result .= $this->orph_report_table($data, true, true, $params_array);
+ $result .= $this->orph_report_table($data, true, true, $params_array, 'valid');
return $result;
}
- function orph_report_table($data, $page_exists, $has_links, $params_array) {
+ function orph_report_table($data, $page_exists, $has_links, $params_array, $caller = null) {
global $conf;
$show_heading = ($page_exists && $conf['useheading']) ? true : false ;
@@ -211,16 +211,15 @@ function orph_report_table($data, $page_exists, $has_links, $params_array) {
// for valid html - need to close the that is feed before this
$output .= ' ';
$output .= '| # | ID | '
- . ($show_heading ? 'Title | ' : '' )
- . 'Links | '
- ."\n" ;
+ . ($show_heading ? 'Title | ' : '' )
+ . ($caller != "orphan" ? 'Links | ' : '')
+ . ''
+ . "\n" ;
arsort($data);
foreach($data as $id=>$item) {
- if( ! (($item['exists'] == $page_exists) and (($item['links'] <> 0)== $has_links)) ) {
- continue ;
- }
+ if( ! (($item['exists'] == $page_exists) and (($item['links'] <> 0)== $has_links)) ) continue ;
// $id is a string, looks like this: page, namespace:page, or namespace::page
$match_array = explode(":", $id);
@@ -247,16 +246,16 @@ function orph_report_table($data, $page_exists, $has_links, $params_array) {
if($show_it) {
$output .= "| $count | "
- . $id .' | '
- . ($show_heading ? '' . hsc(p_get_first_heading($id)) .' | ' : '' )
- . '' . $item['links']
- . ($has_links
- ? " : Show backlinks"
- : ''
- )
- . " | \n";
-
+ . "\" class=\"" . ($page_exists ? "wikilink1" : "wikilink2") . "\" >"
+ . $id .''
+ . ($show_heading ? '' . hsc(p_get_first_heading($id)) .' | ' : '' );
+
+ if($caller != "orphan") { // Skip "link" column if user wants orphan pages only
+ $output .= '' . $item['links']
+ . ($has_links ? " : Show backlinks" : '') . " | ";
+ }
+ $output .= "\n";
$count++;
}
}
From 9eba54f868f4f52e369cb1690719646c52bcaab6 Mon Sep 17 00:00:00 2001
From: Matthias Schulte
Date: Sun, 25 Nov 2012 20:31:24 +0100
Subject: [PATCH 08/44] Update plugin.info.txt
---
plugin.info.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugin.info.txt b/plugin.info.txt
index 8d198d6..8db8c3b 100644
--- a/plugin.info.txt
+++ b/plugin.info.txt
@@ -1,7 +1,7 @@
base orphanswanted
author Doug Edmunds, Cyrille37, Federico Ariel Castagnini, Andy Webber, Matthias Schulte
email dokuwiki@lupo49.de
-date 2012-07-03
+date 2012-11-25
name orphanswanted plugin
desc Display Orphans, Wanteds and Valid link information
url http://dokuwiki.org/plugin:orphanswanted
From 92a5ff7b232af863b77945bd95ee0ce7921c2462 Mon Sep 17 00:00:00 2001
From: Matthias Schulte
Date: Wed, 5 Dec 2012 11:25:05 +0100
Subject: [PATCH 09/44] Merge HEAD, branch 'master' of
github.com:lupo49/dokuwiki-plugin-orphanswanted
From 736de0882efdf2b82b04aabc95c99ea620189daa Mon Sep 17 00:00:00 2001
From: Matthias Schulte
Date: Wed, 5 Dec 2012 11:50:02 +0100
Subject: [PATCH 10/44] Use DokuWikis debug setting ($conf['allowdebug']) for
debug outputs
---
helper.php | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/helper.php b/helper.php
index f14aae7..d5ff0df 100644
--- a/helper.php
+++ b/helper.php
@@ -13,8 +13,6 @@
require_once(DOKU_INC.'inc/search.php');
-define('DEBUG', 0);
-
class helper_plugin_orphanswanted extends DokuWiki_Plugin {
function orph_callback_search_wanted(&$data, $base, $file, $type, $lvl, $opts) {
@@ -56,6 +54,8 @@ function orph_callback_search_wanted(&$data, $base, $file, $type, $lvl, $opts) {
}
function orph_handle_link(&$data, $link) {
+ global $conf;
+
if(isset($data[$link])) {
// This item already has a member in the array
// Note that the file search found it
@@ -68,16 +68,17 @@ function orph_handle_link(&$data, $link) {
);
// echo " \n";
}
- if (DEBUG) echo "-- New count for link " . $link . ": " . $data[$link]['links'] . " \n";
+
+ if ($conf['allowdebug']) echo "-- New count for link " . $link . ": " . $data[$link]['links'] . " \n";
}
/**
* Search for internal wiki links in page $file
*/
- function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts )
- {
+ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts ) {
global $conf;
+
define('LINK_PATTERN', '%\[\[([^\]|#]*)(#[^\]|]*)?\|?([^\]]*)]]%');
if(!preg_match("/.*\.txt$/", $file)) {
@@ -87,7 +88,7 @@ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts )
$currentID = pathID($file);
$currentNS = getNS($currentID);
- if(DEBUG) echo sprintf("%s: %s \n", $file, $currentID);
+ if($conf['allowdebug']) echo sprintf("%s: %s \n", $file, $currentID);
// echo " \n";
$body = @file_get_contents($conf['datadir'] . $file);
@@ -108,7 +109,7 @@ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts )
preg_match_all( LINK_PATTERN, $body, $links );
foreach($links[1] as $link) {
- if(DEBUG) echo sprintf("--- Checking %s \n", $link);
+ if($conf['allowdebug']) echo sprintf("--- Checking %s \n", $link);
if( (0 < strlen(ltrim($link)))
and ! preg_match('/^[a-zA-Z0-9\.]+>{1}.*$/u',$link) // Interwiki
@@ -119,28 +120,28 @@ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts )
) {
$pageExists = false;
resolve_pageid($currentNS, $link, $pageExists );
- if (DEBUG) echo sprintf("---- link='%s' %s ", $link, $pageExists?'EXISTS':'MISS');
+ if ($conf['allowdebug']) echo sprintf("---- link='%s' %s ", $link, $pageExists?'EXISTS':'MISS');
if(((strlen(ltrim($link)) > 0) // there IS an id?
and !auth_quickaclcheck($link) < AUTH_READ)) {
// should be visible to user
//echo " \n";
- if(DEBUG) echo ' A_LINK' ;
+ if($conf['allowdebug']) echo ' A_LINK' ;
$link= utf8_strtolower( $link );
$this->orph_handle_link($data, $link);
}
else
{
- if(DEBUG) echo ' EMPTY_OR_FORBIDDEN' ;
+ if($conf['allowdebug']) echo ' EMPTY_OR_FORBIDDEN' ;
}
} // link is not empty and is a local link?
else {
- if(DEBUG) echo ' NOT_INTERNAL';
+ if($conf['allowdebug']) echo ' NOT_INTERNAL';
}
- if(DEBUG) echo " \n";
+ if($conf['allowdebug']) echo " \n";
} // end of foreach link
}
@@ -193,15 +194,12 @@ function all_pages($params_array) {
$result .= "Valid ";
$result .= $this->orph_report_table($data, true, true, $params_array, 'valid');
-
return $result;
}
function orph_report_table($data, $page_exists, $has_links, $params_array, $caller = null) {
global $conf;
-
$show_heading = ($page_exists && $conf['useheading']) ? true : false ;
-
//take off $params_array[0];
$exclude_array = array_slice($params_array,1);
From 81cf0f28e3b02201bc969f4c46743099a1af45a2 Mon Sep 17 00:00:00 2001
From: Matthias Schulte
Date: Wed, 5 Dec 2012 12:43:58 +0100
Subject: [PATCH 11/44] Added Configuration Manager option to ignore pages in
every output
---
conf/default.php | 9 +++++++++
conf/metadata.php | 10 ++++++++++
helper.php | 29 +++++++++++++++++++++--------
lang/de-informal/settings.php | 10 ++++++++++
lang/de/settings.php | 10 ++++++++++
lang/en/settings.php | 10 ++++++++++
6 files changed, 70 insertions(+), 8 deletions(-)
create mode 100644 conf/default.php
create mode 100644 conf/metadata.php
create mode 100644 lang/de-informal/settings.php
create mode 100644 lang/de/settings.php
create mode 100644 lang/en/settings.php
diff --git a/conf/default.php b/conf/default.php
new file mode 100644
index 0000000..3dd0895
--- /dev/null
+++ b/conf/default.php
@@ -0,0 +1,9 @@
+
+ */
+$conf['ignoredpages'] = ''; // The plugin will doesn't list the given pages
+
+//Setup VIM: ex: et ts=2 :
diff --git a/conf/metadata.php b/conf/metadata.php
new file mode 100644
index 0000000..221fab3
--- /dev/null
+++ b/conf/metadata.php
@@ -0,0 +1,10 @@
+
+ */
+$meta['ignoredpages'] = array('string');
+
+//Setup VIM: ex: et ts=2 :
diff --git a/helper.php b/helper.php
index d5ff0df..f2cb2f3 100644
--- a/helper.php
+++ b/helper.php
@@ -199,6 +199,13 @@ function all_pages($params_array) {
function orph_report_table($data, $page_exists, $has_links, $params_array, $caller = null) {
global $conf;
+ $ignoredPages = $this->getConf('ignoredpages'); // Fetch pages which shouldn't be listed
+ if($ignoredPages != '') {
+ $ignoredPages = explode(';', $ignoredPages);
+ } else {
+ $ignoredPages = null;
+ }
+
$show_heading = ($page_exists && $conf['useheading']) ? true : false ;
//take off $params_array[0];
$exclude_array = array_slice($params_array,1);
@@ -230,15 +237,21 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
//set it to show, unless blocked by exclusion list
$show_it = true;
- foreach ($exclude_array as $exclude_item) {
- //add a trailing : to each $item too
- $exclude_item = $exclude_item . ":";
- // need === to avoid boolean false
- // strpos(haystack, needle)
- // if exclusion is beginning of page's namespace , block it
- if (strpos($page_namespace, $exclude_item) === 0) {
- //there is a match, so block it
+
+ if(!is_null($ignoredPages) && in_array($id, $ignoredPages)) {
+ echo "Skipped page (global ignored): " . $id . " ";
$show_it = false;
+ } else {
+ foreach ($exclude_array as $exclude_item) {
+ //add a trailing : to each $item too
+ $exclude_item = $exclude_item . ":";
+ // need === to avoid boolean false
+ // strpos(haystack, needle)
+ // if exclusion is beginning of page's namespace , block it
+ if (strpos($page_namespace, $exclude_item) === 0) {
+ //there is a match, so block it
+ $show_it = false;
+ }
}
}
diff --git a/lang/de-informal/settings.php b/lang/de-informal/settings.php
new file mode 100644
index 0000000..fb712a8
--- /dev/null
+++ b/lang/de-informal/settings.php
@@ -0,0 +1,10 @@
+
+ */
+
+$lang['ignoredpages'] = 'Diese Seiten nie in den Ausgaben anzeigen (Trennzeichen: Semikolon)';
+
+//Setup VIM: ex: et ts=2 :
diff --git a/lang/de/settings.php b/lang/de/settings.php
new file mode 100644
index 0000000..fb712a8
--- /dev/null
+++ b/lang/de/settings.php
@@ -0,0 +1,10 @@
+
+ */
+
+$lang['ignoredpages'] = 'Diese Seiten nie in den Ausgaben anzeigen (Trennzeichen: Semikolon)';
+
+//Setup VIM: ex: et ts=2 :
diff --git a/lang/en/settings.php b/lang/en/settings.php
new file mode 100644
index 0000000..8796acb
--- /dev/null
+++ b/lang/en/settings.php
@@ -0,0 +1,10 @@
+
+ */
+
+$lang['ignoredpages'] = 'Always skip these pages in the output table (Delimiter: Semicolon)';
+
+//Setup VIM: ex: et ts=2 :
From d5d9d3f4f49b3633245adb4012ba6f87b18fc627 Mon Sep 17 00:00:00 2001
From: Matthias Schulte
Date: Wed, 5 Dec 2012 12:47:54 +0100
Subject: [PATCH 12/44] Updated version info
---
VERSION | 1 -
plugin.info.txt | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
delete mode 100644 VERSION
diff --git a/VERSION b/VERSION
deleted file mode 100644
index fa88583..0000000
--- a/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-2010-04-11
diff --git a/plugin.info.txt b/plugin.info.txt
index 8db8c3b..19b022f 100644
--- a/plugin.info.txt
+++ b/plugin.info.txt
@@ -1,7 +1,7 @@
base orphanswanted
author Doug Edmunds, Cyrille37, Federico Ariel Castagnini, Andy Webber, Matthias Schulte
email dokuwiki@lupo49.de
-date 2012-11-25
+date 2012-12-05
name orphanswanted plugin
desc Display Orphans, Wanteds and Valid link information
url http://dokuwiki.org/plugin:orphanswanted
From eb2732befb9af99816a7ae2ba500189bf1c69f66 Mon Sep 17 00:00:00 2001
From: Dominik Eckelmann
Date: Mon, 11 Mar 2013 16:13:44 +0100
Subject: [PATCH 13/44] added PLUGIN_ORPHANS_WANTED_PROCESS_PAGE event
---
helper.php | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/helper.php b/helper.php
index f2cb2f3..cf460f7 100644
--- a/helper.php
+++ b/helper.php
@@ -31,6 +31,12 @@ function orph_callback_search_wanted(&$data, $base, $file, $type, $lvl, $opts) {
// orph_Check_InternalLinks(&$data,$base,$file,$type,$lvl,$opts);
$this->orph_Check_InternalLinks($data,$base,$file,$type,$lvl,$opts);
+ $eventData = array(
+ 'data' => &$data,
+ 'file' => $file
+ );
+ trigger_event('PLUGIN_ORPHANS_WANTED_PROCESS_PAGE', $eventData);
+
// get id of this file
$id = pathID($file);
From 70a548629e2a0fc02fe1a262fc4b55c4c1d9123c Mon Sep 17 00:00:00 2001
From: Michelle Baert
Date: Wed, 12 Feb 2014 11:04:12 +0100
Subject: [PATCH 14/44] Strip parameters from found links
---
helper.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/helper.php b/helper.php
index cf460f7..e750d30 100644
--- a/helper.php
+++ b/helper.php
@@ -124,6 +124,9 @@ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts ) {
and ! preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$link) // E-Mail (pattern above is defined in inc/mail.php)
and ! preg_match('!^#.+!',$link) // inside page link (html anchor)
) {
+ # remove parameters
+ $link = preg_replace('/\?.*/', '', $link) . "\n";
+
$pageExists = false;
resolve_pageid($currentNS, $link, $pageExists );
if ($conf['allowdebug']) echo sprintf("---- link='%s' %s ", $link, $pageExists?'EXISTS':'MISS');
From eaa178298986d52e622b5adc71f6f3f6aecf1f85 Mon Sep 17 00:00:00 2001
From: Marius van Witzenburg
Date: Wed, 2 Sep 2015 17:12:45 +0200
Subject: [PATCH 15/44] Fixed whitespace
---
syntax.php | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/syntax.php b/syntax.php
index 2f54047..2b8d251 100644
--- a/syntax.php
+++ b/syntax.php
@@ -1,17 +1,17 @@
[!]~~ :: orphans | wanted | valid | all
* [!] :: optional. prefix each with ! e.g., !wiki!comments:currentyear
- *
+ *
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author
* @author Andy Webber
* @author Federico Ariel Castagnini
* @author Cyrille37
*/
-
+
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
@@ -21,43 +21,43 @@
* need to inherit from this class
*/
class syntax_plugin_orphanswanted extends DokuWiki_Syntax_Plugin {
-
+
/**
* What kind of syntax are we?
*/
function getType(){
return 'substition';
}
-
+
/**
* What about paragraphs?
*/
function getPType(){
return 'normal';
}
-
+
/**
* Where to sort in?
*/
function getSort(){
return 990; // was 990
}
-
-
+
+
/**
* Connect pattern to lexer
*/
function connectTo($mode) {
$this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[\w:!]+~~', $mode, 'plugin_orphanswanted');
}
-
+
/**
* Handle the match
*/
function handle($match, $state, $pos, &$handler){
$match_array = array();
$match = substr($match,16,-2); //strip ~~ORPHANSWANTED: from start and ~~ from end
-
+
// Wolfgang 2007-08-29 suggests commenting out the next line
// $match = strtolower($match);
//create array, using ! as separator
@@ -65,17 +65,17 @@ function handle($match, $state, $pos, &$handler){
// $match_array[0] will be orphan, wanted, valid, all, or syntax error
// if there are excluded namespaces, they will be in $match_array[1] .. [x]
// this return value appears in render() as the $data param there
-
+
return $match_array;
}
-
+
/**
* Create output
*/
function render($format, &$renderer, $data) {
global $INFO, $conf;
$helper = plugin_load('helper','orphanswanted');
-
+
if($format == 'xhtml') {
// prevent caching to ensure content is always fresh
$renderer->info['cache'] = false;
@@ -83,7 +83,7 @@ function render($format, &$renderer, $data) {
// $data is an array
// $data[1]..[x] are excluded namespaces, $data[0] is the report type
//handle choices
-
+
switch ($data[0]) {
case 'orphans':
$renderer->doc .= $helper->orphan_pages($data);
@@ -103,9 +103,9 @@ function render($format, &$renderer, $data) {
}
return true;
}
-
+
return false;
- }
+ }
}
-
+
//Setup VIM: ex: et ts=4 enc=utf-8 :
From 9577bab39d4182765e91dfc9b504bed03a6b9fb9 Mon Sep 17 00:00:00 2001
From: Marius van Witzenburg
Date: Wed, 2 Sep 2015 17:15:25 +0200
Subject: [PATCH 16/44] Fixed compatability with
DokuWiki_Syntax_Plugin::handle() and DokuWiki_Syntax_Plugin::render()
---
syntax.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/syntax.php b/syntax.php
index 2b8d251..17e861a 100644
--- a/syntax.php
+++ b/syntax.php
@@ -54,7 +54,7 @@ function connectTo($mode) {
/**
* Handle the match
*/
- function handle($match, $state, $pos, &$handler){
+ function handle($match, $state, $pos, Doku_Handler $handler){
$match_array = array();
$match = substr($match,16,-2); //strip ~~ORPHANSWANTED: from start and ~~ from end
@@ -72,7 +72,7 @@ function handle($match, $state, $pos, &$handler){
/**
* Create output
*/
- function render($format, &$renderer, $data) {
+ function render($format, Doku_Renderer $renderer, $data) {
global $INFO, $conf;
$helper = plugin_load('helper','orphanswanted');
From 2acfc1de2c05b6ef060a472132ac4b25de68ef82 Mon Sep 17 00:00:00 2001
From: Marius van Witzenburg
Date: Mon, 7 Sep 2015 17:16:52 +0200
Subject: [PATCH 17/44] Check if LINK_PATTERN constant is already defined
---
helper.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/helper.php b/helper.php
index cf460f7..d3d78d5 100644
--- a/helper.php
+++ b/helper.php
@@ -85,7 +85,7 @@ function orph_handle_link(&$data, $link) {
function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts ) {
global $conf;
- define('LINK_PATTERN', '%\[\[([^\]|#]*)(#[^\]|]*)?\|?([^\]]*)]]%');
+ if (!defined('LINK_PATTERN')) define('LINK_PATTERN', '%\[\[([^\]|#]*)(#[^\]|]*)?\|?([^\]]*)]]%');
if(!preg_match("/.*\.txt$/", $file)) {
return;
From f3158748a0a7c3cc54bb99e628bd4c1ba4e45576 Mon Sep 17 00:00:00 2001
From: Marius van Witzenburg
Date: Mon, 7 Sep 2015 17:17:10 +0200
Subject: [PATCH 18/44] Whitespace
---
helper.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/helper.php b/helper.php
index d3d78d5..c4c0b8f 100644
--- a/helper.php
+++ b/helper.php
@@ -47,7 +47,7 @@ function orph_callback_search_wanted(&$data, $base, $file, $type, $lvl, $opts) {
// try to avoid making duplicate entries for forms and pages
$item = &$data["$id"];
-
+
if(isset($item)) {
// This item already has a member in the array
// Note that the file search found it
@@ -127,14 +127,14 @@ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts ) {
$pageExists = false;
resolve_pageid($currentNS, $link, $pageExists );
if ($conf['allowdebug']) echo sprintf("---- link='%s' %s ", $link, $pageExists?'EXISTS':'MISS');
-
+
if(((strlen(ltrim($link)) > 0) // there IS an id?
and !auth_quickaclcheck($link) < AUTH_READ)) {
// should be visible to user
//echo " \n";
-
+
if($conf['allowdebug']) echo ' A_LINK' ;
-
+
$link= utf8_strtolower( $link );
$this->orph_handle_link($data, $link);
}
From b74237ade9d019ce255a71690eaad34ec1c54d16 Mon Sep 17 00:00:00 2001
From: Marius van Witzenburg
Date: Mon, 7 Sep 2015 17:17:33 +0200
Subject: [PATCH 19/44] Get namespace with getNS instead of $ns
---
helper.php | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/helper.php b/helper.php
index c4c0b8f..d311c4d 100644
--- a/helper.php
+++ b/helper.php
@@ -158,40 +158,40 @@ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts ) {
// valid = orph_report_table($data, true, true, $params_array);
function orphan_pages($params_array) {
- global $conf;
+ global $conf, $ID;
$result = '';
$data = array();
- search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => $ns));
+ search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => getNS($ID)));
$result .= $this->orph_report_table($data, true, false, $params_array, 'orphan');
return $result;
}
function wanted_pages($params_array) {
- global $conf;
+ global $conf, $ID;
$result = '';
$data = array();
- search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => $ns));
+ search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => getNS($ID)));
$result .= $this->orph_report_table($data, false, true, $params_array, 'wanted');
return $result;
}
function valid_pages($params_array) {
- global $conf;
+ global $conf, $ID;
$result = '';
$data = array();
- search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => $ns));
+ search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => getNS($ID)));
$result .= $this->orph_report_table($data, true, true, $params_array, 'valid');
return $result;
}
function all_pages($params_array) {
- global $conf;
+ global $conf, $ID;
$result = '';
$data = array();
- search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted') , array('ns' => $ns));
+ search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted') , array('ns' => getNS($ID)));
$result .= " Orphans ";
$result .= $this->orph_report_table($data, true, false, $params_array, 'orphan');
From a242594578c0c63bc285b71c6c14ef47f2a1fa0c Mon Sep 17 00:00:00 2001
From: Andreas Gohr
Date: Tue, 2 Feb 2016 16:13:27 +0100
Subject: [PATCH 20/44] Adjust method signatures to match parent
---
syntax.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/syntax.php b/syntax.php
index 2f54047..083fd8a 100644
--- a/syntax.php
+++ b/syntax.php
@@ -54,7 +54,7 @@ function connectTo($mode) {
/**
* Handle the match
*/
- function handle($match, $state, $pos, &$handler){
+ function handle($match, $state, $pos, Doku_Handler $handler){
$match_array = array();
$match = substr($match,16,-2); //strip ~~ORPHANSWANTED: from start and ~~ from end
@@ -72,7 +72,7 @@ function handle($match, $state, $pos, &$handler){
/**
* Create output
*/
- function render($format, &$renderer, $data) {
+ function render($format, Doku_Renderer $renderer, $data) {
global $INFO, $conf;
$helper = plugin_load('helper','orphanswanted');
From b3717627b2c417ecaa300388e05aa3deff40e745 Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Fri, 4 Mar 2016 16:48:32 -0800
Subject: [PATCH 21/44] Added ignored patterns and fixed case-insensitive
patterns
---
helper.php | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/helper.php b/helper.php
index cf460f7..1e437fa 100644
--- a/helper.php
+++ b/helper.php
@@ -99,12 +99,17 @@ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts ) {
// echo " \n";
$body = @file_get_contents($conf['datadir'] . $file);
- // ignores entries in , %%, and emails with @
+ // ignores entries in blocks that ignore links
foreach( array(
- '/.*?<\/nowiki>/',
- '/%%.*?%%/',
- '@]*?>.*?<\/code>@siu',
- '@]*?>.*?<\/file>@siu'
+ '@.*?<\/nowiki>@su',
+ '@%%.*?%%@su',
+ '@.*?@su',
+ '@.*?@su',
+ '@.*?@su',
+ '@.*?@su',
+ '@\n( {2,}|\t)[^\*\- ].*?\n@su',
+ '@]*?>.*?<\/code>@su',
+ '@]*?>.*?<\/file>@su'
)
as $ignored )
{
From c7889fd3be54ce688ed7074e7cd735bb25fe3edb Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Sun, 6 Mar 2016 20:51:58 -0800
Subject: [PATCH 22/44] Fixed detection of blocks starting with 2 spaces or a
tab
---
helper.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/helper.php b/helper.php
index 1e437fa..ee274aa 100644
--- a/helper.php
+++ b/helper.php
@@ -107,7 +107,7 @@ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts ) {
'@.*?@su',
'@.*?@su',
'@.*?@su',
- '@\n( {2,}|\t)[^\*\- ].*?\n@su',
+ '@^( {2,}|\t)[^\*\- ].*?$@mu',
'@]*?>.*?<\/code>@su',
'@]*?>.*?<\/file>@su'
)
From ef15339b0c352d3fabd49c7570e35dc38e139885 Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Sun, 6 Mar 2016 22:20:36 -0800
Subject: [PATCH 23/44] Fix false wanted of implied start pages like [[wiki:]]
---
helper.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/helper.php b/helper.php
index 61c0585..2e02e2d 100644
--- a/helper.php
+++ b/helper.php
@@ -130,7 +130,7 @@ function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts ) {
and ! preg_match('!^#.+!',$link) // inside page link (html anchor)
) {
# remove parameters
- $link = preg_replace('/\?.*/', '', $link) . "\n";
+ $link = preg_replace('/\?.*/', '', $link);
$pageExists = false;
resolve_pageid($currentNS, $link, $pageExists );
From 9169bc609b74c22bb63f90926329b63ae1dcbf2c Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Sun, 6 Mar 2016 23:42:59 -0800
Subject: [PATCH 24/44] Allow the character to be in the syntax pattern
---
syntax.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/syntax.php b/syntax.php
index 17e861a..7adabd5 100644
--- a/syntax.php
+++ b/syntax.php
@@ -48,7 +48,7 @@ function getSort(){
* Connect pattern to lexer
*/
function connectTo($mode) {
- $this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[\w:!]+~~', $mode, 'plugin_orphanswanted');
+ $this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[\w:!-]+~~', $mode, 'plugin_orphanswanted');
}
/**
From bb00354e75ede2faa34eeee44608685d6049cb6e Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Thu, 16 Jun 2016 03:24:34 +0200
Subject: [PATCH 25/44] Update version info
---
plugin.info.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugin.info.txt b/plugin.info.txt
index 19b022f..f24ce3c 100644
--- a/plugin.info.txt
+++ b/plugin.info.txt
@@ -1,7 +1,7 @@
base orphanswanted
author Doug Edmunds, Cyrille37, Federico Ariel Castagnini, Andy Webber, Matthias Schulte
email dokuwiki@lupo49.de
-date 2012-12-05
+date 2016-03-07
name orphanswanted plugin
desc Display Orphans, Wanteds and Valid link information
url http://dokuwiki.org/plugin:orphanswanted
From d41d7525438da12055fb0a91e47cc747df6073c4 Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Mon, 27 Jun 2016 22:30:14 +0200
Subject: [PATCH 26/44] Ignore pages hidden by the global configuration
config:hidepages; solves #30
---
helper.php | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/helper.php b/helper.php
index 2e02e2d..6e574c1 100644
--- a/helper.php
+++ b/helper.php
@@ -253,8 +253,11 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
$show_it = true;
if(!is_null($ignoredPages) && in_array($id, $ignoredPages)) {
- echo "Skipped page (global ignored): " . $id . " ";
- $show_it = false;
+ echo "Skipped page (global ignored): " . $id . " ";
+ $show_it = false;
+ } elseif(isHiddenPage($id)) {
+ echo "Skipped page (global hidden): " . $id . " ";
+ $show_it = false;
} else {
foreach ($exclude_array as $exclude_item) {
//add a trailing : to each $item too
From 27b14293d1fa6a564cd77462f1aae1c20c4c8ebf Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Mon, 27 Jun 2016 22:35:38 +0200
Subject: [PATCH 27/44] Update version info
---
plugin.info.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plugin.info.txt b/plugin.info.txt
index f24ce3c..0eb5200 100644
--- a/plugin.info.txt
+++ b/plugin.info.txt
@@ -1,7 +1,7 @@
base orphanswanted
author Doug Edmunds, Cyrille37, Federico Ariel Castagnini, Andy Webber, Matthias Schulte
email dokuwiki@lupo49.de
-date 2016-03-07
+date 2016-06-27
name orphanswanted plugin
desc Display Orphans, Wanteds and Valid link information
url http://dokuwiki.org/plugin:orphanswanted
From 0d2b65e43bb37e656bebceab114d5fdb222545fb Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Tue, 5 Jul 2016 20:08:13 +0200
Subject: [PATCH 28/44] Hotfix: Stop exposing IDs of hidden pages
---
helper.php | 4 ++--
plugin.info.txt | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/helper.php b/helper.php
index 6e574c1..91d0479 100644
--- a/helper.php
+++ b/helper.php
@@ -253,10 +253,10 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
$show_it = true;
if(!is_null($ignoredPages) && in_array($id, $ignoredPages)) {
- echo "Skipped page (global ignored): " . $id . " ";
+ if ($conf['allowdebug']) echo "Skipped page (global ignored): " . $id . " ";
$show_it = false;
} elseif(isHiddenPage($id)) {
- echo "Skipped page (global hidden): " . $id . " ";
+ if ($conf['allowdebug']) echo "Skipped page (global hidden): " . $id . " ";
$show_it = false;
} else {
foreach ($exclude_array as $exclude_item) {
diff --git a/plugin.info.txt b/plugin.info.txt
index 0eb5200..68c78f2 100644
--- a/plugin.info.txt
+++ b/plugin.info.txt
@@ -1,7 +1,7 @@
base orphanswanted
author Doug Edmunds, Cyrille37, Federico Ariel Castagnini, Andy Webber, Matthias Schulte
email dokuwiki@lupo49.de
-date 2016-06-27
+date 2016-07-05
name orphanswanted plugin
desc Display Orphans, Wanteds and Valid link information
url http://dokuwiki.org/plugin:orphanswanted
From 5085610261663fce54ae20babfb50e005fca9c2d Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Sun, 25 Jun 2017 21:23:56 +0200
Subject: [PATCH 29/44] Always sort namespaces but don't sort for links when
listing orphans.
---
helper.php | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/helper.php b/helper.php
index 91d0479..5235479 100644
--- a/helper.php
+++ b/helper.php
@@ -235,7 +235,14 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
. ''
. "\n" ;
- arsort($data);
+ // Sort by namespace and name
+ ksort($data);
+
+ // Sort descending by existing links.
+ // This does not make sense for orphans since they don't have links.
+ if ($caller != "orphan") {
+ arsort($data);
+ }
foreach($data as $id=>$item) {
if( ! (($item['exists'] == $page_exists) and (($item['links'] <> 0)== $has_links)) ) continue ;
From 163625fde6fc05d878b95022f25f02ce323da36d Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Sun, 25 Jun 2017 23:15:59 +0200
Subject: [PATCH 30/44] Adapted the commit a1d1970 of @rikblok implementing
@include. Fixes #8
---
README | 4 ++--
helper.php | 32 +++++++++++++++++++++++++++-----
plugin.info.txt | 4 ++--
syntax.php | 17 +++++++++++++----
4 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/README b/README
index 5b6ab25..cd072fb 100644
--- a/README
+++ b/README
@@ -8,7 +8,7 @@ All documentation for the Orphanswanted Plugin is available online at:
(c) 2008-2009 Andy Webber
(c) 2009 Federico Ariel Castagnini
(c) 2010 Cyrille37
+(c) Rik Blok
+(c) Christian Paul
See COPYING for license info.
-
-
diff --git a/helper.php b/helper.php
index 91d0479..16b7837 100644
--- a/helper.php
+++ b/helper.php
@@ -6,6 +6,8 @@
* @author Federico Ariel Castagnini
* @author Cyrille37
* @author Matthias Schulte
+ * @author Rik Blok
+ * @author Christian Paul
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
@@ -222,7 +224,8 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
$show_heading = ($page_exists && $conf['useheading']) ? true : false ;
//take off $params_array[0];
- $exclude_array = array_slice($params_array,1);
+ $include_array = $params_array[1];
+ $exclude_array = $params_array[2];
$count = 1;
$output = '';
@@ -249,8 +252,25 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
//add a trailing :
$page_namespace = $page_namespace . ':';
- //set it to show, unless blocked by exclusion list
- $show_it = true;
+ if (empty($include_array)) {
+ // if inclusion list is empty then show all namespaces
+ $show_it = true;
+ } else {
+ // otherwise only show if in inclusion list
+ $show_it = false;
+ foreach ($include_array as $include_item) {
+ //add a trailing : to each $item too
+ $include_item = $include_item . ":";
+ // need === to avoid boolean false
+ // strpos(haystack, needle)
+ // if exclusion is beginning of page's namespace, block it
+ if (strpos($page_namespace, $include_item) === 0) {
+ //there is a match, so show it and move on
+ $show_it = true;
+ break;
+ }
+ }
+ }
if(!is_null($ignoredPages) && in_array($id, $ignoredPages)) {
if ($conf['allowdebug']) echo "Skipped page (global ignored): " . $id . " ";
@@ -258,7 +278,8 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
} elseif(isHiddenPage($id)) {
if ($conf['allowdebug']) echo "Skipped page (global hidden): " . $id . " ";
$show_it = false;
- } else {
+ } elseif ( $show_it ) {
+ //check if blocked by exclusion list
foreach ($exclude_array as $exclude_item) {
//add a trailing : to each $item too
$exclude_item = $exclude_item . ":";
@@ -266,8 +287,9 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
// strpos(haystack, needle)
// if exclusion is beginning of page's namespace , block it
if (strpos($page_namespace, $exclude_item) === 0) {
- //there is a match, so block it
+ //there is a match, so block it and move on
$show_it = false;
+ break;
}
}
}
diff --git a/plugin.info.txt b/plugin.info.txt
index 68c78f2..e646843 100644
--- a/plugin.info.txt
+++ b/plugin.info.txt
@@ -1,7 +1,7 @@
base orphanswanted
author Doug Edmunds, Cyrille37, Federico Ariel Castagnini, Andy Webber, Matthias Schulte
email dokuwiki@lupo49.de
-date 2016-07-05
+date 2017-06-25
name orphanswanted plugin
-desc Display Orphans, Wanteds and Valid link information
+desc Display Orphans, Wanteds and Valid link tables
url http://dokuwiki.org/plugin:orphanswanted
diff --git a/syntax.php b/syntax.php
index 7adabd5..2668111 100644
--- a/syntax.php
+++ b/syntax.php
@@ -2,7 +2,8 @@
/**
* OrphansWanted Plugin: Display Orphans, Wanteds and Valid link information
*
- * syntax ~~ORPHANSWANTED:[!]~~ :: orphans | wanted | valid | all
+ * syntax ~~ORPHANSWANTED:[@][!]~~ :: orphans | wanted | valid | all
+ * [@] :: optional. prefix each with @ e.g., @wiki@comments:currentyear (defaults to all namespaces if not specified)
* [!] :: optional. prefix each with ! e.g., !wiki!comments:currentyear
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
@@ -10,6 +11,8 @@
* @author Andy Webber
* @author Federico Ariel Castagnini
* @author Cyrille37
+ * @author Rik Blok
+ * @author Christian Paul
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
@@ -48,7 +51,7 @@ function getSort(){
* Connect pattern to lexer
*/
function connectTo($mode) {
- $this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[\w:!-]+~~', $mode, 'plugin_orphanswanted');
+ $this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[\w:@!-]+~~', $mode, 'plugin_orphanswanted');
}
/**
@@ -61,7 +64,14 @@ function handle($match, $state, $pos, Doku_Handler $handler){
// Wolfgang 2007-08-29 suggests commenting out the next line
// $match = strtolower($match);
//create array, using ! as separator
- $match_array = explode("!", $match);
+ // eg: $match = 'all@includens!excludens'
+ $match_in = explode("@", $match); // eg: $match_array = array(); $match_in = array('all', 'includens!excludens')
+ $match_ex = explode("!",array_pop($match_in)); // eg: $match_array = array(); $match_in = array('all'); $match_ex = array('includens', 'excludens')
+ array_push($match_in,array_shift($match_ex)); // eg: $match_array = array(); $match_in = array('all', 'includens'); $match_ex = array('excludens')
+ $match_array[0] = array_shift($match_in); // eg: $match_array = array('all'); $match_in = array('includens'); $match_ex = array('excludens')
+ $match_array[1] = $match_in; // eg: $match_array = array('all', array('includens')); $match_ex = array('excludens')
+ $match_array[2] = $match_ex; // eg: $match_array = array('all', array('includens'), array('excludens'))
+
// $match_array[0] will be orphan, wanted, valid, all, or syntax error
// if there are excluded namespaces, they will be in $match_array[1] .. [x]
// this return value appears in render() as the $data param there
@@ -99,7 +109,6 @@ function render($format, Doku_Renderer $renderer, $data) {
break;
default:
$renderer->doc .= "ORPHANSWANTED syntax error";
- // $renderer->doc .= "syntax ~~ORPHANSWANTED:~~ :: orphans|wanted|valid|all Ex: ~~ORPHANSWANTED:valid~~";
}
return true;
}
From a057218344a65a85914a9e196d61ae08e85b33f4 Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Sun, 25 Jun 2017 23:28:43 +0200
Subject: [PATCH 31/44] Update README
Translate to Markdown.
---
README | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/README b/README
index cd072fb..d20e41b 100644
--- a/README
+++ b/README
@@ -1,14 +1,14 @@
-====== Orphanswanted Plugin for DokuWiki ======
+# Orphanswanted Plugin for DokuWiki
All documentation for the Orphanswanted Plugin is available online at:
- * http://dokuwiki.org/plugin:orphanswanted
+ * http://dokuwiki.org/plugin:orphanswanted
-(c) 2006-2008 Doug Edmunds
-(c) 2008-2009 Andy Webber
-(c) 2009 Federico Ariel Castagnini
-(c) 2010 Cyrille37
-(c) Rik Blok
-(c) Christian Paul
+(c) 2006-2008 Doug Edmunds
+(c) 2008-2009 Andy Webber
+(c) 2009 Federico Ariel Castagnini
+(c) 2010 Cyrille37
+(c) Rik Blok
+(c) Christian Paul
See COPYING for license info.
From b0cf01740bd613e25055426d4d01e86147992f74 Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Sun, 25 Jun 2017 23:31:23 +0200
Subject: [PATCH 32/44] Update README
Added years for to contributers
---
README | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README b/README
index d20e41b..07df291 100644
--- a/README
+++ b/README
@@ -8,7 +8,7 @@ All documentation for the Orphanswanted Plugin is available online at:
(c) 2008-2009 Andy Webber
(c) 2009 Federico Ariel Castagnini
(c) 2010 Cyrille37
-(c) Rik Blok
-(c) Christian Paul
+(c) 2011 Rik Blok
+(c) 2016-2017 Christian Paul
See COPYING for license info.
From 3bd865f6859635d582a4a835e2d28019ec6134bd Mon Sep 17 00:00:00 2001
From: Thomas Christlieb
Date: Tue, 7 Nov 2017 19:58:33 +0100
Subject: [PATCH 33/44] Make sure is lowercase. Fixes #35
---
helper.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/helper.php b/helper.php
index 50e7ad3..33b9161 100644
--- a/helper.php
+++ b/helper.php
@@ -42,6 +42,9 @@ function orph_callback_search_wanted(&$data, $base, $file, $type, $lvl, $opts) {
// get id of this file
$id = pathID($file);
+ // make sure ID is lowercase
+ $id = utf8_strtolower($id);
+
//check ACL
if(auth_quickaclcheck($id) < AUTH_READ) {
return false;
From ef490c7273d34e462cfb56c812f9bd1219c98ba3 Mon Sep 17 00:00:00 2001
From: alexdraconian <78018187+alexdraconian@users.noreply.github.com>
Date: Sun, 2 Jan 2022 11:14:24 +0900
Subject: [PATCH 34/44] Use indexer to find all links
---
helper.php | 194 ++++++++++-------------------------------------------
1 file changed, 34 insertions(+), 160 deletions(-)
diff --git a/helper.php b/helper.php
index 33b9161..dfa59b8 100644
--- a/helper.php
+++ b/helper.php
@@ -14,198 +14,71 @@
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_INC.'inc/search.php');
+require_once(DOKU_INC.'inc/search/Indexer.php');
class helper_plugin_orphanswanted extends DokuWiki_Plugin {
- function orph_callback_search_wanted(&$data, $base, $file, $type, $lvl, $opts) {
-
- if($type == 'd') {
- return true; // recurse all directories, but we don't store namespaces
- }
-
- if(!preg_match("/.*\.txt$/", $file)) {
- // Ignore everything but TXT
- return true;
- }
-
- // search the body of the file for links
- // dae mod
- // orph_Check_InternalLinks(&$data,$base,$file,$type,$lvl,$opts);
- $this->orph_Check_InternalLinks($data,$base,$file,$type,$lvl,$opts);
-
- $eventData = array(
- 'data' => &$data,
- 'file' => $file
- );
- trigger_event('PLUGIN_ORPHANS_WANTED_PROCESS_PAGE', $eventData);
-
- // get id of this file
- $id = pathID($file);
-
- // make sure ID is lowercase
- $id = utf8_strtolower($id);
-
- //check ACL
- if(auth_quickaclcheck($id) < AUTH_READ) {
- return false;
- }
-
- // try to avoid making duplicate entries for forms and pages
- $item = &$data["$id"];
-
- if(isset($item)) {
- // This item already has a member in the array
- // Note that the file search found it
- $item['exists'] = true;
- } else {
- // Create a new entry
- $data["$id"]=array('exists' => true, 'links' => 0);
- }
- return true;
- }
-
- function orph_handle_link(&$data, $link) {
- global $conf;
-
- if(isset($data[$link])) {
- // This item already has a member in the array
- // Note that the file search found it
- $data[$link]['links'] ++ ; // count the link
- } else {
- // Create a new entry
- $data[$link] = array(
- 'exists' => false, // Only found a link, not the file
- 'links' => 1
- );
- // echo " \n";
- }
-
- if ($conf['allowdebug']) echo "-- New count for link " . $link . ": " . $data[$link]['links'] . " \n";
- }
-
+ // three choices
+ // $params_array used to extract excluded namespaces for report
+ // orphans = orph_report_table($data, true, false, $params_array);
+ // wanted = orph_report_table($data, false, true), $params_array;
+ // valid = orph_report_table($data, true, true, $params_array);
/**
- * Search for internal wiki links in page $file
+ * Find all page list with wiki's internal indexer.
*/
- function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts ) {
- global $conf;
-
- if (!defined('LINK_PATTERN')) define('LINK_PATTERN', '%\[\[([^\]|#]*)(#[^\]|]*)?\|?([^\]]*)]]%');
-
- if(!preg_match("/.*\.txt$/", $file)) {
- return;
- }
-
- $currentID = pathID($file);
- $currentNS = getNS($currentID);
-
- if($conf['allowdebug']) echo sprintf("%s: %s \n", $file, $currentID);
-
- // echo " \n";
- $body = @file_get_contents($conf['datadir'] . $file);
-
- // ignores entries in blocks that ignore links
- foreach( array(
- '@.*?<\/nowiki>@su',
- '@%%.*?%%@su',
- '@.*?@su',
- '@.*?@su',
- '@.*?@su',
- '@.*?@su',
- '@^( {2,}|\t)[^\*\- ].*?$@mu',
- '@]*?>.*?<\/code>@su',
- '@]*?>.*?<\/file>@su'
- )
- as $ignored )
- {
- $body = preg_replace($ignored, '', $body);
- }
-
- $links = array();
- preg_match_all( LINK_PATTERN, $body, $links );
-
- foreach($links[1] as $link) {
- if($conf['allowdebug']) echo sprintf("--- Checking %s \n", $link);
-
- if( (0 < strlen(ltrim($link)))
- and ! preg_match('/^[a-zA-Z0-9\.]+>{1}.*$/u',$link) // Interwiki
- and ! preg_match('/^\\\\\\\\[\w.:?\-;,]+?\\\\/u',$link) // Windows Share
- and ! preg_match('#^([a-z0-9\-\.+]+?)://#i',$link) // external link (accepts all protocols)
- and ! preg_match('<'.PREG_PATTERN_VALID_EMAIL.'>',$link) // E-Mail (pattern above is defined in inc/mail.php)
- and ! preg_match('!^#.+!',$link) // inside page link (html anchor)
- ) {
- # remove parameters
- $link = preg_replace('/\?.*/', '', $link);
-
- $pageExists = false;
- resolve_pageid($currentNS, $link, $pageExists );
- if ($conf['allowdebug']) echo sprintf("---- link='%s' %s ", $link, $pageExists?'EXISTS':'MISS');
-
- if(((strlen(ltrim($link)) > 0) // there IS an id?
- and !auth_quickaclcheck($link) < AUTH_READ)) {
- // should be visible to user
- //echo " \n";
-
- if($conf['allowdebug']) echo ' A_LINK' ;
-
- $link= utf8_strtolower( $link );
- $this->orph_handle_link($data, $link);
- }
- else
- {
- if($conf['allowdebug']) echo ' EMPTY_OR_FORBIDDEN' ;
+ function _get_page_data() {
+ $all_pages = idx_get_indexer()->getPages();
+ $pages = array();
+ foreach($all_pages as $pageid) {
+ $pages[$pageid] = array("exists"=>1, "links"=>0);
+ }
+
+ foreach($all_pages as $pageid) {
+
+ $relation_data = p_get_metadata($pageid)['relation']['references'];
+ if (!is_null($relation_data)) {
+ foreach($relation_data as $name => $exist) {
+ $pages[$name]['exist'] = $exist;
+ $pages[$name]['links'] += 1;
}
- } // link is not empty and is a local link?
- else {
- if($conf['allowdebug']) echo ' NOT_INTERNAL';
}
+ }
- if($conf['allowdebug']) echo " \n";
- } // end of foreach link
+ return $pages;
}
- // three choices
- // $params_array used to extract excluded namespaces for report
- // orphans = orph_report_table($data, true, false, $params_array);
- // wanted = orph_report_table($data, false, true), $params_array;
- // valid = orph_report_table($data, true, true, $params_array);
-
function orphan_pages($params_array) {
- global $conf, $ID;
+ $data = $this->_get_page_data();
+
$result = '';
- $data = array();
- search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => getNS($ID)));
$result .= $this->orph_report_table($data, true, false, $params_array, 'orphan');
return $result;
}
function wanted_pages($params_array) {
- global $conf, $ID;
+ $data = $this->_get_page_data();
+
$result = '';
- $data = array();
- search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => getNS($ID)));
- $result .= $this->orph_report_table($data, false, true, $params_array, 'wanted');
+ $result .= $this->orph_report_table($data, false, true, $params_array, 'wanted');
return $result;
}
function valid_pages($params_array) {
- global $conf, $ID;
+ $data = $this->_get_page_data();
+
$result = '';
- $data = array();
- search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted'), array('ns' => getNS($ID)));
- $result .= $this->orph_report_table($data, true, true, $params_array, 'valid');
+ $result .= $this->orph_report_table($data, false, true, $params_array, 'wanted');
return $result;
}
function all_pages($params_array) {
- global $conf, $ID;
- $result = '';
- $data = array();
- search($data,$conf['datadir'], array($this, 'orph_callback_search_wanted') , array('ns' => getNS($ID)));
+ $data = $this->_get_page_data();
+ $result = '';
$result .= " Orphans ";
$result .= $this->orph_report_table($data, true, false, $params_array, 'orphan');
$result .= " Wanted ";
@@ -251,6 +124,7 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
}
foreach($data as $id=>$item) {
+
if( ! (($item['exists'] == $page_exists) and (($item['links'] <> 0)== $has_links)) ) continue ;
// $id is a string, looks like this: page, namespace:page, or namespace::page
From 50b49d40869797cc5c0af24f184d75bc2f455b87 Mon Sep 17 00:00:00 2001
From: alexdraconian <78018187+alexdraconian@users.noreply.github.com>
Date: Sun, 2 Jan 2022 16:34:14 +0900
Subject: [PATCH 35/44] error fix
---
helper.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/helper.php b/helper.php
index dfa59b8..0b72ed9 100644
--- a/helper.php
+++ b/helper.php
@@ -70,7 +70,7 @@ function valid_pages($params_array) {
$data = $this->_get_page_data();
$result = '';
- $result .= $this->orph_report_table($data, false, true, $params_array, 'wanted');
+ $result .= $this->orph_report_table($data, false, true, $params_array, 'valid');
return $result;
}
From d209e0918f02ca3723b6679b4f4cfcb21d0dbcca Mon Sep 17 00:00:00 2001
From: alexdraconian <78018187+alexdraconian@users.noreply.github.com>
Date: Sun, 2 Jan 2022 16:35:54 +0900
Subject: [PATCH 36/44] error fix
---
helper.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/helper.php b/helper.php
index 0b72ed9..a87ef68 100644
--- a/helper.php
+++ b/helper.php
@@ -70,7 +70,7 @@ function valid_pages($params_array) {
$data = $this->_get_page_data();
$result = '';
- $result .= $this->orph_report_table($data, false, true, $params_array, 'valid');
+ $result .= $this->orph_report_table($data, true, true, $params_array, 'valid');
return $result;
}
From 5775dcdabaefa3ba77bdeb3d441462d0b9a3aa78 Mon Sep 17 00:00:00 2001
From: alexdraconian <78018187+alexdraconian@users.noreply.github.com>
Date: Mon, 3 Jan 2022 23:18:08 +0900
Subject: [PATCH 37/44] Fix bug with non-exist page
Fix the bug that occures when indexer returns non-exist page.
---
helper.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/helper.php b/helper.php
index a87ef68..de8ef30 100644
--- a/helper.php
+++ b/helper.php
@@ -31,11 +31,13 @@ function _get_page_data() {
$all_pages = idx_get_indexer()->getPages();
$pages = array();
foreach($all_pages as $pageid) {
- $pages[$pageid] = array("exists"=>1, "links"=>0);
+ $pages[$pageid] = array("exists"=>page_exists($pageid), "links"=>0);
}
foreach($all_pages as $pageid) {
+ if (!page_exists($pageid)) continue;
+
$relation_data = p_get_metadata($pageid)['relation']['references'];
if (!is_null($relation_data)) {
foreach($relation_data as $name => $exist) {
From f4ee5bc6a033e881093bdf88ef30612948791aa5 Mon Sep 17 00:00:00 2001
From: alexdraconian <78018187+alexdraconian@users.noreply.github.com>
Date: Sat, 22 Jan 2022 23:37:04 +0900
Subject: [PATCH 38/44] Delete mis-inserted line
---
helper.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/helper.php b/helper.php
index de8ef30..50b2307 100644
--- a/helper.php
+++ b/helper.php
@@ -14,7 +14,6 @@
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_INC.'inc/search.php');
-require_once(DOKU_INC.'inc/search/Indexer.php');
class helper_plugin_orphanswanted extends DokuWiki_Plugin {
From ed253b9102dbbf1b8bf4fb3089db0f37cfeee4c7 Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Tue, 30 May 2023 19:50:06 +0200
Subject: [PATCH 39/44] Don't import syntax.php, it's autoloaded
---
syntax.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/syntax.php b/syntax.php
index 2668111..e11a72d 100644
--- a/syntax.php
+++ b/syntax.php
@@ -17,7 +17,6 @@
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
-require_once(DOKU_PLUGIN.'syntax.php');
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
From 59f33fb856b6d7e13807a98bdad8b9dca895115b Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Tue, 30 May 2023 19:52:59 +0200
Subject: [PATCH 40/44] Update README.md
---
README => README.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
rename README => README.md (73%)
diff --git a/README b/README.md
similarity index 73%
rename from README
rename to README.md
index 07df291..20f13be 100644
--- a/README
+++ b/README.md
@@ -9,6 +9,7 @@ All documentation for the Orphanswanted Plugin is available online at:
(c) 2009 Federico Ariel Castagnini
(c) 2010 Cyrille37
(c) 2011 Rik Blok
-(c) 2016-2017 Christian Paul
+(c) 2016-2023 Christian Paul
+(c) 2022 alexdraconian <78018187+alexdraconian@users.noreply.github.com>
See COPYING for license info.
From ef94f81ae1a6036f4d7bcaab40b347946b15a58c Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Tue, 30 May 2023 19:54:34 +0200
Subject: [PATCH 41/44] Fix unknown array key errors; Add alexdraconian as an
author
---
helper.php | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/helper.php b/helper.php
index 50b2307..0cb152c 100644
--- a/helper.php
+++ b/helper.php
@@ -5,9 +5,10 @@
* @author Andy Webber
* @author Federico Ariel Castagnini
* @author Cyrille37
- * @author Matthias Schulte
+ * @author Matthias Schulte
* @author Rik Blok
* @author Christian Paul
+ * @author alexdraconian <78018187+alexdraconian@users.noreply.github.com>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
@@ -31,17 +32,17 @@ function _get_page_data() {
$pages = array();
foreach($all_pages as $pageid) {
$pages[$pageid] = array("exists"=>page_exists($pageid), "links"=>0);
- }
+ }
foreach($all_pages as $pageid) {
if (!page_exists($pageid)) continue;
- $relation_data = p_get_metadata($pageid)['relation']['references'];
+ $relation_data = p_get_metadata($pageid, 'relation references', METADATA_DONT_RENDER);
if (!is_null($relation_data)) {
- foreach($relation_data as $name => $exist) {
- $pages[$name]['exist'] = $exist;
- $pages[$name]['links'] += 1;
+ foreach($relation_data as $name => $exists) {
+ $pages[$name]['exists'] = $exists;
+ $pages[$name]['links'] = isset($pages[$name]['links']) ? $pages[$name]['links'] + 1 : 1;
}
}
}
@@ -126,7 +127,7 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
foreach($data as $id=>$item) {
- if( ! (($item['exists'] == $page_exists) and (($item['links'] <> 0)== $has_links)) ) continue ;
+ if( ! ((array_key_exists('exists', $item)) and ($item['exists'] == $page_exists) and (array_key_exists('links', $item)) and (($item['links'] <> 0)== $has_links)) ) continue ;
// $id is a string, looks like this: page, namespace:page, or namespace::page
$match_array = explode(":", $id);
From 0e35d1f4c9e91bb0691f867b4c5056680555abcf Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Tue, 30 May 2023 19:55:25 +0200
Subject: [PATCH 42/44] 2023-05-30
---
plugin.info.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/plugin.info.txt b/plugin.info.txt
index e646843..045b167 100644
--- a/plugin.info.txt
+++ b/plugin.info.txt
@@ -1,7 +1,7 @@
base orphanswanted
-author Doug Edmunds, Cyrille37, Federico Ariel Castagnini, Andy Webber, Matthias Schulte
+author Doug Edmunds, Cyrille37, Federico Ariel Castagnini, Andy Webber, Matthias Schulte, Christian Paul, alexdraconian
email dokuwiki@lupo49.de
-date 2017-06-25
+date 2023-05-30
name orphanswanted plugin
desc Display Orphans, Wanteds and Valid link tables
url http://dokuwiki.org/plugin:orphanswanted
From e6dff5c94e14921f9bedf0cbeb17cde1bd657ada Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Tue, 30 May 2023 19:58:19 +0200
Subject: [PATCH 43/44] Remove noreply e-mail address
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 20f13be..96387f5 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,6 @@ All documentation for the Orphanswanted Plugin is available online at:
(c) 2010 Cyrille37
(c) 2011 Rik Blok
(c) 2016-2023 Christian Paul
-(c) 2022 alexdraconian <78018187+alexdraconian@users.noreply.github.com>
+(c) 2022 alexdraconian
See COPYING for license info.
From 54262becefb1608379094928a7776d8db4e215d3 Mon Sep 17 00:00:00 2001
From: Christian Paul
Date: Tue, 30 May 2023 19:58:43 +0200
Subject: [PATCH 44/44] Remove noreply e-mail address 2
---
helper.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/helper.php b/helper.php
index 0cb152c..8fac03e 100644
--- a/helper.php
+++ b/helper.php
@@ -8,7 +8,7 @@
* @author Matthias Schulte
* @author Rik Blok
* @author Christian Paul
- * @author alexdraconian <78018187+alexdraconian@users.noreply.github.com>
+ * @author alexdraconian
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
|