Skip to content

Commit 163625f

Browse files
committed
Adapted the commit a1d1970 of @rikblok implementing @include. Fixes #8
1 parent 0d2b65e commit 163625f

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ All documentation for the Orphanswanted Plugin is available online at:
88
(c) 2008-2009 Andy Webber
99
(c) 2009 Federico Ariel Castagnini
1010
(c) 2010 Cyrille37 <cyrille37@gmail.com>
11+
(c) Rik Blok <rik dot blok at ubc dot ca>
12+
(c) Christian Paul <christian at chrpaul dot de>
1113

1214
See COPYING for license info.
13-
14-

helper.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* @author Federico Ariel Castagnini
77
* @author Cyrille37 <cyrille37@gmail.com>
88
* @author Matthias Schulte <dokuwiki@lupo49.de>
9+
* @author Rik Blok <rik dot blok at ubc dot ca>
10+
* @author Christian Paul <christian at chrpaul dot de>
911
*/
1012
// must be run within Dokuwiki
1113
if(!defined('DOKU_INC')) die();
@@ -222,7 +224,8 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
222224

223225
$show_heading = ($page_exists && $conf['useheading']) ? true : false ;
224226
//take off $params_array[0];
225-
$exclude_array = array_slice($params_array,1);
227+
$include_array = $params_array[1];
228+
$exclude_array = $params_array[2];
226229

227230
$count = 1;
228231
$output = '';
@@ -249,25 +252,44 @@ function orph_report_table($data, $page_exists, $has_links, $params_array, $call
249252
//add a trailing :
250253
$page_namespace = $page_namespace . ':';
251254

252-
//set it to show, unless blocked by exclusion list
253-
$show_it = true;
255+
if (empty($include_array)) {
256+
// if inclusion list is empty then show all namespaces
257+
$show_it = true;
258+
} else {
259+
// otherwise only show if in inclusion list
260+
$show_it = false;
261+
foreach ($include_array as $include_item) {
262+
//add a trailing : to each $item too
263+
$include_item = $include_item . ":";
264+
// need === to avoid boolean false
265+
// strpos(haystack, needle)
266+
// if exclusion is beginning of page's namespace, block it
267+
if (strpos($page_namespace, $include_item) === 0) {
268+
//there is a match, so show it and move on
269+
$show_it = true;
270+
break;
271+
}
272+
}
273+
}
254274

255275
if(!is_null($ignoredPages) && in_array($id, $ignoredPages)) {
256276
if ($conf['allowdebug']) echo "Skipped page (global ignored): " . $id . "<br />";
257277
$show_it = false;
258278
} elseif(isHiddenPage($id)) {
259279
if ($conf['allowdebug']) echo "Skipped page (global hidden): " . $id . "<br />";
260280
$show_it = false;
261-
} else {
281+
} elseif ( $show_it ) {
282+
//check if blocked by exclusion list
262283
foreach ($exclude_array as $exclude_item) {
263284
//add a trailing : to each $item too
264285
$exclude_item = $exclude_item . ":";
265286
// need === to avoid boolean false
266287
// strpos(haystack, needle)
267288
// if exclusion is beginning of page's namespace , block it
268289
if (strpos($page_namespace, $exclude_item) === 0) {
269-
//there is a match, so block it
290+
//there is a match, so block it and move on
270291
$show_it = false;
292+
break;
271293
}
272294
}
273295
}

plugin.info.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
base orphanswanted
22
author Doug Edmunds, Cyrille37, Federico Ariel Castagnini, Andy Webber, Matthias Schulte
33
email dokuwiki@lupo49.de
4-
date 2016-07-05
4+
date 2017-06-25
55
name orphanswanted plugin
6-
desc Display Orphans, Wanteds and Valid link information
6+
desc Display Orphans, Wanteds and Valid link tables
77
url http://dokuwiki.org/plugin:orphanswanted

syntax.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
/**
33
* OrphansWanted Plugin: Display Orphans, Wanteds and Valid link information
44
*
5-
* syntax ~~ORPHANSWANTED:<choice>[!<exclude list>]~~ <choice> :: orphans | wanted | valid | all
5+
* syntax ~~ORPHANSWANTED:<choice>[@<include list>][!<exclude list>]~~ <choice> :: orphans | wanted | valid | all
6+
* [@<include list>] :: optional. prefix each with @ e.g., @wiki@comments:currentyear (defaults to all namespaces if not specified)
67
* [!<exclude list>] :: optional. prefix each with ! e.g., !wiki!comments:currentyear
78
*
89
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
910
* @author <dae@douglasedmunds.com>
1011
* @author Andy Webber <dokuwiki at andywebber dot com>
1112
* @author Federico Ariel Castagnini
1213
* @author Cyrille37 <cyrille37@gmail.com>
14+
* @author Rik Blok <rik dot blok at ubc dot ca>
15+
* @author Christian Paul <christian at chrpaul dot de>
1316
*/
1417

1518
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
@@ -48,7 +51,7 @@ function getSort(){
4851
* Connect pattern to lexer
4952
*/
5053
function connectTo($mode) {
51-
$this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[\w:!-]+~~', $mode, 'plugin_orphanswanted');
54+
$this->Lexer->addSpecialPattern('~~ORPHANSWANTED:[\w:@!-]+~~', $mode, 'plugin_orphanswanted');
5255
}
5356

5457
/**
@@ -61,7 +64,14 @@ function handle($match, $state, $pos, Doku_Handler $handler){
6164
// Wolfgang 2007-08-29 suggests commenting out the next line
6265
// $match = strtolower($match);
6366
//create array, using ! as separator
64-
$match_array = explode("!", $match);
67+
// eg: $match = 'all@includens!excludens'
68+
$match_in = explode("@", $match); // eg: $match_array = array(); $match_in = array('all', 'includens!excludens')
69+
$match_ex = explode("!",array_pop($match_in)); // eg: $match_array = array(); $match_in = array('all'); $match_ex = array('includens', 'excludens')
70+
array_push($match_in,array_shift($match_ex)); // eg: $match_array = array(); $match_in = array('all', 'includens'); $match_ex = array('excludens')
71+
$match_array[0] = array_shift($match_in); // eg: $match_array = array('all'); $match_in = array('includens'); $match_ex = array('excludens')
72+
$match_array[1] = $match_in; // eg: $match_array = array('all', array('includens')); $match_ex = array('excludens')
73+
$match_array[2] = $match_ex; // eg: $match_array = array('all', array('includens'), array('excludens'))
74+
6575
// $match_array[0] will be orphan, wanted, valid, all, or syntax error
6676
// if there are excluded namespaces, they will be in $match_array[1] .. [x]
6777
// this return value appears in render() as the $data param there
@@ -99,7 +109,6 @@ function render($format, Doku_Renderer $renderer, $data) {
99109
break;
100110
default:
101111
$renderer->doc .= "ORPHANSWANTED syntax error";
102-
// $renderer->doc .= "syntax ~~ORPHANSWANTED:<choice>~~<optional_excluded> <choice> :: orphans|wanted|valid|all Ex: ~~ORPHANSWANTED:valid~~";
103112
}
104113
return true;
105114
}

0 commit comments

Comments
 (0)