summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkanat%bugzilla.org <>2009-08-06 17:14:47 +0200
committermkanat%bugzilla.org <>2009-08-06 17:14:47 +0200
commit360c780767308810e4f26010cb9feb84bde68fd2 (patch)
tree1584eb4b87b7d45abfde23108fbbf9651badedea
parentc048675731f016f0b4b7eb1b901ad0c3d8dd69dd (diff)
downloadbugzilla-360c780767308810e4f26010cb9feb84bde68fd2.tar.gz
bugzilla-360c780767308810e4f26010cb9feb84bde68fd2.tar.xz
Bug 508199: A hook for page.cgi
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=dkl, a=mkanat
-rw-r--r--Bugzilla/Hook.pm27
-rw-r--r--extensions/example/code/page-before_template.pl33
-rw-r--r--extensions/example/template/en/default/pages/example.html.tmpl32
-rwxr-xr-xpage.cgi7
4 files changed, 98 insertions, 1 deletions
diff --git a/Bugzilla/Hook.pm b/Bugzilla/Hook.pm
index a8f61a415..1d506424f 100644
--- a/Bugzilla/Hook.pm
+++ b/Bugzilla/Hook.pm
@@ -478,6 +478,33 @@ Params:
=back
+=head2 page-before_template
+
+This is a simple way to add your own pages to Bugzilla. This hooks C<page.cgi>,
+which loads templates from F<template/en/default/pages>. For example,
+C<page.cgi?id=fields.html> loads F<template/en/default/pages/fields.html.tmpl>.
+
+This hook is called right before the template is loaded, so that you can
+pass your own variables to your own pages.
+
+Params:
+
+=over
+
+=item C<page_id>
+
+This is the name of the page being loaded, like C<fields.html>.
+
+Note that if two extensions use the same name, it is uncertain which will
+override the others, so you should be careful with how you name your pages.
+
+=item C<vars>
+
+This is a hashref--put variables into here if you want them passed to
+your template.
+
+=back
+
=head2 product-confirm_delete
Called before displaying the confirmation message when deleting a product.
diff --git a/extensions/example/code/page-before_template.pl b/extensions/example/code/page-before_template.pl
new file mode 100644
index 000000000..dcf059367
--- /dev/null
+++ b/extensions/example/code/page-before_template.pl
@@ -0,0 +1,33 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Example Plugin.
+#
+# The Initial Developer of the Original Code is Canonical Ltd.
+# Portions created by Canonical Ltd. are Copyright (C) 2009
+# Canonical Ltd. All Rights Reserved.
+#
+# Contributor(s):
+# Max Kanat-Alexander <mkanat@bugzilla.org>
+
+
+use strict;
+use warnings;
+use Bugzilla;
+
+my %args = %{ Bugzilla->hook_args };
+my ($vars, $page) = @args{qw(vars page_id)};
+
+# You can see this hook in action by loading page.cgi?id=example.html
+if ($page eq 'example.html') {
+ $vars->{cgi_variables} = { Bugzilla->cgi->Vars };
+}
diff --git a/extensions/example/template/en/default/pages/example.html.tmpl b/extensions/example/template/en/default/pages/example.html.tmpl
new file mode 100644
index 000000000..d53f78fde
--- /dev/null
+++ b/extensions/example/template/en/default/pages/example.html.tmpl
@@ -0,0 +1,32 @@
+[%#
+ # The contents of this file are subject to the Mozilla Public
+ # License Version 1.1 (the "License"); you may not use this file
+ # except in compliance with the License. You may obtain a copy of
+ # the License at http://www.mozilla.org/MPL/
+ #
+ # Software distributed under the License is distributed on an "AS
+ # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ # implied. See the License for the specific language governing
+ # rights and limitations under the License.
+ #
+ # The Original Code is the Bugzilla Example Plugin.
+ #
+ # The Initial Developer of the Original Code is Canonical Ltd.
+ # Portions created by Canonical Ltd. are Copyright (C) 2009
+ # Canonical Ltd. All Rights Reserved.
+ #
+ # Contributor(s):
+ # Max Kanat-Alexander <mkanat@bugzilla.org>
+ #%]
+
+[% PROCESS global/header.html.tmpl
+ title = "Example Page"
+%]
+
+<p>Here's what you passed me:</p>
+[% USE Dumper %]
+<pre>
+ [% Dumper.dump_html(cgi_variables) %]
+</pre>
+
+[% PROCESS global/footer.html.tmpl %]
diff --git a/page.cgi b/page.cgi
index 290a4acb6..914ba3f22 100755
--- a/page.cgi
+++ b/page.cgi
@@ -34,6 +34,7 @@ use lib qw(. lib);
use Bugzilla;
use Bugzilla::Error;
+use Bugzilla::Hook;
Bugzilla->login();
@@ -50,13 +51,17 @@ if ($id) {
ThrowCodeError("bad_page_cgi_id", { "page_id" => $id });
}
+ my %vars;
+ Bugzilla::Hook::process('page-before_template',
+ { page_id => $id, vars => \%vars });
+
my $format = $template->get_format("pages/$1", undef, $2);
$cgi->param('id', $id);
print $cgi->header($format->{'ctype'});
- $template->process("$format->{'template'}")
+ $template->process("$format->{'template'}", \%vars)
|| ThrowTemplateError($template->error());
}
else {