3 if ('cli' != php_sapi_name()) die();
5 #------------------------------------------------------------------------------
6 ini_set('memory_limit','128M');
7 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__
).'/../').'/');
8 require_once DOKU_INC
.'inc/init.php';
9 require_once DOKU_INC
.'inc/common.php';
10 require_once DOKU_INC
.'inc/search.php';
11 require_once DOKU_INC
.'inc/cliopts.php';
13 #------------------------------------------------------------------------------
15 print "Usage: wantedpages.php [wiki:namespace]
17 Outputs a list of wanted pages (pages which have
18 internal links but do not yet exist).
20 If the optional [wiki:namespace] is not provided,
21 defaults to the root wiki namespace
28 #------------------------------------------------------------------------------
29 define ('DW_DIR_CONTINUE',1);
30 define ('DW_DIR_NS',2);
31 define ('DW_DIR_PAGE',3);
33 #------------------------------------------------------------------------------
34 function dw_dir_filter($entry, $basepath) {
35 if ($entry == '.' ||
$entry == '..' ) {
36 return DW_DIR_CONTINUE
;
38 if ( is_dir($basepath . '/' . $entry) ) {
39 if ( strpos($entry, '_') === 0 ) {
40 return DW_DIR_CONTINUE
;
44 if ( preg_match('/\.txt$/',$entry) ) {
47 return DW_DIR_CONTINUE
;
50 #------------------------------------------------------------------------------
51 function dw_get_pages($dir) {
52 static $trunclen = NULL;
55 $trunclen = strlen($conf['datadir'].':');
58 if ( !is_dir($dir) ) {
59 fwrite( STDERR
, "Unable to read directory $dir\n");
65 while ( false !== ( $entry = readdir($dh) ) ) {
66 $status = dw_dir_filter($entry, $dir);
67 if ( $status == DW_DIR_CONTINUE
) {
69 } else if ( $status == DW_DIR_NS
) {
70 $pages = array_merge($pages, dw_get_pages($dir . '/' . $entry));
73 'id' => pathID(substr($dir.'/'.$entry,$trunclen)),
74 'file'=> $dir.'/'.$entry,
83 #------------------------------------------------------------------------------
84 function dw_internal_links($page) {
86 $instructions = p_get_instructions(file_get_contents($page['file']));
88 $cns = getNS($page['id']);
90 foreach($instructions as $ins){
91 if($ins[0] == 'internallink' ||
($conf['camelcase'] && $ins[0] == 'camelcaselink') ){
93 resolve_pageid($cns,$mid,$exists);
95 list($mid) = explode('#',$mid); //record pages without hashs
103 #------------------------------------------------------------------------------
104 $OPTS = Doku_Cli_Opts
::getOptions(__FILE__
,'h',array('help'));
106 if ( $OPTS->isError() ) {
107 fwrite( STDERR
, $OPTS->getMessage() . "\n");
111 if ( $OPTS->has('h') or $OPTS->has('help') ) {
116 $START_DIR = $conf['datadir'];
118 if ( $OPTS->numArgs() == 1 ) {
119 $START_DIR .= '/' . $OPTS->arg(0);
122 #------------------------------------------------------------------------------
123 $WANTED_PAGES = array();
125 foreach ( dw_get_pages($START_DIR) as $WIKI_PAGE ) {
126 $WANTED_PAGES = array_merge($WANTED_PAGES,dw_internal_links($WIKI_PAGE));
128 $WANTED_PAGES = array_unique($WANTED_PAGES);
131 foreach ( $WANTED_PAGES as $WANTED_PAGE ) {
132 print $WANTED_PAGE."\n";