diff options
author | petko <petko@524c5546-5005-0410-9a3e-e25e191bd360> | 2019-12-07 09:41:59 +0000 |
---|---|---|
committer | petko <petko@524c5546-5005-0410-9a3e-e25e191bd360> | 2019-12-07 09:41:59 +0000 |
commit | 90bf5e7475e51e8083e55ffc0da93c10c613e023 (patch) | |
tree | 25efd27b933f21b0f268cfb5830e9d8c0f34a47e /scripts/diag.php | |
parent | cb82d3dc71cdafa8ae6343e5fafe8801fa06b4f6 (diff) | |
download | pmwiki.svn-90bf5e7475e51e8083e55ffc0da93c10c613e023.tar.bz2 |
Mute a number of PHP notices for undefined variables. Add that "URL" means in browser in sample-config.php (PITS:01448). Fix PmXMail() to work for sidebars, headers and footers. Add RecipeCheck in diag.php.
git-svn-id: svn://pmwiki.org/pmwiki/trunk@3594 524c5546-5005-0410-9a3e-e25e191bd360
Diffstat (limited to 'scripts/diag.php')
-rw-r--r-- | scripts/diag.php | 116 |
1 files changed, 113 insertions, 3 deletions
diff --git a/scripts/diag.php b/scripts/diag.php index 257fe99e..314bb4f7 100644 --- a/scripts/diag.php +++ b/scripts/diag.php @@ -8,14 +8,14 @@ This file adds "?action=diag" and "?action=phpinfo" actions to PmWiki. This produces lots of diagnostic output that may be helpful to the software authors when debugging PmWiki or other scripts. - + Script maintained by Petko YOTOV www.pmwiki.org/petko */ -@ini_set('display_errors', '1'); -@ini_set('track_errors','1'); if ($action=='diag') { + @ini_set('track_errors','1'); + @ini_set('display_errors', '1'); @session_start(); header('Content-type: text/plain'); print_r($GLOBALS); @@ -60,3 +60,113 @@ function StopWatchHTML($pagename, $print = 0) { return $out; } +### From Cookbook:RecipeCheck +/* Copyright 2007-2019 Patrick R. Michaud (pmichaud@pobox.com) + + This recipe adds ?action=recipecheck to a site. When activated, + ?action=recipecheck fetches the current list of Cookbook recipes + and their versions from pmwiki.org. It then compares this list + with the versions of any installed recipes on the local site + and reports any differences. + + By default the recipe restricts ?action=recipecheck to admins. + + Note that not all recipes currently follow PmWiki's + recipecheck standard (feel free to report these to the pmwiki-users + mailing list). + + * 2007-04-17: Added suggestions by Feral + - explicit black text + - skip non-php files and directories + * 2019-11-28: Added to scripts/diag.php by Petko +*/ +SDV($HandleActions['recipecheck'], 'HandleRecipeCheckCore'); +SDV($HandleAuth['recipecheck'], 'admin'); +SDV($ActionTitleFmt['recipecheck'], '| $[Recipe Check]'); + +SDV($WikiStyleApply['tr'], 'tr'); +SDV($HTMLStylesFmt['recipecheck'], ' + table.recipecheck tr.ok { color:black; background-color:#ccffcc; } + table.recipecheck tr.check { color:black; background-color:#ffffcc; } + table.recipecheck { border:1px solid #cccccc; padding:4px; } +'); + +SDV($RecipeListUrl, 'http://www.pmwiki.org/pmwiki/recipelist'); + +function HandleRecipeCheckCore($pagename, $auth = 'admin') { + global $RecipeListUrl, $Version, $RecipeInfo, + $RecipeCheckFmt, $PageStartFmt, $PageEndFmt; + $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT); + if (!$page) Abort('?admin access required'); + $cvinfo = GetRecipeListCore($RecipeListUrl); + if (!$cvinfo) { + $msg = "Unable to retrieve cookbook data from $RecipeListUrl\n"; + $allow_url_fopen = ini_get('allow_url_fopen'); + if (!$allow_url_fopen) $msg .= " + <br /><br />It appears that your PHP environment isn't allowing + the recipelist to be downloaded from pmwiki.org + (allow_url_fopen = $allow_url_fopen)."; + Abort($msg); + } + $rinfo['PmWiki:Upgrades'] = $Version; + ScanRecipeInfoCore('cookbook', $cvinfo); + foreach((array)$RecipeInfo as $r => $v) { + if (!@$v['Version']) continue; + $r = preg_replace('/^(?!PmWiki:)(Cookbook[.:])?/', 'Cookbook:', $r); + $rinfo[$r] = $v['Version']; + } + $markup = "!!Recipe status for {\$PageUrl}\n".RecipeTableCore($rinfo, $cvinfo); + $html = MarkupToHTML($pagename, $markup); + SDV($RecipeCheckFmt, array(&$PageStartFmt, $html, &$PageEndFmt)); + PrintFmt($pagename, $RecipeCheckFmt); +} + + +function GetRecipeListCore($list) { + $cvinfo = array(); + $fp = fopen($list, 'r'); + while ($fp && !feof($fp)) { + $line = fgets($fp, 1024); + if ($line[0] == '#') continue; + if (preg_match('/(\\S+) +(.*)/', $line, $match)) + $cvinfo[$match[1]] = trim($match[2]); + } + fclose($fp); + return $cvinfo; +} + + +function ScanRecipeInfoCore($dlistfmt, $cvinfo = NULL) { + global $RecipeInfo; + foreach((array)$dlistfmt as $dir) { + $dfp = @opendir($dir); if (!$dfp) continue; + while ( ($name = readdir($dfp)) !== false) { + if ($name[0] == '.') continue; + if (!preg_match('/\\.php/i', $name)) continue; + $text = implode('', @file("$dir/$name")); + if (preg_match("/^\\s*\\\$RecipeInfo\\['(.*?)'\\]\\['Version'\\]\\s*=\\s*'(.*?)'\\s*;/m", $text, $match)) + SDV($RecipeInfo[$match[1]]['Version'], $match[2]); + if (preg_match("/^\\s*SDV\\(\\s*\\\$RecipeInfo\\['(.*?)'\\]\\['Version'\\]\\s*,\\s*'(.*?)'\\s*\\)\\s*\\;/m", $text, $match)) + SDV($RecipeInfo[$match[1]]['Version'], $match[2]); + if (@$cvinfo[$name]) { + $r = preg_replace('/^.*:/', '', $cvinfo[$name]); + SDV($RecipeInfo[$r]['Version'], "unknown ($name)"); + } + } + closedir($dfp); + } +} + + +function RecipeTableCore($rinfo, $cvinfo) { + $fmt = "||%-40s ||%-20s ||%-20s ||\n"; + $out = "||class=recipecheck cellpadding=0 cellspacing=0 width=600\n"; + $out .= sprintf($fmt, '!Recipe', '!local', '!pmwiki.org'); + foreach($rinfo as $r => $lv) { + $cv = @$cvinfo[$r]; + $style = ($lv == $cv) ? 'ok' : 'check'; + $out .= sprintf($fmt, "%apply=tr $style%[[$r]]", $lv, $cv); + } + return $out; +} + |