Commit 80c7ebec authored by gerv%gerv.net's avatar gerv%gerv.net

Bug 230742 - document new 'hooks' mechanism. This is my take on Myk's text -…

Bug 230742 - document new 'hooks' mechanism. This is my take on Myk's text - probably still needs further polish.
parent 8c75b37b
...@@ -18,78 +18,45 @@ ...@@ -18,78 +18,45 @@
<xref linkend="template-http-accept"/>. <xref linkend="template-http-accept"/>.
</para> </para>
<section id="template-directory"> <section>
<title>Template Directory Structure</title> <title>What to Edit</title>
<para> <para>
The template directory structure starts with top level directory The template directory structure is that there's a top level directory,
named <filename>template</filename>, which contains a directory <filename>template</filename>, which contains a directory for
for each installed localization. The next level defines the each installed localization. The default English templates are
language used in the templates. Bugzilla comes with English therefore in <filename>en</filename>. Underneath that, there
templates, so the directory name is <filename>en</filename>, is the <filename>default</filename> directory and optionally the
and we will discuss <filename>template/en</filename> throughout <filename>custom</filename> directory. The <filename>default</filename>
the documentation. Below <filename>template/en</filename> is the directory contains all the templates shipped with Bugzilla, whereas
<filename>default</filename> directory, which contains all the the <filename>custom</filename> directory does not exist at first and
standard templates shipped with Bugzilla. must be created if you want to use it.
</para> </para>
<warning>
<para>
A directory <filename>data/templates</filename> also exists;
this is where Template Toolkit puts the compiled versions of
the templates from either the default or custom directories.
<emphasis>Do not</emphasis> directly edit the files in this
directory, or all your changes will be lost the next time
Template Toolkit recompiles the templates.
</para>
</warning>
</section>
<section id="template-method">
<title>Choosing a Customization Method</title>
<para>
If you want to edit Bugzilla's templates, the first decision
you must make is how you want to go about doing so. There are two
choices, and which you use depends mainly on the scope of your
modifications, and the method you plan to use to upgrade Bugzilla.
</para>
<para> <para>
There are two different ways of editing Bugzilla's templates,
and which you use depends mainly on the method you plan to use to
upgrade Bugzilla.
The first method of making customizations is to directly edit the The first method of making customizations is to directly edit the
templates found in <filename>template/en/default</filename>. templates in <filename>template/en/default</filename>. This is
This is probably the best way to go about it if you are going to probably the best method for small changes if you are going to use
be upgrading Bugzilla through CVS, because if you then execute the CVS method of upgrading, because if you then execute a
a <command>cvs update</command>, any changes you have made will <command>cvs update</command>, any template fixes will get
be merged automagically with the updated versions. automagically merged into your modified versions.
</para> </para>
<note>
<para>
If you use this method, and CVS conflicts occur during an
update, the conflicted templates (and possibly other parts
of your installation) will not work until they are resolved.
</para>
</note>
<para> <para>
The second method is to copy the templates to be modified If you use this method, your installation will break if CVS conflicts
into a mirrored directory structure under occur.
<filename>template/en/custom</filename>. Templates in this
directory structure automatically override any identically-named
and identically-located templates in the
<filename>default</filename> directory.
</para> </para>
<note>
<para>
The <filename>custom</filename> directory does not exist
at first and must be created if you want to use it.
</para>
</note>
<para> <para>
The second method of customization should be used if you The other method is to copy the templates to be modified into a
use the overwriting method of upgrade, because otherwise mirrored directory
your changes will be lost. This method may also be better if structure under <filename>template/en/custom</filename>. The templates
in this directory automatically override those in default.
This is the technique you
need to use if you use the overwriting method of upgrade, because
otherwise your changes will be lost. This method is also better if
you are using the CVS method of upgrading and are going to make major you are using the CVS method of upgrading and are going to make major
changes, because it is guaranteed that the contents of this directory changes, because it is guaranteed that the contents of this directory
will not be touched during an upgrade, and you can then decide whether will not be touched during an upgrade, and you can then decide whether
...@@ -98,9 +65,9 @@ ...@@ -98,9 +65,9 @@
</para> </para>
<para> <para>
Using this method, your installation may break if incompatible If you use this method, your installation may break if incompatible
changes are made to the template interface. Such changes should changes are made to the template interface. If such changes are made
be documented in the release notes, provided you are using a they will be documented in the release notes, provided you are using a
stable release of Bugzilla. If you use using unstable code, you will stable release of Bugzilla. If you use using unstable code, you will
need to deal with this one yourself, although if possible the changes need to deal with this one yourself, although if possible the changes
will be mentioned before they occur in the deprecations section of the will be mentioned before they occur in the deprecations section of the
...@@ -109,25 +76,21 @@ ...@@ -109,25 +76,21 @@
<note> <note>
<para> <para>
Regardless of which method you choose, it is recommended that Don't directly edit the compiled templates in
you run <command>./checksetup.pl</command> after creating or <filename class="directory">data/template/*</filename> - your
editing any templates in the <filename>template/en/default</filename> changes will be lost when Template Toolkit recompiles them.
directory, and after editing any templates in the
<filename>custom</filename> directory.
</para> </para>
</note> </note>
<warning> <note>
<para> <para>It is recommended that you run <command>./checksetup.pl</command>
It is <emphasis>required</emphasis> that you run after any template edits, especially if you've created a new file in
<command>./checksetup.pl</command> after creating a new the <filename class="directory">custom</filename> directory.
template in the <filename>custom</filename> directory. Failure
to do so will raise an incomprehensible error message.
</para> </para>
</warning> </note>
</section> </section>
<section id="template-edit"> <section>
<title>How To Edit Templates</title> <title>How To Edit Templates</title>
<note> <note>
...@@ -135,7 +98,7 @@ ...@@ -135,7 +98,7 @@
If you are making template changes that you intend on submitting back If you are making template changes that you intend on submitting back
for inclusion in standard Bugzilla, you should read the relevant for inclusion in standard Bugzilla, you should read the relevant
sections of the sections of the
<ulink url="http://www.bugzilla.org/docs/developer.html">Developers' <ulink url="http://www.bugzilla.org/developerguide.html">Developers'
Guide</ulink>. Guide</ulink>.
</para> </para>
</note> </note>
...@@ -153,7 +116,7 @@ ...@@ -153,7 +116,7 @@
to properly HTML filter data that has been passed into the template. to properly HTML filter data that has been passed into the template.
This means that if the data can possibly contain special HTML characters This means that if the data can possibly contain special HTML characters
such as &lt;, and the data was not intended to be HTML, they need to be such as &lt;, and the data was not intended to be HTML, they need to be
converted to entity form, i.e. &amp;lt;. You use the 'html' filter in the converted to entity form, ie &amp;lt;. You use the 'html' filter in the
Template Toolkit to do this. If you forget, you may open up Template Toolkit to do this. If you forget, you may open up
your installation to cross-site scripting attacks. your installation to cross-site scripting attacks.
</para> </para>
...@@ -162,18 +125,16 @@ ...@@ -162,18 +125,16 @@
Also note that Bugzilla adds a few filters of its own, that are not Also note that Bugzilla adds a few filters of its own, that are not
in standard Template Toolkit. In particular, the 'url_quote' filter in standard Template Toolkit. In particular, the 'url_quote' filter
can convert characters that are illegal or have special meaning in URLs, can convert characters that are illegal or have special meaning in URLs,
such as &amp;, to the encoded form, i.e. %26. This actually encodes most such as &amp;, to the encoded form, ie %26. This actually encodes most
characters (but not the common ones such as letters and numbers and so characters (but not the common ones such as letters and numbers and so
on), including the HTML-special characters, so there's never a need to on), including the HTML-special characters, so there's never a need to
HTML filter afterwards. HTML filter afterwards.
</para> </para>
<para> <para>
Editing templates is a good way of doing a <quote>poor man's custom Editing templates is a good way of doing a "poor man's custom fields".
fields</quote>.
For example, if you don't use the Status Whiteboard, but want to have For example, if you don't use the Status Whiteboard, but want to have
a free-form text entry box for <quote>Build Identifier</quote>, a free-form text entry box for "Build Identifier", then you can just
then you can just
edit the templates to change the field labels. It's still be called edit the templates to change the field labels. It's still be called
status_whiteboard internally, but your users don't need to know that. status_whiteboard internally, but your users don't need to know that.
</para> </para>
...@@ -181,29 +142,22 @@ ...@@ -181,29 +142,22 @@
</section> </section>
<section id="template-formats"> <section>
<title>Template Formats and Types</title> <title>Template Formats</title>
<para> <para>
Some CGI's have the ability to use more than one template. For example, Some CGIs have the ability to use more than one template. For
<filename>buglist.cgi</filename> can output itself as RDF, or as two example, buglist.cgi can output bug lists as RDF or two
formats of HTML (complex and simple). The mechanism that provides this different forms of HTML (complex and simple). (Try this out
feature is extensible. by appending <filename>&amp;format=simple</filename> to a buglist.cgi
</para> URL on your Bugzilla installation.) This
mechanism, called template 'formats', is extensible.
<para>
Bugzilla can support different types of output, which again can have
multiple formats. In order to request a certain type, you can append
the &amp;ctype=&lt;contenttype&gt; (such as rdf or html) to the
<filename>&lt;cginame&gt;.cgi</filename> URL. If you would like to
retrieve a certain format, you can use the &amp;format=&lt;format&gt;
(such as simple or complex) in the URL.
</para> </para>
<para> <para>
To see if a CGI supports multiple output formats and types, grep the To see if a CGI supports multiple output formats, grep the
CGI for <quote>get_format</quote>. If it's not present, adding CGI for "GetFormat". If it's not present, adding
multiple format/type support isn't too hard - see how it's done in multiple format support isn't too hard - see how it's done in
other CGIs, e.g. config.cgi. other CGIs, e.g. config.cgi.
</para> </para>
...@@ -222,32 +176,22 @@ ...@@ -222,32 +176,22 @@
<para> <para>
You now need to decide what content type you want your template You now need to decide what content type you want your template
served as. The content types are defined in the served as. Open up the <filename>localconfig</filename> file and find the
<filename>Bugzilla/Constants.pm</filename> file in the <filename>$contenttypes</filename>
<filename>contenttypes</filename> variable. If your content type is not there, add it. Remember
constant. If your content type is not there, add it. Remember the three- or four-letter tag assigned to you content type.
the three- or four-letter tag assigned to your content type.
This tag will be part of the template filename. This tag will be part of the template filename.
</para> </para>
<note>
<para>
After adding or changing a content type, it's suitable to edit
<filename>Bugzilla/Constants.pm</filename> in order to reflect
the changes. Also, the file should be kept up to date after an
upgrade if content types have been customized in the past.
</para>
</note>
<para> <para>
Save the template as <filename>&lt;stubname&gt;-&lt;formatname&gt;.&lt;contenttypetag&gt;.tmpl</filename>. Save the template as <filename>&lt;stubname&gt;-&lt;formatname&gt;.&lt;contenttypetag&gt;.tmpl</filename>.
Try out the template by calling the CGI as Try out the template by calling the CGI as
<filename>&lt;cginame&gt;.cgi?format=&lt;formatname&gt;&amp;ctype=&lt;type&gt;</filename> . <filename>&lt;cginame&gt;.cgi?format=&lt;formatname&gt;</filename> .
</para> </para>
</section> </section>
<section id="template-specific"> <section>
<title>Particular Templates</title> <title>Particular Templates</title>
<para> <para>
...@@ -271,8 +215,7 @@ ...@@ -271,8 +215,7 @@
<para> <para>
<command>global/banner.html.tmpl</command>: <command>global/banner.html.tmpl</command>:
This contains the <quote>banner</quote>, the part of the header This contains the "banner", the part of the header that appears
that appears
at the top of all Bugzilla pages. The default banner is reasonably at the top of all Bugzilla pages. The default banner is reasonably
barren, so you'll probably want to customize this to give your barren, so you'll probably want to customize this to give your
installation a distinctive look and feel. It is recommended you installation a distinctive look and feel. It is recommended you
...@@ -288,26 +231,6 @@ ...@@ -288,26 +231,6 @@
</para> </para>
<para> <para>
<command>global/variables.none.tmpl</command>:
This defines a list of terms that may be changed in order to
<quote>brand</quote> the Bugzilla instance In this way, terms
like <quote>bugs</quote> can be replaced with <quote>issues</quote>
across the whole Bugzilla installation. The name
<quote>Bugzilla</quote> and other words can be customized as well.
</para>
<para>
<command>list/table.html.tmpl</command>:
This template controls the appearance of the bug lists created
by Bugzilla. Editing this template allows per-column control of
the width and title of a column, the maximum display length of
each entry, and the wrap behaviour of long entries.
For long bug lists, Bugzilla inserts a 'break' every 100 bugs by
default; this behaviour is also controlled by this template, and
that value can be modified here.
</para>
<para>
<command>bug/create/user-message.html.tmpl</command>: <command>bug/create/user-message.html.tmpl</command>:
This is a message that appears near the top of the bug reporting page. This is a message that appears near the top of the bug reporting page.
By modifying this, you can tell your users how they should report By modifying this, you can tell your users how they should report
...@@ -315,78 +238,50 @@ ...@@ -315,78 +238,50 @@
</para> </para>
<para> <para>
<command>bug/process/midair.html.tmpl</command>:
This is the page used if two people submit simultaneous changes to the
same bug. The second person to submit their changes will get this page
to tell them what the first person did, and ask if they wish to
overwrite those changes or go back and revisit the bug. The default
title and header on this page read "Mid-air collision detected!" If
you work in the aviation industry, or other environment where this
might be found offensive (yes, we have true stories of this happening)
you'll want to change this to something more appropriate for your
environment.
</para>
<para>
<command>bug/create/create.html.tmpl</command> and <command>bug/create/create.html.tmpl</command> and
<command>bug/create/comment.txt.tmpl</command>: <command>bug/create/comment.txt.tmpl</command>:
You may not wish to go to the effort of creating custom fields in You may wish to get bug submitters to give certain bits of structured
Bugzilla, yet you want to make sure that each bug report contains information, each in a separate input widget, for which there is not a
a number of pieces of important information for which there is not field in the database. The bug entry system has been designed in an
a special field. The bug entry system has been designed in an extensible fashion to enable you to define arbitrary fields and widgets,
extensible fashion to enable you to add arbitrary HTML widgets, and have their values appear formatted in the initial
such as drop-down lists or textboxes, to the bug entry page Description, rather than in database fields. An example of this
and have their values appear formatted in the initial comment. is the mozilla.org
A hidden field that indicates the format should be added inside <ulink url="http://bugzilla.mozilla.org/enter_bug.cgi?format=guided">guided
the form in order to make the template functional. Its value should bug submission form</ulink>.
be the suffix of the template filename. For example, if the file </para>
is called <filename>create-cust.html.tmpl</filename>, then
<programlisting>&lt;input type="hidden" name="format" value="cust"&gt;</programlisting> <para>
should be used inside the form. To make this work, create a custom template for
</para> <filename>enter_bug.cgi</filename> (the default template, on which you
could base it, is <filename>create.html.tmpl</filename>),
<para> and either call it <filename>create.html.tmpl</filename> or use a format and
An example of this is the mozilla.org call it <filename>create-&lt;formatname&gt;.html.tmpl</filename>.
<ulink url="http://landfill.bugzilla.org/bugzilla-tip/enter_bug.cgi?product=WorldControl&amp;format=guided">guided Put it in the <filename class="directory">custom/bug/create</filename>
bug submission form</ulink>. The code for this comes with the Bugzilla directory. In it, add widgets for each piece of information you'd like
distribution as an example for you to copy. It can be found in the
files
<filename>create-guided.html.tmpl</filename> and
<filename>comment-guided.html.tmpl</filename>.
</para>
<para>
So to use this feature, create a custom template for
<filename>enter_bug.cgi</filename>. The default template, on which you
could base it, is
<filename>custom/bug/create/create.html.tmpl</filename>.
Call it <filename>create-&lt;formatname&gt;.html.tmpl</filename>, and
in it, add widgets for each piece of information you'd like
collected - such as a build number, or set of steps to reproduce. collected - such as a build number, or set of steps to reproduce.
</para> </para>
<para> <para>
Then, create a template like Then, create a template like
<filename>custom/bug/create/comment.txt.tmpl</filename>, and call it <filename>custom/bug/create/comment.txt.tmpl</filename>, also named
<filename>comment-&lt;formatname&gt;.txt.tmpl</filename>. This after your format if you are using one, which
template should reference the form fields you have created using references the form fields you have created. When a bug report is
the syntax <filename>[% form.&lt;fieldname&gt; %]</filename>. When a
bug report is
submitted, the initial comment attached to the bug report will be submitted, the initial comment attached to the bug report will be
formatted according to the layout of this template. formatted according to the layout of this template.
</para> </para>
<para> <para>
For example, if your custom enter_bug template had a field For example, if your enter_bug template had a field
<programlisting>&lt;input type="text" name="buildid" size="30"&gt;</programlisting> <programlisting>&lt;input type="text" name="buildid" size="30"&gt;</programlisting>
and then your comment.txt.tmpl had and then your comment.txt.tmpl had
<programlisting>BuildID: [% form.buildid %]</programlisting> <programlisting>BuildID: [% form.buildid %]</programlisting>
then something like then
<programlisting>BuildID: 20020303</programlisting> <programlisting>BuildID: 20020303</programlisting>
would appear in the initial comment. would appear in the initial checkin comment.
</para> </para>
</section> </section>
<section id="template-http-accept"> <section id="template-http-accept">
<title>Configuring Bugzilla to Detect the User's Language</title> <title>Configuring Bugzilla to Detect the User's Language</title>
...@@ -400,7 +295,7 @@ ...@@ -400,7 +295,7 @@
</para> </para>
<para>After untarring the localizations (or creating your own) in the <para>After untarring the localizations (or creating your own) in the
<filename class="directory">BUGZILLA_ROOT/template</filename> directory, <filename class="directory">$BUGZILLA_HOME/template</filename> directory,
you must update the <option>languages</option> parameter to contain any you must update the <option>languages</option> parameter to contain any
localizations you'd like to permit. You may also wish to set the localizations you'd like to permit. You may also wish to set the
<option>defaultlanguage</option> parameter to something other than <option>defaultlanguage</option> parameter to something other than
...@@ -413,83 +308,74 @@ ...@@ -413,83 +308,74 @@
<section id="cust-hooks"> <section id="cust-hooks">
<title>Template Hooks</title> <title>Template Hooks</title>
<warning>
<para>
Template Hooks require Template Toolkit version 2.12 or
above, or the application of a patch. See <ulink
url="http://bugzilla.mozilla.org/show_bug.cgi?id=239112">bug
239112</ulink> for details.
</para>
</warning>
<para> <para>
Template hooks are a way for extensions to Bugzilla to insert code Template hooks are a way for customisers or Bugzilla extensions to insert
into the standard Bugzilla templates without modifying the template files code into the standard Bugzilla templates without modifying them.
themselves. The hooks mechanism defines a consistent API for extending The hooks mechanism defines an API for extending the
the standard templates in a way that cleanly separates standard code standard templates with a clean separation of code.
from extension code. Hooks reduce merge conflicts and make it easier This makes the changes less tied to specific versions of
to write extensions that work across multiple versions of Bugzilla, Bugzilla, and reduces merge conflicts, making
making upgrading a Bugzilla installation with installed extensions easier. upgrading a modified Bugzilla installation easier.
</para> </para>
<para> <para>
A template hook is just a named place in a standard template file A template hook is just an named place in a standard template file.
where extension template files for that hook get processed. Each hook When Bugzilla reaches this position, it checks whether there are any
has a corresponding directory in the Bugzilla directory tree. Hooking an extension template files for that hook. If so, it processes them. Each
extension template to a hook is as simple as putting the extension file hook has a directory of its own in the Bugzilla template directory tree.
into the hook's directory. When Bugzilla processes the standard template Hooking a template file on to a specific hook is as
and reaches the hook, it will process all extension templates in the simple as putting the file into that hook's directory.
hook's directory. The hooks themselves can be added into any standard
template upon request by extension authors.
</para> </para>
<para> <para>
To use hooks to extend a Bugzilla template, first make sure there is To use hooks to extend a Bugzilla template, first make sure there is a
a hook at the appropriate place within the template you want to extend. hook at the appropriate place within the template you want to extend.
Hooks appear in the standard Bugzilla templates as a single directive Hooks appear in the default Bugzilla templates as a single template
in the format directive in the format
<literal role="code">[% Hook.process("<varname>name</varname>") %]</literal>, <filename>[% Hook.process("&lt;name&gt;") %]</filename>, where
where <varname>name</varname> is the unique (within that template) &lt;name&gt;
name of the hook. is the unique (within that template) name of the hook.
</para> </para>
<para> <para>
If you aren't sure which template you want to extend or just want If you aren't sure which template you want to extend or just want to
to browse the available hooks, either use your favorite multi-file search browse the available hooks, either use your favorite multi-file search
tool (e.g. <command>grep</command>) to search the standard templates tool (e.g. grep) to search the standard templates for occurrences of
for occurrences of <methodname>Hook.process</methodname> or browse "Hook.process" or browse the directory tree in
the directory tree in <filename>$BUGZILLA_HOME/template/en/extension/hook/</filename>,
<filename>BUGZILLA_ROOT/template/en/extension/hook/</filename>, which contains a directory for each hook. Each hook's directory
which contains a directory for each hook in the following location: is located as follows:
</para> </para>
<para> <para>
<filename>BUGZILLA_ROOT/template/en/extension/hook/PATH_TO_STANDARD_TEMPLATE/STANDARD_TEMPLATE_NAME/HOOK_NAME/</filename> <filename>$BUGZILLA_HOME/template/en/extension/hook/&lt;path-to-standard-template&gt;/&lt;standard-template-name&gt;/&lt;hook-name&gt;/</filename>
</para> </para>
<para> <para>
If there is no hook at the appropriate place within the Bugzilla template If there is no hook in the appropriate place within the Bugzilla
you want to extend, template you want to extend,
<ulink url="http://bugzilla.mozilla.org/enter_bug.cgi?product=Bugzilla&amp;component=User%20Interface">file <ulink url="http://bugzilla.mozilla.org/enter_bug.cgi?product=Bugzilla&amp;component=User%20Interface">file
a bug requesting one</ulink>, specifying: a bug requesting one</ulink>, specifying:
</para> </para>
<simplelist> <simplelist>
<member>the template for which you are requesting a hook;</member> <member>the template for which you are requesting a hook;</member>
<member> <member>
where in the template you would like the hook to be placed where in the template you would like the hook to be placed (line
(line number/position for latest version of template in CVS number/position for latest version of template in CVS or description of
or description of location); location);
</member> </member>
<member>the purpose of the hook;</member> <member>the purpose of the hook;</member>
<member>a link to information about your extension, if any.</member> <member>a link to information about your extension, if any.</member>
</simplelist> </simplelist>
<para> <para>
The Bugzilla reviewers will promptly review each hook request, The Bugzilla reviewers will promptly review each hook request,
name the hook, add it to the template, check the new version name the hook,
of the template into CVS, and create the corresponding directory in add it to the template and check the new version into CVS, and add the
<filename>BUGZILLA_ROOT/template/en/extension/hook/</filename>. corresponding directory to
<filename>$BUGZILLA_HOME/template/en/extension/hook/</filename>.
</para> </para>
<para> <para>
...@@ -510,8 +396,8 @@ ...@@ -510,8 +396,8 @@
</para> </para>
<para> <para>
That's it! Now, when the standard template containing the hook That's it! Now, when the standard template containing the hook is
is processed, your extension template will be processed at the point processed, your extension template will be processed at the point
where the hook appears. where the hook appears.
</para> </para>
...@@ -519,44 +405,44 @@ ...@@ -519,44 +405,44 @@
For example, let's say you have an extension named Projman that adds For example, let's say you have an extension named Projman that adds
project management capabilities to Bugzilla. Projman has an project management capabilities to Bugzilla. Projman has an
administration interface <filename>edit-projects.cgi</filename>, administration interface <filename>edit-projects.cgi</filename>,
and you want to add a link to it into the navigation bar at the bottom and you want to
of every Bugzilla page for those users who are authorized add a link to it into the navigation bar at the bottom of every Bugzilla
to administer projects. page for those users who are authorized to administer projects.
</para> </para>
<para> <para>
The navigation bar is generated by the template file The navigation bar is generated by the template file
<filename>useful-links.html.tmpl</filename>, which is located in <filename>useful-links.html.tmpl</filename>, which is located in the
the <filename>global/</filename> subdirectory on the standard Bugzilla <filename>global/</filename> subdirectory on the standard Bugzilla
template path template path
<filename>BUGZILLA_ROOT/template/en/default/</filename>. <filename>$BUGZILLA_HOME/template/en/default/</filename>.
Looking in <filename>useful-links.html.tmpl</filename>, you find Looking in <filename>useful-links.html.tmpl</filename>, you find the
the following hook at the end of the list of standard Bugzilla following
administration links: hook at the end of the list of standard Bugzilla administration links:
</para> </para>
<programlisting><![CDATA[... <programlisting>...
[% ', <a href="editkeywords.cgi">keywords</a>' [% ', &lt;a href="editkeywords.cgi"&gt;keywords&lt;/a&gt;'
IF user.groups.editkeywords %] IF user.groups.editkeywords %]
[% Hook.process("edit") %] [% Hook.process("edit") %]
...]]></programlisting> ...</programlisting>
<para> <para>
The corresponding directory for this hook is The corresponding directory for this hook is
<filename>BUGZILLA_ROOT/template/en/extension/hook/global/useful-links.html.tmpl/edit/</filename>. <filename>$BUGZILLA_HOME/template/en/extension/hook/global/useful-links.html.tmpl/edit/</filename>.
</para> </para>
<para> <para>
You put a template named You put a template named
<filename>projman-edit-projects.html.tmpl</filename> <filename>projman-edit-projects.html.tmpl</filename>
into that directory with the following content: into that directory with the following content:
</para> </para>
<programlisting><![CDATA[...[% ', <a href="edit-projects.cgi">projects</a>' IF user.groups.projman_admins %]]]></programlisting> <programlisting>[% ', &lt;a href="edit-projects.cgi"&gt;projects&lt;/a&gt;' IF user.groups.projman_admins %]</programlisting>
<para> <para>
Voila! The link now appears after the other administration links in the Voila! The link now appears after the other administration links in the
navigation bar for users in the <literal>projman_admins</literal> group. navigation bar for users in the <filename>projman_admins</filename> group.
</para> </para>
<para> <para>
...@@ -566,24 +452,26 @@ ...@@ -566,24 +452,26 @@
<itemizedlist> <itemizedlist>
<listitem> <listitem>
<para> <para>
You may want to prefix your extension template names You may want to prefix your extension templates names with
with the name of your extension, e.g. the name of your extension, e.g.
<filename>projman-foo.html.tmpl</filename>, <filename>projman-foo.html.tmpl</filename>,
so they do not conflict with the names of templates installed by so there is no chance of a conflict with the names of
other extensions. templates installed by other extensions.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
If your extension includes entirely new templates in addition to If your extension includes entirely new templates in addition to
extensions of standard templates, it should install those new extensions of standard templates, it should install those new templates
templates into an extension-specific subdirectory of the into an extension-specific subdirectory of the
<filename>BUGZILLA_ROOT/template/en/extension/</filename> <filename>$BUGZILLA_HOME/template/en/extension/</filename>
directory. The <filename>extension/</filename> directory, like the directory.
<filename>default/</filename> and <filename>custom/</filename> The <filename>extension/</filename> directory, like the
directories, is part of the template search path, so putting templates <filename>default/</filename>
there enables them to be found by the template processor. and <filename>custom/</filename> directories, is part of the template
search path, so putting templates there enables them to be found by
the template processor.
</para> </para>
<para> <para>
...@@ -591,36 +479,18 @@ ...@@ -591,36 +479,18 @@
<filename>custom/</filename> directory (i.e. templates added by the <filename>custom/</filename> directory (i.e. templates added by the
specific installation), then in the <filename>extension/</filename> specific installation), then in the <filename>extension/</filename>
directory (i.e. templates added by extensions), and finally in the directory (i.e. templates added by extensions), and finally in the
<filename>default/</filename> directory (i.e. the standard Bugzilla <filename>default/</filename> directory, for the standard Bugzilla
templates). Thus extension templates can override standard templates, templates.
but installation-specific templates override both. Thus extension templates can override standard templates, but
</para> installation-specific templates override both.
<para>
Note that overriding standard templates with extension templates
gives you great power but also makes upgrading an installation harder.
As with custom templates, we recommend using this functionality
sparingly and only when absolutely necessary.
</para>
</listitem>
<listitem>
<para>
Installation customizers can also take advantage of hooks when adding
code to a Bugzilla template. To do so, create directories in
<filename>BUGZILLA_ROOT/template/en/custom/hook/</filename>
equivalent to the directories in
<filename>BUGZILLA_ROOT/template/en/extension/hook/</filename>
for the hooks you want to use, then place your customization templates
into those directories.
</para> </para>
<para> <para>
Obviously this method of customizing Bugzilla only lets you add code Note that overriding standard templates gives you great power but
to the standard templates; you cannot change the existing code. also makes
Nevertheless, for those customizations that only add code, this method upgrading an installation harder. As with custom templates, we
can reduce conflicts when merging changes, making upgrading recommend using this functionality sparingly and only when absolutely
your customized Bugzilla installation easier. necessary.
</para> </para>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
...@@ -655,17 +525,17 @@ ...@@ -655,17 +525,17 @@
allowed to do what. The relevant function is called allowed to do what. The relevant function is called
<filename>CheckCanChangeField()</filename>, <filename>CheckCanChangeField()</filename>,
and is found in <filename>process_bug.cgi</filename> in your and is found in <filename>process_bug.cgi</filename> in your
Bugzilla directory. If you open that file and search for Bugzilla directory. If you open that file and grep for
<quote>sub CheckCanChangeField</quote>, you'll find it. "sub CheckCanChangeField", you'll find it.
</para> </para>
<para> <para>
This function has been carefully commented to allow you to see exactly This function has been carefully commented to allow you to see exactly
how it works, and give you an idea of how to make changes to it. how it works, and give you an idea of how to make changes to it. Certain
Certain marked sections should not be changed - these are marked sections should not be changed - these are the "plumbing" which
the <quote>plumbing</quote> which makes the rest of the function work. makes the rest of the function work. In between those sections, you'll
In between those sections, you'll find snippets of code like: find snippets of code like:
<programlisting> # Allow the assignee to change anything. <programlisting> # Allow the owner to change anything.
if ($ownerid eq $whoid) { if ($ownerid eq $whoid) {
return 1; return 1;
}</programlisting> }</programlisting>
...@@ -674,11 +544,11 @@ ...@@ -674,11 +544,11 @@
<para> <para>
So, how does one go about changing this function? Well, simple changes So, how does one go about changing this function? Well, simple changes
can be made just by removing pieces - for example, if you wanted to can be made just be removing pieces - for example, if you wanted to
prevent any user adding a comment to a bug, just remove the lines marked prevent any user adding a comment to a bug, just remove the lines marked
<quote>Allow anyone to change comments.</quote> If you don't want the "Allow anyone to change comments." And if you want the reporter to have
Reporter to have any special rights on bugs they have filed, just no special rights on bugs they have filed, just remove the entire section
remove the entire section that deals with the Reporter. which refers to him.
</para> </para>
<para> <para>
...@@ -697,12 +567,8 @@ ...@@ -697,12 +567,8 @@
} }
}</programlisting> }</programlisting>
This says that only users in the group "quality_assurance" can change This says that only users in the group "quality_assurance" can change
the QA Contact field of a bug. the QA Contact field of a bug. Getting more weird:
</para> <programlisting> if (($field eq "priority") &&
<para>
Getting more weird:
<programlisting><![CDATA[ if (($field eq "priority") &&
(Bugzilla->user->email =~ /.*\@example\.com$/)) (Bugzilla->user->email =~ /.*\@example\.com$/))
{ {
if ($oldvalue eq "P1") { if ($oldvalue eq "P1") {
...@@ -711,20 +577,11 @@ ...@@ -711,20 +577,11 @@
else { else {
return 0; return 0;
} }
}]]></programlisting> }</programlisting>
This says that if the user is trying to change the priority field, This says that if the user is trying to change the priority field,
and their email address is @example.com, they can only do so if the and their email address is @example.com, they can only do so if the
old value of the field was "P1". Not very useful, but illustrative. old value of the field was "P1". Not very useful, but illustrative.
</para> </para>
<warning>
<para>
If you are modifying <filename>process_bug.cgi</filename> in any
way, do not change the code that is bounded by DO_NOT_CHANGE blocks.
Doing so could compromise security, or cause your installation to
stop working entirely.
</para>
</warning>
<para> <para>
For a list of possible field names, look in For a list of possible field names, look in
...@@ -735,29 +592,29 @@ ...@@ -735,29 +592,29 @@
</section> </section>
<section id="dbmodify"> <section id="dbmodify">
<title>Modifying Your Running System</title> <title>Modifying Your Running System</title>
<para> <para>Bugzilla optimizes database lookups by storing all relatively
Bugzilla optimizes database lookups by storing all relatively static information in the
static information in the <filename>versioncache</filename> <filename>versioncache</filename> file, located in the
file, located in the <filename class="directory">data/</filename> <filename class="directory">data/</filename>
subdirectory under your installation directory. subdirectory under your installation directory.</para>
</para>
<para> <para>If you make a change to the structural data in your database (the
If you make a change to the structural data in your database (the versions table for example), or to the
versions table for example), or to the <quote>constants</quote> <quote>constants</quote>
encoded in <filename>defparams.pl</filename>, you will need to remove
the cached content from the data directory (by doing a
<command>rm data/versioncache</command>), or your changes won't show up.
</para>
<para> encoded in <filename>defparams.pl</filename>, you will need to remove
<filename>versioncache</filename> gets regenerated automatically the cached content from the data directory (by doing a
whenever it's more than an hour old, so Bugzilla will eventually <quote>rm data/versioncache</quote>
notice your changes by itself, but generally you want it to notice
right away, so that you can test things. ), or your changes won't show up.</para>
</para>
<para> <filename>versioncache</filename>
gets automatically regenerated whenever it's more than
an hour old, so Bugzilla will eventually notice your changes by itself,
but generally you want it to notice right away, so that you can test
things.</para>
</section> </section>
<section id="dbdoc"> <section id="dbdoc">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment