cvs: doc-editor /php ExtJsController.php ToolsCheckDoc.php class.php
| From: | Yannick Torres | Date: | Mon, 20 Apr 2009 18:59:46 +0000 |
| Subject: | cvs: doc-editor /php ExtJsController.php ToolsCheckDoc.php class.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-3818@lists.php.net to get a copy of this message | ||
yannick Mon Apr 20 18:59:46 2009 UTC
Added files:
/doc-editor/php ToolsCheckDoc.php
Modified files:
/doc-editor/php class.php ExtJsController.php
Log:
Implemente new ToolsCheckDoc class
http://cvs.php.net/viewvc.cgi/doc-editor/php/class.php?r1=1.36&r2=1.37&diff_format=u Index: doc-editor/php/class.php diff -u doc-editor/php/class.php:1.36 doc-editor/php/class.php:1.37 --- doc-editor/php/class.php:1.36 Sat Apr 18 22:16:53 2009 +++ doc-editor/php/class.php Mon Apr 20 18:59:46 2009 @@ -13,6 +13,7 @@ require_once dirname(__FILE__) . '/conf.inc.php'; require_once dirname(__FILE__) . '/LockFile.php'; require_once dirname(__FILE__) . '/ToolsError.php'; +require_once dirname(__FILE__) . '/ToolsCheckDoc.php'; class phpDoc { @@ -135,29 +136,14 @@ $en_revision = ($infoEN['rev'] == 'NULL') ? 'NULL' : "'".$infoEN['rev']."'"; $xmlid = ($infoEN['xmlid'] == 'NULL') ? 'NULL' : "'".$infoEN['xmlid']."'"; - // $this->Check_doc() ? is this dir is /reference/*/functions/ ? $tmp = explode('/', $dir); - if (isset($tmp[1]) && isset($tmp[3]) && $tmp[1] == 'reference' && $tmp[3] == 'functions' ) { - $check_doc = $this->check_doc($infoEN['content']); - - } else { - - $check_doc['check_oldstyle'] = 'NULL'; - $check_doc['check_undoc'] = 'NULL'; - $check_doc['check_roleerror'] = 'NULL'; - $check_doc['check_badorder'] = 'NULL'; - $check_doc['check_noseealso'] = 'NULL'; - $check_doc['check_noreturnvalues'] = 'NULL'; - $check_doc['check_noparameters'] = 'NULL'; - $check_doc['check_noexamples'] = 'NULL'; - $check_doc['check_noerrors'] = 'NULL'; - - } + $ToolsCheckDoc = new ToolsCheckDoc($this->db); + $ToolsCheckDocResult = $ToolsCheckDoc->checkDoc($infoEN['content'], $dir); // Sql insert. $s = "INSERT INTO files (lang, xmlid, dir, path, name, revision, size, mdate, maintainer, status, check_oldstyle, check_undoc, check_roleerror, check_badorder, check_noseealso, check_noreturnvalues, check_noparameters, check_noexamples,check_noerrors) - VALUES ('en', $xmlid, '$idDir', '$dir/', '$file', $en_revision, $en_size,$en_date, NULL, NULL, ".$check_doc['check_oldstyle'].", ".$check_doc['check_undoc'].", ".$check_doc['check_roleerror'].", ".$check_doc['check_badorder'].", ".$check_doc['check_noseealso'].", ".$check_doc['check_noreturnvalues'].", ".$check_doc['check_noparameters'].", ".$check_doc['check_noexamples'].", ".$check_doc['check_noerrors'].")"; + VALUES ('en', $xmlid, '$idDir', '$dir/', '$file', $en_revision, $en_size,$en_date, NULL, NULL, ".$ToolsCheckDocResult['check_oldstyle'].", ".$ToolsCheckDocResult['check_undoc'].", ".$ToolsCheckDocResult['check_roleerror'].", ".$ToolsCheckDocResult['check_badorder'].", ".$ToolsCheckDocResult['check_noseealso'].", ".$ToolsCheckDocResult['check_noreturnvalues'].", ".$ToolsCheckDocResult['check_noparameters'].", ".$ToolsCheckDocResult['check_noexamples'].", ".$ToolsCheckDocResult['check_noerrors'].")"; $this->db->query($s) or die('Error: '.$this->db->error); @@ -2048,7 +2034,7 @@ $t = explode('.',$a->name); $ext = $t[count($t)-1]; - $nodes[] = array('text'=>$a->lang.$a->path.$a->name, 'id'=>'//'.$a->lang.$a->path.$a->name, 'leaf'=>true, 'cls'=>'file', 'extension'=>$ext, 'type'=>'file'); + $nodes[] = array('text'=>$a->lang.$a->path.$a->name, 'id'=>'//'.$a->lang.$a->path.$a->name, 'leaf'=>true, 'cls'=>'file', 'extension'=>$ext, 'type'=>'file', 'from'=>'search'); } @@ -2160,264 +2146,6 @@ return $r->fetch_object(); } - function check_doc($content) { - - $return['check_oldstyle'] = 'NULL'; - $return['check_undoc'] = 'NULL'; - $return['check_roleerror'] = 'NULL'; - $return['check_badorder'] = 'NULL'; - $return['check_noseealso'] = 'NULL'; - $return['check_noreturnvalues'] = 'NULL'; - $return['check_noparameters'] = 'NULL'; - $return['check_noexamples'] = 'NULL'; - $return['check_noerrors'] = 'NULL'; - - $xmlstr = str_replace('&', '&', $content); - - $xml = new DOMDocument(); - $xml->preserveWhiteSpace = false; - - if (!@$xml->loadXml($xmlstr)) { - //echo "XML Parse Error: $function\n"; - return $return; - } - - // Variables initialisation - $noparameters = false; - $returnvoid = false; - - - $refsect1s = $xml->getElementsByTagName('refsect1'); - foreach ($refsect1s as $refsect1) { - $role = $refsect1->getAttribute('role'); - switch ($role) { - case 'description': - - // Get text buffer for various checks - $whole_description = $refsect1->nodeValue; - - // If not documented, mark it and skip to next function - if (strpos($whole_description, '&warn.undocumented.func;') !== false) { - $return['check_undoc'] = 1; - return $return; - } - - // If deprecated, skip to next function - // @todo: add a better way of handling this (new entity in phpdoc?) - if (strpos($whole_description, 'This function is deprecated') !== false) { - return $return; - } - - // If an alias, skip to next function - if (strpos($whole_description, '&info.function.alias;') !== false) { - return $return; - } else { - $refnamedivs = $xml->getElementsByTagName('refnamediv'); - foreach ($refnamedivs as $refnamediv) { - if (stripos($refnamediv->nodeValue, 'alias') !== false) { - return $return; - } - } - } - - // Look into the methodsynopsys tag(s) - $methodsynopsiss = $xml->getElementsByTagName('methodsynopsis'); - foreach ($methodsynopsiss as $methodsynopsis) { - foreach ($methodsynopsis->childNodes as $child) { - switch ($child->nodeName) { - case '#comment': - // Skip comments - continue; - - case 'type': - // This is the return type - break; - - case 'void': - // This either the return type or 0 parameters - if (!isset($methodname)) { - //$returnvoid = true; - } else { // no parameters - $noparameters = true; - } - break; - - case 'methodname': - $methodname = $child->nodeValue; - break; - - case 'methodparam': - case 'modifier': - break; - - default: - //echo "Unknown child for methodsynopsis: {$child->nodeName} in $function\n"; - } - } - } - - - break; - - case 'returnvalues': - case 'parameters': - case 'seealso': - case 'examples': - case 'notes': - case 'changelog': - case 'errors': - case 'unicode': - // test order - switch ($role) { - case 'parameters': - if (isset($notes) && isset($changelog) && isset($returnvalues) && isset($examples) && isset($seealso)) { - $return['check_badorder'] = 1; - } - break; - case 'returnvalues': - if (isset($notes) && isset($changelog) && isset($examples) && isset($seealso)) { - $return['check_badorder'] = 1; - } - break; - case 'changelog': - if (isset($notes) && isset($examples) && isset($seealso)) { - $return['check_badorder'] = 1; - } - break; - case 'examples': - if (isset($notes) && isset($seealso)) { - $return['check_badorder'] = 1; - } - break; - case 'notes': - if (isset($seealso)) { - $return['check_badorder'] = 1; - } - break; - } - $$role = 1; - $whole_content = $refsect1->nodeValue; - - // Check for default stub generated by xml_proto - if ($role == 'returnvalues' && strpos($whole_content, 'What the function returns, first on success, then on failure.') !== false) { - unset($returnvalues); - } - break; - - default: - if ($role != '') { - $check_doc['check_roleerror'] = 1; - } else { - $check_doc['check_oldstyle'] = 1; - // Skip the remaining refsect1 - return $return; - } - } - } - - // See also checks - if (!isset($seealso)) { - $return['check_noseealso'] = 1; - } - unset($seealso); - - // Return Values - if (!isset($returnvalues)) { - $return['check_noreturnvalues'] = 1; - } - unset($returnvalues); - - // Parameters - if (!isset($parameters) && !$noparameters) { - $return['check_noparameters'] = 1; - } - unset($parameters); - - // Examples checks - if (!isset($examples)) { - $return['check_noexamples'] = 1; - } - unset($examples); - - // Errors checks - if (!isset($errors)) { - $return['check_noerrors'] = 1; - } - unset($errors); - - return $return; - - } // check_doc - - function getCheckDocData() { - - $node = array(); - - $s = 'SELECT - path, - COUNT(*) AS total, - SUM(check_oldstyle) as total_check_oldstyle, - SUM(check_undoc) as total_check_undoc, - SUM(check_roleerror) as total_check_roleerror, - SUM(check_badorder) as total_check_badorder, - SUM(check_noseealso) as total_check_noseealso, - SUM(check_noreturnvalues) as total_check_noreturnvalues, - SUM(check_noparameters) as total_check_noparameters, - SUM(check_noexamples) as total_check_noexamples, - SUM(check_noerrors) as total_check_noerrors - - FROM files - - WHERE - `lang`=\'en\' AND - `path` REGEXP "^/reference/.*/functions/$" - - GROUP BY path - - ORDER BY path'; - - $r = $this->db->query($s); - $nb = $r->num_rows; - $i = 0; - while ($a = $r->fetch_object()) { - $i++; - - $tmp = explode('/', $a->path); - $extension = $tmp[2]; - - $node[] = array( - "id" => $i, - "extension" => ucFirst($extension), - "path" => $a->path, - "check_oldstyle" => ( !$a->total_check_oldstyle) ? 0 : (int)$a->total_check_oldstyle, - "check_undoc" => ( !$a->total_check_undoc) ? 0 : (int)$a->total_check_undoc, - "check_roleerror" => ( !$a->total_check_roleerror) ? 0 : (int)$a->total_check_roleerror, - "check_badorder" => ( !$a->total_check_badorder) ? 0 : (int)$a->total_check_badorder, - "check_noseealso" => ( !$a->total_check_noseealso) ? 0 : (int)$a->total_check_noseealso, - "check_noreturnvalues" => ( !$a->total_check_noreturnvalues) ? 0 : (int)$a->total_check_noreturnvalues, - "check_noparameters" => ( !$a->total_check_noparameters) ? 0 : (int)$a->total_check_noparameters, - "check_noexamples" => ( !$a->total_check_noexamples) ? 0 : (int)$a->total_check_noexamples, - "check_noerrors" => ( !$a->total_check_noerrors) ? 0 : (int)$a->total_check_noerrors - ); - - } // While - - return array('nb' => $nb, 'node' => $node); - - } //getCheckDocData - - function getCheckDocFiles($path, $errorType) - { - $s = sprintf('SELECT name FROM `files` WHERE `lang`="en" AND `path`="%s" AND `%s`=1', $path, $errorType); - $r = $this->db->query($s); - - $node = array(); - while ($row = $r->fetch_assoc()) { - $node[] = $row; - } - return $node; - } // get_Check_Doc_Files - /** * Get the last update datetime * @return The last update datetime or "in_progress" if the update is in progress http://cvs.php.net/viewvc.cgi/doc-editor/php/ExtJsController.php?r1=1.19&r2=1.20&diff_format=u Index: doc-editor/php/ExtJsController.php diff -u doc-editor/php/ExtJsController.php:1.19 doc-editor/php/ExtJsController.php:1.20 --- doc-editor/php/ExtJsController.php:1.19 Sun Apr 19 11:17:23 2009 +++ doc-editor/php/ExtJsController.php Mon Apr 20 18:59:46 2009 @@ -736,7 +736,8 @@ $this->phpDoc->isLogged(); - $r = $this->phpDoc->getCheckDocData(); + $ToolsCheckDoc = new ToolsCheckDoc($this->phpDoc->db); + $r = $ToolsCheckDoc->getCheckDocData(); return $this->getResponse(array('nbItems' => $r['nb'], 'Items' => $r['node'])); } @@ -748,7 +749,8 @@ $path = $this->getRequestVariable('path'); $errorType = $this->getRequestVariable('errorType'); - $r = $this->phpDoc->getCheckDocFiles($path, $errorType); + $ToolsCheckDoc = new ToolsCheckDoc($this->phpDoc->db); + $r = $ToolsCheckDoc->getCheckDocFiles($path, $errorType); return $this->getResponse(array('success' => true, 'files' => $r)); } http://cvs.php.net/viewvc.cgi/doc-editor/php/ToolsCheckDoc.php?view=markup&rev=1.1 Index: doc-editor/php/ToolsCheckDoc.php +++ doc-editor/php/ToolsCheckDoc.php <?php /** * A class for the check doc tools * Original check_phpdoc script have been written by didou <didou@php.net> * you can found it here : http://cvs.php.net/viewvc.cgi/phpdoc/scripts/check_phpdoc/ * */ class ToolsCheckDoc { /** * Database connection * * @var resource */ private $db; /** * Initialise * * @param string $db The database connection */ function __construct($db) { $this->db = $db; } /** * Get Files for a particular path and errorType. * * @param string $path The path for the files to retrieve * @param string $errorType The type of error to retrieve * @return An indexed array readable by ExtJs */ function getCheckDocFiles($path, $errorType) { $s = sprintf('SELECT name FROM `files` WHERE `lang`="en" AND `path`="%s" AND `%s`=1', $path, $errorType); $r = $this->db->query($s); $node = array(); while ($row = $r->fetch_assoc()) { $node[] = $row; } return $node; } /** * Get check doc data. * * @return An indexed array readable by ExtJs */ function getCheckDocData() { $node = array(); $s = 'SELECT path, COUNT(*) AS total, SUM(check_oldstyle) as total_check_oldstyle, SUM(check_undoc) as total_check_undoc, SUM(check_roleerror) as total_check_roleerror, SUM(check_badorder) as total_check_badorder, SUM(check_noseealso) as total_check_noseealso, SUM(check_noreturnvalues) as total_check_noreturnvalues, SUM(check_noparameters) as total_check_noparameters, SUM(check_noexamples) as total_check_noexamples, SUM(check_noerrors) as total_check_noerrors FROM files WHERE `lang`=\'en\' AND `path` REGEXP "^/reference/.*/functions/$" GROUP BY path ORDER BY path'; $r = $this->db->query($s); $nb = $r->num_rows; $i = 0; while ($a = $r->fetch_object()) { $i++; $tmp = explode('/', $a->path); $extension = $tmp[2]; $node[] = array( "id" => $i, "extension" => ucFirst($extension), "path" => $a->path, "check_oldstyle" => ( !$a->total_check_oldstyle) ? 0 : (int)$a->total_check_oldstyle, "check_undoc" => ( !$a->total_check_undoc) ? 0 : (int)$a->total_check_undoc, "check_roleerror" => ( !$a->total_check_roleerror) ? 0 : (int)$a->total_check_roleerror, "check_badorder" => ( !$a->total_check_badorder) ? 0 : (int)$a->total_check_badorder, "check_noseealso" => ( !$a->total_check_noseealso) ? 0 : (int)$a->total_check_noseealso, "check_noreturnvalues" => ( !$a->total_check_noreturnvalues) ? 0 : (int)$a->total_check_noreturnvalues, "check_noparameters" => ( !$a->total_check_noparameters) ? 0 : (int)$a->total_check_noparameters, "check_noexamples" => ( !$a->total_check_noexamples) ? 0 : (int)$a->total_check_noexamples, "check_noerrors" => ( !$a->total_check_noerrors) ? 0 : (int)$a->total_check_noerrors ); } // While return array('nb' => $nb, 'node' => $node); } /** * Run check doc tools on a file. * * @param string $content The content of the file * @param string $path The path of the file * @return An indexed array for saving into DB */ function checkDoc($content, $path) { $return['check_oldstyle'] = 'NULL'; $return['check_undoc'] = 'NULL'; $return['check_roleerror'] = 'NULL'; $return['check_badorder'] = 'NULL'; $return['check_noseealso'] = 'NULL'; $return['check_noreturnvalues'] = 'NULL'; $return['check_noparameters'] = 'NULL'; $return['check_noexamples'] = 'NULL'; $return['check_noerrors'] = 'NULL'; if (isset($tmp[1]) && isset($tmp[3]) && $tmp[1] == 'reference' && $tmp[3] == 'functions' ) { return $return; } $xmlstr = str_replace('&', '&', $content); $xml = new DOMDocument(); $xml->preserveWhiteSpace = false; if (!@$xml->loadXml($xmlstr)) { //echo "XML Parse Error: $function\n"; return $return; } // Variables initialisation $noparameters = false; $returnvoid = false; $refsect1s = $xml->getElementsByTagName('refsect1'); foreach ($refsect1s as $refsect1) { $role = $refsect1->getAttribute('role'); switch ($role) { case 'description': // Get text buffer for various checks $whole_description = $refsect1->nodeValue; // If not documented, mark it and skip to next function if (strpos($whole_description, '&warn.undocumented.func;') !== false) { $return['check_undoc'] = 1; return $return; } // If deprecated, skip to next function // @todo: add a better way of handling this (new entity in phpdoc?) if (strpos($whole_description, 'This function is deprecated') !== false) { return $return; } // If an alias, skip to next function if (strpos($whole_description, '&info.function.alias;') !== false) { return $return; } else { $refnamedivs = $xml->getElementsByTagName('refnamediv'); foreach ($refnamedivs as $refnamediv) { if (stripos($refnamediv->nodeValue, 'alias') !== false) { return $return; } } } // Look into the methodsynopsys tag(s) $methodsynopsiss = $xml->getElementsByTagName('methodsynopsis'); foreach ($methodsynopsiss as $methodsynopsis) { foreach ($methodsynopsis->childNodes as $child) { switch ($child->nodeName) { case '#comment': // Skip comments continue; case 'type': // This is the return type break; case 'void': // This either the return type or 0 parameters if (!isset($methodname)) { //$returnvoid = true; } else { // no parameters $noparameters = true; } break; case 'methodname': $methodname = $child->nodeValue; break; case 'methodparam': case 'modifier': break; default: //echo "Unknown child for methodsynopsis: {$child->nodeName} in $function\n"; } } } break; case 'returnvalues': case 'parameters': case 'seealso': case 'examples': case 'notes': case 'changelog': case 'errors': case 'unicode': // test order switch ($role) { case 'parameters': if (isset($notes) && isset($changelog) && isset($returnvalues) && isset($examples) && isset($seealso)) { $return['check_badorder'] = 1; } break; case 'returnvalues': if (isset($notes) && isset($changelog) && isset($examples) && isset($seealso)) { $return['check_badorder'] = 1; } break; case 'changelog': if (isset($notes) && isset($examples) && isset($seealso)) { $return['check_badorder'] = 1; } break; case 'examples': if (isset($notes) && isset($seealso)) { $return['check_badorder'] = 1; } break; case 'notes': if (isset($seealso)) { $return['check_badorder'] = 1; } break; } $$role = 1; $whole_content = $refsect1->nodeValue; // Check for default stub generated by xml_proto if ($role == 'returnvalues' && strpos($whole_content, 'What the function returns, first on success, then on failure.') !== false) { unset($returnvalues); } break; default: if ($role != '') { $check_doc['check_roleerror'] = 1; } else { $check_doc['check_oldstyle'] = 1; // Skip the remaining refsect1 return $return; } } } // See also checks if (!isset($seealso)) { $return['check_noseealso'] = 1; } unset($seealso); // Return Values if (!isset($returnvalues)) { $return['check_noreturnvalues'] = 1; } unset($returnvalues); // Parameters if (!isset($parameters) && !$noparameters) { $return['check_noparameters'] = 1; } unset($parameters); // Examples checks if (!isset($examples)) { $return['check_noexamples'] = 1; } unset($examples); // Errors checks if (!isset($errors)) { $return['check_noerrors'] = 1; } unset($errors); return $return; } }
http://cvs.php.net/viewvc.cgi/doc-editor/php/class.php?r1=1.36&r2=1.37&diff_format=u Index: doc-editor/php/class.php diff -u doc-editor/php/class.php:1.36 doc-editor/php/class.php:1.37 --- doc-editor/php/class.php:1.36 Sat Apr 18 22:16:53 2009 +++ doc-editor/php/class.php Mon Apr 20 18:59:46 2009 @@ -13,6 +13,7 @@ require_once dirname(__FILE__) . '/conf.inc.php'; require_once dirname(__FILE__) . '/LockFile.php'; require_once dirname(__FILE__) . '/ToolsError.php'; +require_once dirname(__FILE__) . '/ToolsCheckDoc.php'; class phpDoc { @@ -135,29 +136,14 @@ $en_revision = ($infoEN['rev'] == 'NULL') ? 'NULL' : "'".$infoEN['rev']."'"; $xmlid = ($infoEN['xmlid'] == 'NULL') ? 'NULL' : "'".$infoEN['xmlid']."'"; - // $this->Check_doc() ? is this dir is /reference/*/functions/ ? $tmp = explode('/', $dir); - if (isset($tmp[1]) && isset($tmp[3]) && $tmp[1] == 'reference' && $tmp[3] == 'functions' ) { - $check_doc = $this->check_doc($infoEN['content']); - - } else { - - $check_doc['check_oldstyle'] = 'NULL'; - $check_doc['check_undoc'] = 'NULL'; - $check_doc['check_roleerror'] = 'NULL'; - $check_doc['check_badorder'] = 'NULL'; - $check_doc['check_noseealso'] = 'NULL'; - $check_doc['check_noreturnvalues'] = 'NULL'; - $check_doc['check_noparameters'] = 'NULL'; - $check_doc['check_noexamples'] = 'NULL'; - $check_doc['check_noerrors'] = 'NULL'; - - } + $ToolsCheckDoc = new ToolsCheckDoc($this->db); + $ToolsCheckDocResult = $ToolsCheckDoc->checkDoc($infoEN['content'], $dir); // Sql insert. $s = "INSERT INTO files (lang, xmlid, dir, path, name, revision, size, mdate, maintainer, status, check_oldstyle, check_undoc, check_roleerror, check_badorder, check_noseealso, check_noreturnvalues, check_noparameters, check_noexamples,check_noerrors) - VALUES ('en', $xmlid, '$idDir', '$dir/', '$file', $en_revision, $en_size,$en_date, NULL, NULL, ".$check_doc['check_oldstyle'].", ".$check_doc['check_undoc'].", ".$check_doc['check_roleerror'].", ".$check_doc['check_badorder'].", ".$check_doc['check_noseealso'].", ".$check_doc['check_noreturnvalues'].", ".$check_doc['check_noparameters'].", ".$check_doc['check_noexamples'].", ".$check_doc['check_noerrors'].")"; + VALUES ('en', $xmlid, '$idDir', '$dir/', '$file', $en_revision, $en_size,$en_date, NULL, NULL, ".$ToolsCheckDocResult['check_oldstyle'].", ".$ToolsCheckDocResult['check_undoc'].", ".$ToolsCheckDocResult['check_roleerror'].", ".$ToolsCheckDocResult['check_badorder'].", ".$ToolsCheckDocResult['check_noseealso'].", ".$ToolsCheckDocResult['check_noreturnvalues'].", ".$ToolsCheckDocResult['check_noparameters'].", ".$ToolsCheckDocResult['check_noexamples'].", ".$ToolsCheckDocResult['check_noerrors'].")"; $this->db->query($s) or die('Error: '.$this->db->error); @@ -2048,7 +2034,7 @@ $t = explode('.',$a->name); $ext = $t[count($t)-1]; - $nodes[] = array('text'=>$a->lang.$a->path.$a->name, 'id'=>'//'.$a->lang.$a->path.$a->name, 'leaf'=>true, 'cls'=>'file', 'extension'=>$ext, 'type'=>'file'); + $nodes[] = array('text'=>$a->lang.$a->path.$a->name, 'id'=>'//'.$a->lang.$a->path.$a->name, 'leaf'=>true, 'cls'=>'file', 'extension'=>$ext, 'type'=>'file', 'from'=>'search'); } @@ -2160,264 +2146,6 @@ return $r->fetch_object(); } - function check_doc($content) { - - $return['check_oldstyle'] = 'NULL'; - $return['check_undoc'] = 'NULL'; - $return['check_roleerror'] = 'NULL'; - $return['check_badorder'] = 'NULL'; - $return['check_noseealso'] = 'NULL'; - $return['check_noreturnvalues'] = 'NULL'; - $return['check_noparameters'] = 'NULL'; - $return['check_noexamples'] = 'NULL'; - $return['check_noerrors'] = 'NULL'; - - $xmlstr = str_replace('&', '&', $content); - - $xml = new DOMDocument(); - $xml->preserveWhiteSpace = false; - - if (!@$xml->loadXml($xmlstr)) { - //echo "XML Parse Error: $function\n"; - return $return; - } - - // Variables initialisation - $noparameters = false; - $returnvoid = false; - - - $refsect1s = $xml->getElementsByTagName('refsect1'); - foreach ($refsect1s as $refsect1) { - $role = $refsect1->getAttribute('role'); - switch ($role) { - case 'description': - - // Get text buffer for various checks - $whole_description = $refsect1->nodeValue; - - // If not documented, mark it and skip to next function - if (strpos($whole_description, '&warn.undocumented.func;') !== false) { - $return['check_undoc'] = 1; - return $return; - } - - // If deprecated, skip to next function - // @todo: add a better way of handling this (new entity in phpdoc?) - if (strpos($whole_description, 'This function is deprecated') !== false) { - return $return; - } - - // If an alias, skip to next function - if (strpos($whole_description, '&info.function.alias;') !== false) { - return $return; - } else { - $refnamedivs = $xml->getElementsByTagName('refnamediv'); - foreach ($refnamedivs as $refnamediv) { - if (stripos($refnamediv->nodeValue, 'alias') !== false) { - return $return; - } - } - } - - // Look into the methodsynopsys tag(s) - $methodsynopsiss = $xml->getElementsByTagName('methodsynopsis'); - foreach ($methodsynopsiss as $methodsynopsis) { - foreach ($methodsynopsis->childNodes as $child) { - switch ($child->nodeName) { - case '#comment': - // Skip comments - continue; - - case 'type': - // This is the return type - break; - - case 'void': - // This either the return type or 0 parameters - if (!isset($methodname)) { - //$returnvoid = true; - } else { // no parameters - $noparameters = true; - } - break; - - case 'methodname': - $methodname = $child->nodeValue; - break; - - case 'methodparam': - case 'modifier': - break; - - default: - //echo "Unknown child for methodsynopsis: {$child->nodeName} in $function\n"; - } - } - } - - - break; - - case 'returnvalues': - case 'parameters': - case 'seealso': - case 'examples': - case 'notes': - case 'changelog': - case 'errors': - case 'unicode': - // test order - switch ($role) { - case 'parameters': - if (isset($notes) && isset($changelog) && isset($returnvalues) && isset($examples) && isset($seealso)) { - $return['check_badorder'] = 1; - } - break; - case 'returnvalues': - if (isset($notes) && isset($changelog) && isset($examples) && isset($seealso)) { - $return['check_badorder'] = 1; - } - break; - case 'changelog': - if (isset($notes) && isset($examples) && isset($seealso)) { - $return['check_badorder'] = 1; - } - break; - case 'examples': - if (isset($notes) && isset($seealso)) { - $return['check_badorder'] = 1; - } - break; - case 'notes': - if (isset($seealso)) { - $return['check_badorder'] = 1; - } - break; - } - $$role = 1; - $whole_content = $refsect1->nodeValue; - - // Check for default stub generated by xml_proto - if ($role == 'returnvalues' && strpos($whole_content, 'What the function returns, first on success, then on failure.') !== false) { - unset($returnvalues); - } - break; - - default: - if ($role != '') { - $check_doc['check_roleerror'] = 1; - } else { - $check_doc['check_oldstyle'] = 1; - // Skip the remaining refsect1 - return $return; - } - } - } - - // See also checks - if (!isset($seealso)) { - $return['check_noseealso'] = 1; - } - unset($seealso); - - // Return Values - if (!isset($returnvalues)) { - $return['check_noreturnvalues'] = 1; - } - unset($returnvalues); - - // Parameters - if (!isset($parameters) && !$noparameters) { - $return['check_noparameters'] = 1; - } - unset($parameters); - - // Examples checks - if (!isset($examples)) { - $return['check_noexamples'] = 1; - } - unset($examples); - - // Errors checks - if (!isset($errors)) { - $return['check_noerrors'] = 1; - } - unset($errors); - - return $return; - - } // check_doc - - function getCheckDocData() { - - $node = array(); - - $s = 'SELECT - path, - COUNT(*) AS total, - SUM(check_oldstyle) as total_check_oldstyle, - SUM(check_undoc) as total_check_undoc, - SUM(check_roleerror) as total_check_roleerror, - SUM(check_badorder) as total_check_badorder, - SUM(check_noseealso) as total_check_noseealso, - SUM(check_noreturnvalues) as total_check_noreturnvalues, - SUM(check_noparameters) as total_check_noparameters, - SUM(check_noexamples) as total_check_noexamples, - SUM(check_noerrors) as total_check_noerrors - - FROM files - - WHERE - `lang`=\'en\' AND - `path` REGEXP "^/reference/.*/functions/$" - - GROUP BY path - - ORDER BY path'; - - $r = $this->db->query($s); - $nb = $r->num_rows; - $i = 0; - while ($a = $r->fetch_object()) { - $i++; - - $tmp = explode('/', $a->path); - $extension = $tmp[2]; - - $node[] = array( - "id" => $i, - "extension" => ucFirst($extension), - "path" => $a->path, - "check_oldstyle" => ( !$a->total_check_oldstyle) ? 0 : (int)$a->total_check_oldstyle, - "check_undoc" => ( !$a->total_check_undoc) ? 0 : (int)$a->total_check_undoc, - "check_roleerror" => ( !$a->total_check_roleerror) ? 0 : (int)$a->total_check_roleerror, - "check_badorder" => ( !$a->total_check_badorder) ? 0 : (int)$a->total_check_badorder, - "check_noseealso" => ( !$a->total_check_noseealso) ? 0 : (int)$a->total_check_noseealso, - "check_noreturnvalues" => ( !$a->total_check_noreturnvalues) ? 0 : (int)$a->total_check_noreturnvalues, - "check_noparameters" => ( !$a->total_check_noparameters) ? 0 : (int)$a->total_check_noparameters, - "check_noexamples" => ( !$a->total_check_noexamples) ? 0 : (int)$a->total_check_noexamples, - "check_noerrors" => ( !$a->total_check_noerrors) ? 0 : (int)$a->total_check_noerrors - ); - - } // While - - return array('nb' => $nb, 'node' => $node); - - } //getCheckDocData - - function getCheckDocFiles($path, $errorType) - { - $s = sprintf('SELECT name FROM `files` WHERE `lang`="en" AND `path`="%s" AND `%s`=1', $path, $errorType); - $r = $this->db->query($s); - - $node = array(); - while ($row = $r->fetch_assoc()) { - $node[] = $row; - } - return $node; - } // get_Check_Doc_Files - /** * Get the last update datetime * @return The last update datetime or "in_progress" if the update is in progress http://cvs.php.net/viewvc.cgi/doc-editor/php/ExtJsController.php?r1=1.19&r2=1.20&diff_format=u Index: doc-editor/php/ExtJsController.php diff -u doc-editor/php/ExtJsController.php:1.19 doc-editor/php/ExtJsController.php:1.20 --- doc-editor/php/ExtJsController.php:1.19 Sun Apr 19 11:17:23 2009 +++ doc-editor/php/ExtJsController.php Mon Apr 20 18:59:46 2009 @@ -736,7 +736,8 @@ $this->phpDoc->isLogged(); - $r = $this->phpDoc->getCheckDocData(); + $ToolsCheckDoc = new ToolsCheckDoc($this->phpDoc->db); + $r = $ToolsCheckDoc->getCheckDocData(); return $this->getResponse(array('nbItems' => $r['nb'], 'Items' => $r['node'])); } @@ -748,7 +749,8 @@ $path = $this->getRequestVariable('path'); $errorType = $this->getRequestVariable('errorType'); - $r = $this->phpDoc->getCheckDocFiles($path, $errorType); + $ToolsCheckDoc = new ToolsCheckDoc($this->phpDoc->db); + $r = $ToolsCheckDoc->getCheckDocFiles($path, $errorType); return $this->getResponse(array('success' => true, 'files' => $r)); } http://cvs.php.net/viewvc.cgi/doc-editor/php/ToolsCheckDoc.php?view=markup&rev=1.1 Index: doc-editor/php/ToolsCheckDoc.php +++ doc-editor/php/ToolsCheckDoc.php <?php /** * A class for the check doc tools * Original check_phpdoc script have been written by didou <didou@php.net> * you can found it here : http://cvs.php.net/viewvc.cgi/phpdoc/scripts/check_phpdoc/ * */ class ToolsCheckDoc { /** * Database connection * * @var resource */ private $db; /** * Initialise * * @param string $db The database connection */ function __construct($db) { $this->db = $db; } /** * Get Files for a particular path and errorType. * * @param string $path The path for the files to retrieve * @param string $errorType The type of error to retrieve * @return An indexed array readable by ExtJs */ function getCheckDocFiles($path, $errorType) { $s = sprintf('SELECT name FROM `files` WHERE `lang`="en" AND `path`="%s" AND `%s`=1', $path, $errorType); $r = $this->db->query($s); $node = array(); while ($row = $r->fetch_assoc()) { $node[] = $row; } return $node; } /** * Get check doc data. * * @return An indexed array readable by ExtJs */ function getCheckDocData() { $node = array(); $s = 'SELECT path, COUNT(*) AS total, SUM(check_oldstyle) as total_check_oldstyle, SUM(check_undoc) as total_check_undoc, SUM(check_roleerror) as total_check_roleerror, SUM(check_badorder) as total_check_badorder, SUM(check_noseealso) as total_check_noseealso, SUM(check_noreturnvalues) as total_check_noreturnvalues, SUM(check_noparameters) as total_check_noparameters, SUM(check_noexamples) as total_check_noexamples, SUM(check_noerrors) as total_check_noerrors FROM files WHERE `lang`=\'en\' AND `path` REGEXP "^/reference/.*/functions/$" GROUP BY path ORDER BY path'; $r = $this->db->query($s); $nb = $r->num_rows; $i = 0; while ($a = $r->fetch_object()) { $i++; $tmp = explode('/', $a->path); $extension = $tmp[2]; $node[] = array( "id" => $i, "extension" => ucFirst($extension), "path" => $a->path, "check_oldstyle" => ( !$a->total_check_oldstyle) ? 0 : (int)$a->total_check_oldstyle, "check_undoc" => ( !$a->total_check_undoc) ? 0 : (int)$a->total_check_undoc, "check_roleerror" => ( !$a->total_check_roleerror) ? 0 : (int)$a->total_check_roleerror, "check_badorder" => ( !$a->total_check_badorder) ? 0 : (int)$a->total_check_badorder, "check_noseealso" => ( !$a->total_check_noseealso) ? 0 : (int)$a->total_check_noseealso, "check_noreturnvalues" => ( !$a->total_check_noreturnvalues) ? 0 : (int)$a->total_check_noreturnvalues, "check_noparameters" => ( !$a->total_check_noparameters) ? 0 : (int)$a->total_check_noparameters, "check_noexamples" => ( !$a->total_check_noexamples) ? 0 : (int)$a->total_check_noexamples, "check_noerrors" => ( !$a->total_check_noerrors) ? 0 : (int)$a->total_check_noerrors ); } // While return array('nb' => $nb, 'node' => $node); } /** * Run check doc tools on a file. * * @param string $content The content of the file * @param string $path The path of the file * @return An indexed array for saving into DB */ function checkDoc($content, $path) { $return['check_oldstyle'] = 'NULL'; $return['check_undoc'] = 'NULL'; $return['check_roleerror'] = 'NULL'; $return['check_badorder'] = 'NULL'; $return['check_noseealso'] = 'NULL'; $return['check_noreturnvalues'] = 'NULL'; $return['check_noparameters'] = 'NULL'; $return['check_noexamples'] = 'NULL'; $return['check_noerrors'] = 'NULL'; if (isset($tmp[1]) && isset($tmp[3]) && $tmp[1] == 'reference' && $tmp[3] == 'functions' ) { return $return; } $xmlstr = str_replace('&', '&', $content); $xml = new DOMDocument(); $xml->preserveWhiteSpace = false; if (!@$xml->loadXml($xmlstr)) { //echo "XML Parse Error: $function\n"; return $return; } // Variables initialisation $noparameters = false; $returnvoid = false; $refsect1s = $xml->getElementsByTagName('refsect1'); foreach ($refsect1s as $refsect1) { $role = $refsect1->getAttribute('role'); switch ($role) { case 'description': // Get text buffer for various checks $whole_description = $refsect1->nodeValue; // If not documented, mark it and skip to next function if (strpos($whole_description, '&warn.undocumented.func;') !== false) { $return['check_undoc'] = 1; return $return; } // If deprecated, skip to next function // @todo: add a better way of handling this (new entity in phpdoc?) if (strpos($whole_description, 'This function is deprecated') !== false) { return $return; } // If an alias, skip to next function if (strpos($whole_description, '&info.function.alias;') !== false) { return $return; } else { $refnamedivs = $xml->getElementsByTagName('refnamediv'); foreach ($refnamedivs as $refnamediv) { if (stripos($refnamediv->nodeValue, 'alias') !== false) { return $return; } } } // Look into the methodsynopsys tag(s) $methodsynopsiss = $xml->getElementsByTagName('methodsynopsis'); foreach ($methodsynopsiss as $methodsynopsis) { foreach ($methodsynopsis->childNodes as $child) { switch ($child->nodeName) { case '#comment': // Skip comments continue; case 'type': // This is the return type break; case 'void': // This either the return type or 0 parameters if (!isset($methodname)) { //$returnvoid = true; } else { // no parameters $noparameters = true; } break; case 'methodname': $methodname = $child->nodeValue; break; case 'methodparam': case 'modifier': break; default: //echo "Unknown child for methodsynopsis: {$child->nodeName} in $function\n"; } } } break; case 'returnvalues': case 'parameters': case 'seealso': case 'examples': case 'notes': case 'changelog': case 'errors': case 'unicode': // test order switch ($role) { case 'parameters': if (isset($notes) && isset($changelog) && isset($returnvalues) && isset($examples) && isset($seealso)) { $return['check_badorder'] = 1; } break; case 'returnvalues': if (isset($notes) && isset($changelog) && isset($examples) && isset($seealso)) { $return['check_badorder'] = 1; } break; case 'changelog': if (isset($notes) && isset($examples) && isset($seealso)) { $return['check_badorder'] = 1; } break; case 'examples': if (isset($notes) && isset($seealso)) { $return['check_badorder'] = 1; } break; case 'notes': if (isset($seealso)) { $return['check_badorder'] = 1; } break; } $$role = 1; $whole_content = $refsect1->nodeValue; // Check for default stub generated by xml_proto if ($role == 'returnvalues' && strpos($whole_content, 'What the function returns, first on success, then on failure.') !== false) { unset($returnvalues); } break; default: if ($role != '') { $check_doc['check_roleerror'] = 1; } else { $check_doc['check_oldstyle'] = 1; // Skip the remaining refsect1 return $return; } } } // See also checks if (!isset($seealso)) { $return['check_noseealso'] = 1; } unset($seealso); // Return Values if (!isset($returnvalues)) { $return['check_noreturnvalues'] = 1; } unset($returnvalues); // Parameters if (!isset($parameters) && !$noparameters) { $return['check_noparameters'] = 1; } unset($parameters); // Examples checks if (!isset($examples)) { $return['check_noexamples'] = 1; } unset($examples); // Errors checks if (!isset($errors)) { $return['check_noerrors'] = 1; } unset($errors); return $return; } }