summary refs log tree commit diff
path: root/MantisSmalltech.php
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@internetsafetylabs.org>2025-10-08 06:59:43 -0700
committerIrene Knapp <ireneista@internetsafetylabs.org>2025-10-08 14:56:13 -0700
commit028e89d0dc1aa52033d2a16cb17946abfe09e909 (patch)
treeae08c013b723de680e3a3b1efe69e07a833d306f /MantisSmalltech.php
parentca9e5d974a7add7ab0e25e0076a7e77e2b7072e1 (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
Diffstat (limited to 'MantisSmalltech.php')
-rw-r--r--MantisSmalltech.php47
1 files changed, 36 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|>)))((?:[\\(\\[\\{\']|&quot;)*)'
       . 'cl\\/(\\d+)'
-      . '(?=(?:[\\.,;?!\\)\\]\\}\'"])*(?:$|(?=\\s)))/',
-      '\\1[cl/\\2](https://gerrit.internetsafetylabs.org/c/\\2)',
+      . '(?=(?:[\\.,;?!\\)\\]\\}\']|&quot;)*(?:$|(?=\\s|<)))/',
+      '\\1<a href="https://gerrit.internetsafetylabs.org/c/\\2">cl/\\2</a>',
       $p_string);
 
     return $p_string;