1 DEBIAN GFORGE PLUGINS HOWTO
2 --------------------------------
4 Here is a short HOWTO explaining how plugins work in Debian
5 GForge, and how to make a new one.
7 It was written by Roland Mas <lolando@debian.org>.
9 WHAT PLUGINS ARE, AND WHY THEY ARE USEFUL
10 -----------------------------------------
12 Plugins are extensions to the "core" of GForge, providing extra
13 functionality without being tightly integrated within Sourceforge
14 proper. They are useful because they allow for independent
15 development of third-party functionality, and they add flexibility to
16 Sourceforge as to what features are available on a particular
19 As an example, it's been suggested to integrate a shared calendar
20 application in Sourceforge. It's a good idea and an interesting
21 feature, but not one that everybody wants. Thus, including it in the
22 GForge code would piss off someone. Additionnally, there might
23 be several competing implementations for such a calnedar application.
24 Choosing one among them would also piss off people. So it is made
25 possible to have a system so that different implementations can exist
26 and be installed separately.
31 It is expected that a plugin is just some new feature added to
32 GForge, and not a change in the behaviour of existing features.
33 A plug-in should therefore only add files, not change existing ones.
34 Whether these files be web pages, offline scripts, static
35 documentation or else is not relevant.
37 Of course, *some* changes will have to be made to the "core" files,
38 if only to add links to new web pages, for instance. These changes
39 are acceptable, and will be discussed below. Here come the details
40 about how the plugin system is implemented.
42 - A plugin will be identified primarily by a string handle, which will
43 be static across all installations of this plugin. It should be
44 composed of lowercase letters only, because it's going to be used in
45 table names and we don't want namespace conflicts. For instance, if
46 the ACME company writes a time tracking tool plugin, the handle for
47 that plugin could be "acmetimetracker". When installed, the plugin
48 will be assigned an integer identifier. This id might vary from site
49 to site, and should not be depended upon.
51 We [the GForge-proper maintainers team] will maintain some sort
52 of list of allocated plugin names so that different plugins get
53 different allocated identifiers, see below.
55 - Tables in the database schema: special tables have been added to the
56 database schema to keep track of installed plugins. They are
57 described below (simplified descriptions):
59 | CREATE TABLE plugins (plugin_id integer,
60 | plugin_name character(32),
62 | CONSTRAINT plugins_pkey PRIMARY KEY (plugin_id)
64 | CREATE TABLE group_plugin (group_plugin_id integer,
67 | CONSTRAINT PRIMARY KEY (plugin_id),
68 | CONSTRAINT FOREIGN KEY (group_id) REFERENCES groups(group_id)
70 | CREATE TABLE user_plugin (user_plugin_id integer,
73 | CONSTRAINT PRIMARY KEY (plugin_id),
74 | CONSTRAINT FOREIGN KEY (user_id) REFERENCES users(user_id)
78 "plugins" lists the installed plugins, with the numeric id, the
79 string handle (say, "acmetimetracker") and a description.
81 "group_plugin" is a way to store the fact that a group "uses" a
82 plugin without needing to add a "uses_acmetimetracker" to the groups
83 table for each known plugin.
85 "user_plugin" is the same, for users.
87 - A plugin may create its own tables in the same database. These
88 tables must be named plugin_foo_* if the plugin's string identifier is
89 "foo". One suggested table is plugin_foo_meta_data, which should be
90 used to store the plugin meta-data, such as the installed version.
91 The plugin can then use some code like db-upgrade.pl if its database
92 schema changes over time.
94 [TODO: Standardise the command/script/something below]
95 These tables may have foreign key referential integrity constraints
96 going from them to standard tables, but not the other way round. If
97 they have, then a command/script/something must be provided so that
98 the main db-upgrade.pl can disable the constraints and re-enable them
99 afterwards in case some database schema changes are needed.
101 Similarly, a plugin may create sequences, indexes, views, etc,
102 provided that their names are prefixed with plugin_foo_ too.
104 A plugin should not modify the data in tables that do not belong to
105 it. If it really needs to, then please discuss it with us first,
106 there might be cases where it's needed/useful. Reading those data is
107 okay, but it must be careful not to leak any info to places/users
108 which normally wouldn't have had access to it.
110 - Functions in Group.class and User.class: the Group and User classes
111 now have a usesPlugin() method. It takes a single parameter, the
112 "acmetimetracker" identifier for the module, and returns a boolean if
113 the particular user/group has turned on the use of that module. Also
114 provided are setPluginUsage() methods, taking a plugin name and a
115 boolean value as arguments and returning true on success and false on
118 - A plugin should not change the existing files. Of course, it will
119 need a way to adds links to its own web pages. This is done by a
120 "hook" system. Each plugin can hook itself up to a number of hook
121 points in the main code, and execute arbitrary code when that point is
122 reached. Basically, the plugin registers itself to a global object
123 (of the PluginManager class, if you want to know). You have to call
124 the register_plugin() function, providing it an object of a subclass
125 of the Plugin class that is provided by the main code. That object
126 must provide a GetHooks() method, which returns a list of hook names.
127 Whenever one of these hooks is encountered, the object's CallHook()
128 method is called with the hook name and extra parameters that depend
129 on the hook. Adding a link to your page in some place is just a
130 matter of "subscribing" yourself to the hook that is in the
131 appropriate place, and printing the appropriate link whenever your
132 CallHook() method is called from that place.
134 Registering your plugin is done by providing a
135 /usr/lib/gforge/plugins/<pluginname>/include/<pluginname>-init.php.
136 It will be parsed by the PluginManager object. That file should
137 contain a call to register_plugin(), passing it an object of the
138 appropriate class. See the helloworld plugin for an example.
140 The hooks are managed centrally by the GForge code maintainers.
141 If you need one, please ask, we'll add it. At the time of writing,
142 there's only one hook implemented (for the helloworld plugin). It's
143 called "usermenu" and occurs in the user_menu() method of the Layout
144 class. I rely on you plugins developers to provide more ideas :-)
146 - Plugin-specific web pages should reside either in the /plugin/*/
147 URL-space (that is, plugin "foo" will probably put its files in
148 /usr/share/gforge/www/plugins/foo/) or (if the web interface is not
149 written in PHP) in /plugin/*/cgi-bin/ URL-space (files in
150 /usr/lib/sourceforge/cgi-bin/plugins/foo/).
152 If possible, and as much as possible, a plugin should use the layout
153 functions defined by GForge (Layout.class, HTML.class, or
154 whatever they're called), to ensure a consistent look and themability.
156 Of course, the previous point only applies to plugins written in
157 PHP. Plugins written in other languages are not excluded by this
158 proposal, and there is no need to restrict them. Should they appear,
159 they might need to recode some of GForge's functions in Perl or
160 another language. I see no need to restrict that either. Only thing:
161 it would be better if the porting were as straightforward as possible.
162 Do not reimplement, please. Just translate from PHP to Perl or
163 whatever. If you do, please submit your translation to us, so that it
164 can be provided by GForge proper and maintained in common.
166 [TODO: Think about that, design, implement]
167 Speaking of languages... There should be some way to have
168 plugin-specific language files, so that the plugins can use the
169 standard methods used elsewhere in Sourceforge. I haven't thought
170 about that very deeply yet, but I think it will evolve into a
171 recommendation that the "handles" in the language files are
172 plugin_foo_page / item (as compared to the current page / item model
173 used for "core" GForge i18n strings).
175 - A plugin should register itself into the database using the provided
176 register-plugin script on its installation, and unregister itself
177 using unregister-plugin on removal. When unregistering, be careful
178 to delete all the rows in tables that contain a reference to your
179 plugin_id, so that the unregistration process (which deletes your row
180 in the plugins table) does not fail due to referential integrity errors.
182 HOW DO I MAKE A PLUGIN?
183 -----------------------
185 Your best bet would be to start with the sample "helloworld" plugin
186 and change parts of it. It shows an example of most of the things you
187 should need to make your plugin: PHP pages, configuration files, bits
188 of Apache configuration, cron jobs, etc. If you need something else,
189 please ask, we'll discuss it, (hopefully) reach an agreement on how to
190 Do It Right, and implement a sample in helloworld.
192 HOW TO NAME MY PLUGIN
193 ---------------------
195 If you plan on distributing your plugin to the public, please contact
196 the GForge maintainer with your proposed name, and we'll add it
197 to the list below. This ensures that no other plugin will use the
198 same name, so as to reduce the risk of name conflicts.
200 If you only intend to keep your plugin for yourself, you might still
201 contact us with your plugin name. If you're really nice, we might
202 consider adding it here too, so that other people who want to
203 distribute their plugin do not reuse the same name.
205 For reference, this is the list of currently used plugin names:
207 - helloworld, the plugin provided as an example.
209 -- Roland Mas <lolando@debian.org>