On Fri, Jul 25, 2008 at 15:58, Hannes Magnusson
<[EMAIL PROTECTED]> wrote:
> Hi all
>
> I'd like to fix bug#44244 like we fixed the
> methodless-exception-problem[1], by introducing phpdoc:class element
> which will behave exactly like the phpdoc:exception element.
> This way we can index <phpdoc:class><titleabbrev> (the actual
> classname) and therefore automatically generate links to only classes,
> and the same for <exceptionname> obviously.
>
> I don't have a patch for it at the moment though, but it would be
> exactly like the phpdoc:exception Docbook DTD patch.
<classname> now links to classes/exceptions (defined using the
phpdoc:class/phpdoc:exception elements), see attachments.
Only tested it on those few exceptions and class, but will change all
I can find to use phpdoc:class/phpdoc:exception when I commit.
Comments? Feedback? Screw you?
-Hannes
Index: build.php
===================================================================
RCS file: /repository/phd/build.php,v
retrieving revision 1.54.2.2
diff -u -r1.54.2.2 build.php
--- build.php 1 Aug 2008 11:17:06 -0000 1.54.2.2
+++ build.php 4 Aug 2008 18:44:37 -0000
@@ -28,32 +28,36 @@
/* {{{ Build the .ser file names to allow multiple sources for PHD. */
$OPTIONS['index_location'] = $OPTIONS['xml_root'] . DIRECTORY_SEPARATOR . '.index_' . basename($OPTIONS['xml_file'], '.xml') . '.ser';
$OPTIONS['refnames_location'] = $OPTIONS['xml_root'] . DIRECTORY_SEPARATOR . '.refnames_' . basename($OPTIONS['xml_file'], '.xml') . '.ser';
+$OPTIONS['classes_location'] = $OPTIONS['xml_root'] . DIRECTORY_SEPARATOR . '.classes_' . basename($OPTIONS['xml_file'], '.xml') . '.ser';
/* }}} */
/* {{{ Index the DocBook file or load from .ser cache files
NOTE: There are two cache files (where * is the basename of the XML source file):
- index_*.ser (containing the ID infos)
- refnames_*.ser (containing <refname> => File ID) */
-if (!$OPTIONS["index"] && (file_exists($OPTIONS['index_location']) && file_exists($OPTIONS['refnames_location']))) {
+if (!$OPTIONS["index"] && (file_exists($OPTIONS['index_location']) && file_exists($OPTIONS['refnames_location']) && file_exists($OPTIONS['classes_location']))) {
/* FIXME: Load from sqlite db? */
v("Unserializing cached index files...", VERBOSE_INDEXING);
$IDs = unserialize(file_get_contents($OPTIONS['index_location']));
$REFS = unserialize(file_get_contents($OPTIONS['refnames_location']));
+ $CLASSES = unserialize(file_get_contents($OPTIONS['classes_location']));
v("Unserialization done", VERBOSE_INDEXING);
} else {
v("Indexing...", VERBOSE_INDEXING);
- /* This file will "return" an $IDs & $REFS array */
+ /* This file will "return" an $IDs, $REFS, $CLASSES array */
require $ROOT. "/mktoc.php";
file_put_contents($OPTIONS['index_location'], $ids = serialize($IDs));
file_put_contents($OPTIONS['refnames_location'], $refs = serialize($REFS));
+ file_put_contents($OPTIONS['classes_location'], $classes = serialize($CLASSES));
$IDs2 = unserialize($ids);
$REFS2 = unserialize($refs);
- if ($IDs !== $IDs2 || $REFS !== $REFS2) {
+ $CLASSES2 = unserialize($classes);
+ if ($IDs !== $IDs2 || $REFS !== $REFS2 || $CLASSES !== $CLASSES2) {
trigger_error("Serialized representation does not match", E_USER_WARNING);
}
@@ -79,7 +83,7 @@
// {{{ Initialize the output format and fetch the methodmaps
require $ROOT. "/formats/$output_format.php";
- $format = new $classname(array($IDs, $REFS));
+ $format = new $classname(array($IDs, $REFS, $CLASSES));
$formatmap = $format->getElementMap();
$formattextmap = $format->getTextMap();
/* }}} */
@@ -96,7 +100,7 @@
switch($theme) {
// FIXME: This is stupid and definetly does not belong in here.
case "php":
- $themes[$themename] = new $themename(array($IDs, $REFS),
+ $themes[$themename] = new $themename(array($IDs, $REFS, $CLASSES),
array(
"version" => $OPTIONS["version_info"],
"acronym" => $OPTIONS["acronyms_file"],
@@ -104,7 +108,7 @@
);
break;
default:
- $themes[$themename] = new $themename(array($IDs, $REFS));
+ $themes[$themename] = new $themename(array($IDs, $REFS, $CLASSES));
}
// FIXME: this needs to go away when we add support for
Index: config.php
===================================================================
RCS file: /repository/phd/config.php,v
retrieving revision 1.45.2.9
diff -u -r1.45.2.9 config.php
--- config.php 1 Aug 2008 12:40:29 -0000 1.45.2.9
+++ config.php 4 Aug 2008 18:44:38 -0000
@@ -152,6 +152,7 @@
'chunk_extra' => array(
"legalnotice" => true,
"phpdoc:exception" => true,
+ "phpdoc:class" => true,
),
'index' => true,
'xml_root' => '.',
Index: mktoc.php
===================================================================
RCS file: /repository/phd/mktoc.php,v
retrieving revision 1.10
diff -u -r1.10 mktoc.php
--- mktoc.php 24 May 2008 14:49:14 -0000 1.10
+++ mktoc.php 4 Aug 2008 18:44:38 -0000
@@ -1,7 +1,7 @@
<?php
/* $Id: mktoc.php,v 1.10 2008/05/24 14:49:14 gwynne Exp $ */
$r = new PhDReader($OPTIONS);
-$REFS = $FILENAMES = array();
+$CLASSES = $REFS = $FILENAMES = array();
$CURRENT_FILENAME = $LAST_CHUNK = "";
#FIXME: This is a workaround for the <legalnotice> element in the PHP manual
@@ -19,7 +19,11 @@
continue;
}
elseif($name == "titleabbrev") {
- $IDs[$lastid]["sdesc"] = trim($r->readContent($name));
+ $IDs[$lastid]["sdesc"] = $class = trim($r->readContent($name));
+ $elm = $r->getParentTagName();
+ if ($elm == "phpdoc:class" || $elm == "phpdoc:exception") {
+ $CLASSES[strtolower($class)] = $lastid;
+ }
continue;
}
} elseif($name == "refname") {
Index: include/PhDHelper.class.php
===================================================================
RCS file: /repository/phd/include/PhDHelper.class.php,v
retrieving revision 1.9
diff -u -r1.9 PhDHelper.class.php
--- include/PhDHelper.class.php 27 Jan 2008 14:32:33 -0000 1.9
+++ include/PhDHelper.class.php 4 Aug 2008 18:44:38 -0000
@@ -4,6 +4,7 @@
class PhDHelper {
private $IDs = array();
private $refs = array();
+ private $classes = array();
/* abstract */ protected $elementmap = array();
/* abstract */ protected $textmap = array();
private static $autogen = array();
@@ -11,6 +12,7 @@
public function __construct(array $a) {
$this->IDs = $a[0];
$this->refs = $a[1];
+ $this->classes = $a[2];
}
final public function getFilename($id) {
return isset($this->IDs[$id]) ? $this->IDs[$id]["filename"] : false;
@@ -29,6 +31,9 @@
public function getRefnameLink($ref) {
return isset($this->refs[$ref]) ? $this->refs[$ref] : null;
}
+ public function getClassnameLink($class) {
+ return isset($this->classes[$class]) ? $this->classes[$class] : null;
+ }
final public function getElementMap() {
return $this->elementmap;
}
Index: themes/php/phpdotnet.php
===================================================================
RCS file: /repository/phd/themes/php/phpdotnet.php,v
retrieving revision 1.53.2.1
diff -u -r1.53.2.1 phpdotnet.php
--- themes/php/phpdotnet.php 23 Jul 2008 18:31:49 -0000 1.53.2.1
+++ themes/php/phpdotnet.php 4 Aug 2008 18:44:38 -0000
@@ -5,6 +5,7 @@
protected $elementmap = array(
'acronym' => 'format_suppressed_tags',
'function' => 'format_suppressed_tags',
+ 'classname' => 'format_suppressed_tags',
'link' => 'format_link',
'refpurpose' => 'format_refpurpose',
'title' => array(
@@ -69,6 +70,7 @@
'refentry' => 'format_chunk',
'reference' => 'format_container_chunk',
'phpdoc:exception' => 'format_exception_chunk',
+ 'phpdoc:class' => 'format_class_chunk',
'sect1' => 'format_chunk',
'sect2' => 'format_chunk',
'sect3' => 'format_chunk',
@@ -85,6 +87,7 @@
protected $textmap = array(
'acronym' => 'format_acronym_text',
'function' => 'format_function_text',
+ 'classname' => 'format_classname_text',
'methodname' => array(
/* DEFAULT */ 'format_function_text',
'constructorsynopsis' => array(
@@ -112,7 +115,11 @@
),
'refname' => 'format_refname_text',
- 'titleabbrev' => 'format_suppressed_tags',
+ 'titleabbrev' => array(
+ /* DEFAULT */ 'format_suppressed_tags',
+ 'phpdoc:class' => 'format_grep_classname_text',
+ 'phpdoc:exception' => 'format_grep_classname_text',
+ ),
);
private $versions = array();
private $acronyms = array();
@@ -125,6 +132,7 @@
protected $cchunk = array();
/* Default Chunk settings */
protected $dchunk = array(
+ "phpdoc:class" => null,
"fieldsynopsis" => array(
"modifier" => "public",
),
@@ -410,6 +418,9 @@
public function format_exception_chunk($open, $name, $attrs, $props) {
return $this->format_container_chunk($open, "reference", $attrs, $props);
}
+ public function format_class_chunk($open, $name, $attrs, $props) {
+ return $this->format_container_chunk($open, "reference", $attrs, $props);
+ }
public function format_container_chunk_title($open, $name, $attrs) {
if ($open) {
@@ -489,6 +500,20 @@
}
return '<b>' .$display_value.($tag == "function" ? "()" : ""). '</b>';
}
+
+ public function format_grep_classname_text($value, $tag) {
+ $this->cchunk["phpdoc:class"] = strtolower($value);
+ }
+ public function format_classname_text($value, $tag) {
+ if (($filename = $this->getClassnameLink(strtolower($value))) !== null && $this->cchunk["phpdoc:class"] !== strtolower($value)) {
+ if ($this->chunked) {
+ return '<a href="'.$filename. '.' .$this->ext. '" class="classname">' .$value. '</a>';
+ }
+ return '<a href="#'.$filename. '" class="classname">'.$value.'</a>';
+ }
+ return '<b class="classname">' .$value. '</b>';
+ }
+
public function format_type_if_object_or_pseudo_text($type, $tagname) {
if (in_array(strtolower($type), array("bool", "int", "double", "boolean", "integer", "float", "string", "array", "object", "resource", "null"))) {
return false;
? man3
? phpman
Index: docbook/docbook-xml/docbook.dtd
===================================================================
RCS file: /repository/phpdoc/docbook/docbook-xml/docbook.dtd,v
retrieving revision 1.4
diff -u -r1.4 docbook.dtd
--- docbook/docbook-xml/docbook.dtd 23 Jul 2008 18:44:36 -0000 1.4
+++ docbook/docbook-xml/docbook.dtd 4 Aug 2008 18:45:12 -0000
@@ -2531,7 +2531,7 @@
>
-<!ELEMENT book (((title|titleabbrev|subtitle)*, info?), (glossary|bibliography|index|toc|dedication|acknowledgements|preface|chapter|appendix|article|colophon|part|reference|phpdoc:exception)+)>
+<!ELEMENT book (((title|titleabbrev|subtitle)*, info?), (glossary|bibliography|index|toc|dedication|acknowledgements|preface|chapter|appendix|article|colophon|part|reference|phpdoc:exception|phpdoc:class)+)>
<!ATTLIST book
xmlns CDATA #FIXED "http://docbook.org/ns/docbook"
@@ -2603,7 +2603,7 @@
>
-<!ELEMENT part (((title|titleabbrev|subtitle)*, info?), partintro?, (glossary|bibliography|index|toc|dedication|acknowledgements|preface|chapter|appendix|article|colophon|refentry|reference)+)>
+<!ELEMENT part (((title|titleabbrev|subtitle)*, info?), partintro?, (glossary|bibliography|index|toc|dedication|acknowledgements|preface|chapter|appendix|article|colophon|refentry|reference|phpdoc:exception|phpdoc:class)+)>
<!ATTLIST part
xmlns CDATA #FIXED "http://docbook.org/ns/docbook"
@@ -2748,6 +2748,18 @@
>
+<!ELEMENT class (((title|titleabbrev|subtitle)*, info?), partintro?, (refentry)*)>
+
+<!ATTLIST class
+ xmlns CDATA #FIXED "http://docbook.org/ns/docbook"
+ role CDATA #IMPLIED
+ %db.common.attributes;
+ %db.common.linking.attributes;
+ status CDATA #IMPLIED
+ label CDATA #IMPLIED
+
+>
+
<!ELEMENT exception (((title|titleabbrev|subtitle)*, info?), partintro?, (refentry)*)>
<!ATTLIST exception
Index: en/language/predefined/errorexception.xml
===================================================================
RCS file: /repository/phpdoc/en/language/predefined/errorexception.xml,v
retrieving revision 1.2
diff -u -r1.2 errorexception.xml
--- en/language/predefined/errorexception.xml 21 Apr 2008 08:38:09 -0000 1.2
+++ en/language/predefined/errorexception.xml 4 Aug 2008 18:45:14 -0000
@@ -1,8 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.2 $ -->
-<reference xml:id="class.errorexception" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
+<phpdoc:exception xml:id="class.errorexception"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:phpdoc="http://php.net/ns/phpdoc">
<title>ErrorException</title>
+ <titleabbrev>ErrorException</titleabbrev>
<partintro>
@@ -105,7 +110,7 @@
&language.predefined.errorexception.construct;
&language.predefined.errorexception.getseverity;
-</reference>
+</phpdoc:exception>
<!-- Keep this comment at the end of the file
Local variables:
Index: en/language/predefined/exception.xml
===================================================================
RCS file: /repository/phpdoc/en/language/predefined/exception.xml,v
retrieving revision 1.2
diff -u -r1.2 exception.xml
--- en/language/predefined/exception.xml 15 Apr 2008 23:19:15 -0000 1.2
+++ en/language/predefined/exception.xml 4 Aug 2008 18:45:14 -0000
@@ -1,8 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.2 $ -->
-<reference xml:id="class.exception" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
+<phpdoc:exception xml:id="class.exception"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:phpdoc="http://php.net/ns/phpdoc">
<title>Exception</title>
+ <titleabbrev>Exception</titleabbrev>
<partintro>
@@ -128,7 +133,7 @@
&language.predefined.exception.tostring;
&language.predefined.exception.clone;
-</reference>
+</phpdoc:exception>
<!-- Keep this comment at the end of the file
Local variables:
Index: en/reference/phar/Phar.xml
===================================================================
RCS file: /repository/phpdoc/en/reference/phar/Phar.xml,v
retrieving revision 1.1
diff -u -r1.1 Phar.xml
--- en/reference/phar/Phar.xml 21 Jan 2008 15:23:52 -0000 1.1
+++ en/reference/phar/Phar.xml 4 Aug 2008 18:45:16 -0000
@@ -1,7 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.1 $ -->
-<reference xml:id="class.Phar" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
+<phpdoc:class xml:id="class.Phar" xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:phpdoc="http://php.net/ns/phpdoc">
<title>The Phar class</title>
<titleabbrev>Phar</titleabbrev>
@@ -61,7 +64,7 @@
&reference.phar.entities.Phar;
-</reference>
+</phpdoc:class>
<!-- Keep this comment at the end of the file
Local variables:
Index: en/reference/xmlreader/xmlreader.xml
===================================================================
RCS file: /repository/phpdoc/en/reference/xmlreader/xmlreader.xml,v
retrieving revision 1.3
diff -u -r1.3 xmlreader.xml
--- en/reference/xmlreader/xmlreader.xml 26 Dec 2007 18:56:29 -0000 1.3
+++ en/reference/xmlreader/xmlreader.xml 4 Aug 2008 18:45:19 -0000
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.3 $ -->
-<reference xml:id="class.xmlreader" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
+<phpdoc:class xml:id="class.xmlreader" xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:phpdoc="http://php.net/ns/phpdoc">
<title>The XMLReader class</title>
<titleabbrev>XMLReader</titleabbrev>
@@ -548,7 +551,7 @@
&reference.xmlreader.entities.xmlreader;
-</reference>
+</phpdoc:class>
<!-- Keep this comment at the end of the file
Local variables: