View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0022107||mantisbt||plug-ins||public||2017-01-03 18:58||2017-06-07 06:13|
|Target Version||2.0.1||Fixed in Version||2.0.1|
|Summary||0022107: 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.
|Tags||No tags attached.|
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 https://github.com/mantisbt-plugins/source-integration/blob/master/Source/Source.php#L145 for a working example of a plugin link with this event
The code of the Source Integration plugin is for Mantis 1.3. I've no problem with Mantis 1.3, but with 2.0.
The HTML looks like this:
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
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  for an explanation of the change.
Let me know if that fixes the problem.
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.
You may be right, actually.
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.
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?
@TiKu the 2.0.x branch as been merged into master; this is fixed in 2.1 as well:
@dregad Ah, thank you. I've misinterpreted the changelog.
MantisBT: master-2.0.x bbf4cac7
2017-01-04 08:43:37Details 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
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  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.
|mod - core/helper_api.php||Diff File|