]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 508199: A hook for page.cgi
authormkanat%bugzilla.org <>
Thu, 6 Aug 2009 15:20:13 +0000 (15:20 +0000)
committermkanat%bugzilla.org <>
Thu, 6 Aug 2009 15:20:13 +0000 (15:20 +0000)
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=dkl, a=mkanat

Bugzilla/Hook.pm
extensions/example/code/page-before_template.pl [new file with mode: 0644]
extensions/example/template/en/default/pages/example.html.tmpl [new file with mode: 0644]
page.cgi

index 5bc2e7716efb8d68cf010a533990f3d6c28bdc7b..de35f93b536447bac9c57a04de83e250b7f4389b 100644 (file)
@@ -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 (file)
index 0000000..dcf0593
--- /dev/null
@@ -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 (file)
index 0000000..d53f78f
--- /dev/null
@@ -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 %]
index 290a4acb6bc515fb8efe0b83920e00c371eab34e..914ba3f221237e1467bdef5661289a390897246c 100755 (executable)
--- 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 {