diff options
| author | Irene Knapp <ireneista@internetsafetylabs.org> | 2025-10-08 06:59:43 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@internetsafetylabs.org> | 2025-10-08 14:56:13 -0700 |
| commit | 028e89d0dc1aa52033d2a16cb17946abfe09e909 (patch) | |
| tree | ae08c013b723de680e3a3b1efe69e07a833d306f | |
| parent | ca9e5d974a7add7ab0e25e0076a7e77e2b7072e1 (diff) | |
play nicer with MantisCoreFormatting; put cl/ syntax behind config
there had been an issue where plugin load order was inconsistent; that's fixed. also, there's now a config page for the plugin. Force-Push: initial development in a new repo Change-Id: I654eba97fe6fbb12d4e97630be79b9e3c8b21404
| -rw-r--r-- | MantisSmalltech.php | 47 | ||||
| -rw-r--r-- | lang/strings_english.txt | 7 | ||||
| -rw-r--r-- | pages/config.php | 91 | ||||
| -rw-r--r-- | pages/config_edit.php | 38 |
4 files changed, 172 insertions, 11 deletions
diff --git a/MantisSmalltech.php b/MantisSmalltech.php index df6a984..6207cb0 100644 --- a/MantisSmalltech.php +++ b/MantisSmalltech.php @@ -12,11 +12,32 @@ class MantisSmalltechPlugin extends MantisPlugin { function register() { $this->name = plugin_lang_get( 'title' ); $this->description = plugin_lang_get( 'description' ); - $this->page = ''; + $this->page = 'config'; $this->version = '0.1'; $this->requires = array( 'MantisCore' => '2.3.0-dev', + + /* Plugin loading uses a topological sort. It's important that we know + * what order we load in with respect to MantisCoreFormatting, because + * that also affects the order our event bindings run in: The plugin + * that loads last, gets the event last. + * + * We would really prefer to load before MantisCoreFormatting, so that + * we can both consume and output Markdown, rather than HTML. + * Unfortunatly, the only way that we as a plugin can control that is + * by declaring a dependency, which makes us run afterwards. Otherwise, + * it winds up being unpredictable and depends on things such as which + * plugins are force-installed. + * + * By tweaking the full system configuration at the nix level, we'd have + * the ability to run before, but it's best if MantisSmalltech doesn't + * require nix. + * + * So, we run at the end, and deal with the limitations that come with + * working in HTML. + */ + 'MantisCoreFormatting' => '2.3.0-dev', ); $this->author = 'Irene Knapp'; @@ -47,27 +68,31 @@ class MantisSmalltechPlugin extends MantisPlugin { return $t_hooks; } + /** + * Default plugin configuration. + * @return array + */ + function config() { + return array( + 'process_gerrit_links' => ON + ); + } + function display_bug_id( $p_event_name, $p_string, $p_number ) { return sprintf( 'b/%u', $p_number ); } - function display_formatted( $p_event, $p_string, $p_multiline = true ): string { /* This is better documented in the Gerrit config. If you read that one - * first, there's just two things to keep in mind about this one. - * - * 1. Gerrit applies HTML-escaping to the input prior to letting us see - * it, Mantis gives us raw input. - * - * 2. Gerrit expects HTML output; Mantis expects Markdown. + * first, it's quite similar, except that Mantis leaves apostrophes alone. */ $p_string = preg_replace( - '/(?<=(?:^|(?<=\\s)))((?:[\\(\\[\\{\'"])*)' + '/(?<=(?:^|(?<=\\s|>)))((?:[\\(\\[\\{\']|")*)' . 'cl\\/(\\d+)' - . '(?=(?:[\\.,;?!\\)\\]\\}\'"])*(?:$|(?=\\s)))/', - '\\1[cl/\\2](https://gerrit.internetsafetylabs.org/c/\\2)', + . '(?=(?:[\\.,;?!\\)\\]\\}\']|")*(?:$|(?=\\s|<)))/', + '\\1<a href="https://gerrit.internetsafetylabs.org/c/\\2">cl/\\2</a>', $p_string); return $p_string; diff --git a/lang/strings_english.txt b/lang/strings_english.txt index ec164f6..d3baac9 100644 --- a/lang/strings_english.txt +++ b/lang/strings_english.txt @@ -2,3 +2,10 @@ $s_plugin_MantisSmalltech_title = 'MantisSmalltech'; $s_plugin_MantisSmalltech_description = 'The Smalltech extensions to the Mantis bug tracker'; +$s_plugin_MantisSmalltech_config = 'Configuration'; + +$s_plugin_smalltech_process_gerrit_links = 'Gerrit Link Processing'; +$s_plugin_smalltech_process_gerrit_links_info = 'Convert Gerrit CL numbers into links, when they\'re in the format cl/123.'; +$s_plugin_smalltech_enabled = 'On'; +$s_plugin_smalltech_disabled = 'Off'; + diff --git a/pages/config.php b/pages/config.php new file mode 100644 index 0000000..109e4aa --- /dev/null +++ b/pages/config.php @@ -0,0 +1,91 @@ +<?php + +auth_reauthenticate(); +access_ensure_global_level( config_get( 'manage_plugin_threshold' ) ); + +layout_page_header( lang_get( 'plugin_MantisSmalltech_title' ) ); + +layout_page_begin( 'manage_overview_page.php' ); + +print_manage_menu( 'manage_plugin_page.php' ); + +# Syntax highlighting. Currently selected theme +$t_syntax_highlighting_current_theme = plugin_config_get( 'syntax_highlighting_theme' ); +?> + +<div class="col-md-12 col-xs-12"> +<div class="space-10"></div> +<div class="form-container"> + +<form id="smalltech-config-form" action="<?php echo plugin_page( 'config_edit' )?>" method="post"> +<?php echo form_security_field( 'plugin_smalltech_config_edit' ) ?> + +<div class="widget-box widget-color-blue2"> + <div class="widget-header widget-header-small"> + <h4 class="widget-title lighter"> + <?php print_icon( 'fa-text-width', 'ace-icon' ); ?> + <?php echo sprintf( '%s: %s', + lang_get( 'plugin_MantisSmalltech_title' ), + lang_get( 'plugin_MantisSmalltech_config' ) + ) ?> + </h4> + </div> +<div class="widget-body"> +<div class="widget-main no-padding"> +<div class="table-responsive"> +<table class="table table-bordered table-condensed table-striped"> +<tr> + <th class="category width-40"> + <?php echo lang_get( 'plugin_smalltech_process_gerrit_links' ) ?> + <br> + <span class="small"> + <?php echo lang_get( 'plugin_smalltech_process_gerrit_links_info' ) ?> + </span> + </th> + <td class="center width-20"> + <label> + <input + type="radio" + name="process_gerrit_links" + value="1" + class="ace" + <?php check_checked( plugin_config_get( 'process_gerrit_links' ), ON ) ?> + > + <span class="lbl padding-6"> + <?php echo lang_get( 'plugin_smalltech_enabled' ) ?> + </span> + </label> + </td> + <td class="center width-20"> + <label> + <input + type="radio" + name="process_gerrit_links" + value="0" + class="ace" + <?php check_checked( plugin_config_get( 'process_gerrit_links' ), OFF ) ?> + > + <span class="lbl padding-6"> + <?php echo lang_get( 'plugin_smalltech_disabled' ) ?> + </span> + </label> + </td> +</tr> + +</table> +</div> +</div> +<div class="widget-toolbox padding-8 clearfix"> + <input + type="submit" class="btn btn-primary btn-white btn-round" + value="<?php echo lang_get( 'change_configuration' ) ?>" + > +</div> +</div> +</div> +</form> +</div> +</div> + +<?php +layout_page_end(); diff --git a/pages/config_edit.php b/pages/config_edit.php new file mode 100644 index 0000000..b48bdbf --- /dev/null +++ b/pages/config_edit.php @@ -0,0 +1,38 @@ +<?php +# MantisBT - A PHP based bugtracking system + +# MantisBT is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# MantisBT is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with MantisBT. If not, see <http://www.gnu.org/licenses/>. + +/** + * Edit Core Formatting Configuration + * @package MantisBT + * @copyright Copyright 2000 - 2002 Kenzaburo Ito - kenito@300baud.org + * @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net + * @link http://www.mantisbt.org + */ + +form_security_validate( 'plugin_smalltech_config_edit' ); + +auth_reauthenticate(); +access_ensure_global_level( config_get( 'manage_plugin_threshold' ) ); + +$f_process_gerrit_links = gpc_get_int( 'process_gerrit_links', ON ); + +if( plugin_config_get( 'process_gerrit_links' ) != $f_process_gerrit_links ) { + plugin_config_set( 'process_gerrit_links', $f_process_gerrit_links ); +} + +form_security_purge( 'plugin_smalltech_config_edit' ); + +print_header_redirect( plugin_page( 'config', true ) ); |