wiki:plugins_installes:orphanswanted
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
wiki:plugins_installes:orphanswanted [17/08/2009 15:31] – édition externe 127.0.0.1 | wiki:plugins_installes:orphanswanted [19/05/2012 00:19] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 11: | Ligne 11: | ||
Each table shows the reference count. | Each table shows the reference count. | ||
- | ===== Usage ===== | + | ===== Evolution |
- | **Basic** usage is to place the one of the following four lines into the page markup: | + | ==== version 2.5beta ==== |
- | < | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | </ | + | |
- | | + | |
- | **Enhanced** usage adds optional namespaces, each prefixed | + | **New version proposal** : 2010-02-18, version 2.5beta. \\ |
- | <code> | + | Some changes to do it working |
- | | + | |
- | Example | + | <code php> |
+ | <?php | ||
+ | /** | ||
+ | * OrphansWanted Plugin: Display Orphans, Wanteds and Valid link information | ||
+ | * version 2.5beta 2010-02-19 | ||
+ | * http:// | ||
+ | | ||
+ | * syntax ~~ORPHANSWANTED:< | ||
+ | * [!< | ||
+ | * @license | ||
+ | * @author | ||
+ | * Updated by Andy Webber to include comments from DokuWiki plugin page upto 2008-11-10 | ||
+ | */ | ||
+ | |||
+ | if(!defined(' | ||
+ | if(!defined(' | ||
+ | require_once(DOKU_PLUGIN.' | ||
+ | |||
+ | require_once(DOKU_INC.' | ||
+ | |||
+ | |||
+ | // | ||
- | | + | function orph_callback_search_wanted(& |
+ | |||
+ | if($type == ' | ||
+ | return true; // recurse all directories, | ||
+ | } | ||
+ | |||
+ | if(!preg_match("/ | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | // search the body of the file for links | ||
+ | // dae mod | ||
+ | // | ||
+ | orph_Check_InternalLinks($data, | ||
+ | |||
+ | // 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 = & | ||
+ | if(isset($item)) { | ||
+ | // This item already has a member in the array | ||
+ | // Note that the file search found it | ||
+ | $item[' | ||
+ | } else { | ||
+ | // Create a new entry | ||
+ | $data[" | ||
+ | ' | ||
+ | } | ||
+ | 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][' | ||
+ | // echo " | ||
+ | } else { | ||
+ | // Create a new entry | ||
+ | $data[$link] = array( | ||
+ | ' | ||
+ | ' | ||
+ | ); | ||
+ | // echo " | ||
+ | } | ||
+ | } | ||
- | Example -- exclude multiple namespaces: | ||
- | | + | /** |
+ | * Search for internal | ||
+ | */ | ||
+ | function orph_Check_InternalLinks( &$data, $base, $file, $type, $lvl, $opts ) | ||
+ | { | ||
+ | $dbg = false ; | ||
+ | define(' | ||
+ | |||
+ | if( ! preg_match("/ | ||
+ | { | ||
+ | return ; | ||
+ | } | ||
+ | |||
+ | if( $dbg ) echo '< | ||
+ | |||
+ | global $conf; | ||
+ | // echo " | ||
+ | $body = @file_get_contents($conf[' | ||
+ | |||
+ | // ignores entries in < | ||
+ | foreach( array( | ||
+ | '/< | ||
+ | '/ | ||
+ | '/< | ||
+ | ) | ||
+ | as $ignored ) | ||
+ | { | ||
+ | $body = preg_replace($ignored, | ||
+ | } | ||
+ | |||
+ | $links = array(); | ||
+ | preg_match_all( LINK_PATTERN, | ||
+ | |||
+ | foreach( $links[1] as $link ) | ||
+ | { | ||
+ | if( $dbg ) echo $link ; | ||
+ | |||
+ | if( (0 < strlen(ltrim($link))) | ||
+ | and ! preg_match('/ | ||
+ | and ! preg_match('/ | ||
+ | and ! preg_match('# | ||
+ | and ! preg_match('<' | ||
+ | and ! preg_match(' | ||
+ | ) { | ||
+ | |||
+ | $pageExists=false; | ||
+ | resolve_pageid(false, | ||
+ | //echo ' | ||
+ | |||
+ | if(((strlen(ltrim($link)) > 0) // there IS an id? | ||
+ | and !auth_quickaclcheck($link) < AUTH_READ)) { // should be visible to user | ||
+ | //echo " | ||
+ | |||
+ | if( $dbg ) echo ' A_LINK' | ||
+ | |||
+ | $link= strtolower( $link ); | ||
+ | orph_handle_link($data, | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | if( $dbg ) echo ' EMPTY_OR_FORBIDDEN' | ||
+ | } | ||
+ | } // link is not empty and is a local link? | ||
+ | else | ||
+ | { | ||
+ | if( $dbg ) echo ' NOT_INTERNAL'; | ||
+ | } | ||
+ | |||
+ | if( $dbg ) echo "< | ||
+ | |||
+ | } // end of foreach link | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | // -------------------- | ||
+ | |||
+ | /** | ||
+ | * All DokuWiki plugins to extend the parser/ | ||
+ | * need to inherit from this class | ||
+ | */ | ||
+ | class syntax_plugin_orphanswanted extends DokuWiki_Syntax_Plugin { | ||
+ | /** | ||
+ | * return some info | ||
+ | */ | ||
+ | function getInfo(){ | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | syntax ~~ORPHANSWANTED:< | ||
+ | < | ||
+ | < | ||
+ | ' | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * What kind of syntax are we? | ||
+ | */ | ||
+ | function getType(){ | ||
+ | return ' | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * What about paragraphs? | ||
+ | */ | ||
+ | function getPType(){ | ||
+ | return ' | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Where to sort in? | ||
+ | */ | ||
+ | function getSort(){ | ||
+ | return 990; //was 990 | ||
+ | } | ||
+ | |||
+ | |||
+ | /** | ||
+ | * Connect pattern to lexer | ||
+ | */ | ||
+ | function connectTo($mode) { | ||
+ | $this-> | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * Handle the match | ||
+ | */ | ||
+ | |||
+ | function handle($match, | ||
+ | $match_array = array(); | ||
+ | $match = substr($match, | ||
+ | // Wolfgang 2007-08-29 suggests commenting out the next line | ||
+ | $match = strtolower($match); | ||
+ | //create array, using ! as separator | ||
+ | $match_array = explode(" | ||
+ | // $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, | ||
+ | global $INFO, $conf; | ||
+ | if($format == ' | ||
+ | |||
+ | // user needs to add ~~NOCACHE~~ manually to page, to assure ACL rules are followed | ||
+ | // coding here is too late, it doesn' | ||
+ | // $renderer-> | ||
+ | |||
+ | // $data is an array | ||
+ | // $data[1]..[x] are excluded namespaces, $data[0] is the report type | ||
+ | //handle choices | ||
+ | switch ($data[0]){ | ||
+ | case ' | ||
+ | $renderer-> | ||
+ | break; | ||
+ | case ' | ||
+ | $renderer-> | ||
+ | break; | ||
+ | case ' | ||
+ | $renderer-> | ||
+ | break; | ||
+ | case ' | ||
+ | $renderer-> | ||
+ | break; | ||
+ | default: | ||
+ | $renderer-> | ||
+ | // $renderer-> | ||
+ | } | ||
+ | |||
+ | | ||
+ | } | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | |||
+ | // three choices | ||
+ | // $params_array used to extract excluded namespaces for report | ||
+ | // orphans = orph_report_table($data, | ||
+ | // wanted = orph_report_table($data, | ||
+ | // valid = orph_report_table($data, | ||
+ | |||
+ | |||
+ | function orphan_pages($params_array) { | ||
+ | global $conf; | ||
+ | $result = ''; | ||
+ | $data = array(); | ||
+ | search($data, | ||
+ | $result .= $this-> | ||
+ | |||
+ | return $result; | ||
+ | } | ||
+ | |||
+ | function wanted_pages($params_array) { | ||
+ | global $conf; | ||
+ | $result = ''; | ||
+ | $data = array(); | ||
+ | search($data, | ||
+ | $result .= $this-> | ||
+ | |||
+ | return $result; | ||
+ | } | ||
+ | |||
+ | function valid_pages($params_array) { | ||
+ | global $conf; | ||
+ | $result = ''; | ||
+ | $data = array(); | ||
+ | search($data, | ||
+ | $result .= $this-> | ||
+ | |||
+ | return $result; | ||
+ | } | ||
+ | |||
+ | function all_pages($params_array) { | ||
+ | global $conf; | ||
+ | $result = ''; | ||
+ | $data = array(); | ||
+ | search($data, | ||
+ | |||
+ | $result .= "</ | ||
+ | $result .= $this-> | ||
+ | $result .= "</ | ||
+ | $result .= $this-> | ||
+ | $result .= "</ | ||
+ | $result .= $this-> | ||
+ | |||
+ | |||
+ | return $result; | ||
+ | } | ||
+ | |||
+ | function orph_report_table( $data, $page_exists, | ||
+ | { | ||
+ | global $conf; | ||
+ | | ||
+ | $show_heading = ($page_exists && $conf[' | ||
+ | | ||
+ | //take off $params_array[0]; | ||
+ | $exclude_array = array_slice($params_array, | ||
+ | | ||
+ | $count = 1; | ||
+ | $output = ''; | ||
+ | | ||
+ | // for valid html - need to close the <p> that is feed before this | ||
+ | $output .= '</ | ||
+ | $output .= '< | ||
+ | . ($show_heading ? '< | ||
+ | . '< | ||
+ | ." | ||
+ | | ||
+ | arsort($data); | ||
+ | | ||
+ | foreach($data as $id=> | ||
+ | { | ||
+ | |||
+ | if( ! (($item[' | ||
+ | { | ||
+ | continue ; | ||
+ | } | ||
+ | |||
+ | // $id is a string, looks like this: page, namespace: | ||
+ | $match_array = explode(":", | ||
+ | //remove last item in array, the page identifier | ||
+ | $match_array = array_slice($match_array, | ||
+ | //put it back together | ||
+ | $page_namespace = implode (":", | ||
+ | //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, | ||
+ | // if exclusion is beginning of page's namespace , block it | ||
+ | if (strpos($page_namespace, | ||
+ | // | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | if( $show_it ) | ||
+ | { | ||
+ | $output .= "< | ||
+ | . " | ||
+ | . " | ||
+ | . $id .'</ | ||
+ | . ($show_heading ? '< | ||
+ | . '< | ||
+ | . ($has_links | ||
+ | ? "& | ||
+ | : '' | ||
+ | ) | ||
+ | . "</ | ||
+ | | ||
+ | $count++; | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | | ||
+ | $output .= "</ | ||
+ | //for valid html = need to reopen a <p> | ||
+ | $output .= '< | ||
+ | | ||
+ | return $output; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | ?> | ||
</ | </ | ||
wiki/plugins_installes/orphanswanted.1250515895.txt.gz · Dernière modification : 19/05/2012 00:16 (modification externe)