View Issue Details

IDProjectCategoryView StatusLast Update
0022107mantisbtplug-inspublic2017-06-07 06:13
ReporterTiKu Assigned Todregad  
Status closedResolutionfixed 
Product Version2.0.0-beta.1 
Target Version2.0.1Fixed in Version2.0.1 
Summary0022107: EVENT_MENU_MAIN does not support relative paths

According to the documentation for EVENT_MENU_MAIN relative paths seem to be preferred over absolute URLs. However, it seems to be impossible to use relative paths. If I set 'link' to a path returned by the plugin_page function, the menu option will point to http://plugin.php/?page=..., missing the domain part.

I'm not sure whether it does matter, but my Mantis installation has no real domain. It is reachable locally only, under http://btr. Maybe this confuses the code.

TagsNo tags attached.




2017-01-04 04:21

developer   ~0054914

It's not really clear how you're trying to set your link, maybe a code snippet would help. Posting the generated HTML may also be useful, as well as your instance's relevant configuration (config_inc.php).

Please see for a working example of a plugin link with this event



2017-01-04 05:34

reporter   ~0054920

Last edited: 2017-06-07 06:13

The code of the Source Integration plugin is for Mantis 1.3. I've no problem with Mantis 1.3, but with 2.0.
My event handler for EVENT_MENU_MAIN looks like this:

function event_menu_main() {
    return array(
            'title' => 'Entry 1',
            'access_level' => UPDATER,
            'url' => plugin_page("entry1.php")
            'title' => 'Entry 2',
            'access_level' => UPDATER,
            'url' => plugin_page("entry2.php")
            'title' => 'Entry3',
            'access_level' => ADMINISTRATOR,
            'url' => plugin_page("entry3.php")

The HTML looks like this:

&lt;a href=&quot;//plugin.php?page=myPlugin/entry1.php&quot;>
&lt;i class=&quot;menu-icon fa fa-plug&quot;></i> 
&lt;span class=&quot;menu-text&quot;> Entry 1 &lt;/span>
&lt;b class=&quot;arrow&quot;></b>
&lt;a href=&quot;//plugin.php?page=myPlugin/entry2.php&quot;>
&lt;i class=&quot;menu-icon fa fa-plug&quot;></i> 
&lt;span class=&quot;menu-text&quot;> Entry 2 &lt;/span>
&lt;b class=&quot;arrow&quot;></b>
&lt;a href=&quot;//plugin.php?page=myPlugin/entry3.php&quot;>
&lt;i class=&quot;menu-icon fa fa-plug&quot;></i> 
&lt;span class=&quot;menu-text&quot;> Entry 3 &lt;/span>
&lt;b class=&quot;arrow&quot;></b>

So the problem seems to be that Mantis adds an extra slash to the link, accidently turning it into a protocol relative url. My config file contains only the database and email config.

EDIT: fix markdown



2017-01-04 07:35

developer   ~0054921

My apologies, I mistakenly linked to the wrong branch, the URL should have been

Notice the use of 'true' as second parameter to plugin_page.php, which will bypass the use of helper_mantis_url(). See [1] for an explanation of the change.

Let me know if that fixes the problem.




2017-01-04 07:49

reporter   ~0054922

Yes, this fixes the problem, thank you. However, I'm not really convinced that this is the way to go. Maybe I misunderstand the use of the $p_redirect parameter. To me this seems more like a workaround than a proper solution. In my opinion a proper solution would be to check whether the link starts with a slash and not add an extra slash if it does.



2017-01-04 08:40

developer   ~0054923

this seems more like a workaround than a proper solution.

You may be right, actually.

a proper solution would be to check whether the link starts with a slash and not add an extra slash if it does.

What helper_mantis_url() does is prepend the given URL with $g_short_path, so simply checking for a leading '/' would definitely not be the right way to fix this, as it would only work if Mantis were installed at the root. The function would have to determine whether the short path has already been added.

Try this:

diff --git a/core/helper_api.php b/core/helper_api.php
index 47d6b0e..d63d1e2 100644
--- a/core/helper_api.php
+++ b/core/helper_api.php
@@ -605,7 +605,14 @@ function helper_mantis_url( $p_url ) {
if( is_blank( $p_url ) ) {
return $p_url;

  • return config_get_global( 'short_path' ) . $p_url;
  • Return URL as-is if it already starts with short path

  • $t_short_path = config_get_global( 'short_path' );
  • if( strpos( $p_url, $t_short_path ) === 0 ) {
  • return $p_url;
  • }
  • return $t_short_path . $p_url;




2017-01-06 18:22

developer   ~0054968




2017-02-01 04:48

reporter   ~0055430

The change seems to be in the 2.0.x branch only. I cannot see it in the 2.1.0 release. Does this mean that it won't be merged to future versions of Mantis?



2017-02-01 05:24

developer   ~0055434

@TiKu the 2.0.x branch as been merged into master; this is fixed in 2.1 as well:

 $ git branch -r --contains bbf4cac7
  origin/HEAD -> origin/master


2017-02-01 05:29

reporter   ~0055435

@dregad Ah, thank you. I've misinterpreted the changelog.

Related Changesets

MantisBT: master-2.0.x bbf4cac7

2017-01-04 08:43:37


Details Diff
Allow helper_mantis_url() to be called twice

Starting with Mantis 2.0, the Layout API's layout_sidebar_menu()
function takes care of calling helper_mantis_url() for relative URLs in
menu items.

Since that function blindly prepends $g_short_path to the given URL,
this causes issues for plugins relying on a plugin_page() call with
default parameters, e.g. to display menu items via EVENT_MENU_MAIN
event, because the short path is prefixed twice resulting in generation
of an invalid URL.

As pointed out by user @TiKu in 0022107:0054922 using plugin_page()'s $p_redirect
parameter = true as it was done for the Source Integration plugin [1] is
really a workaround.

This commit fixes the issue by only prepending the short path if it is
not yet part of the given URL string.

Fixes 0022107

Affected Issues
mod - core/helper_api.php Diff File