View Issue Details

IDProjectCategoryView StatusLast Update
0022107mantisbtplug-inspublic2017-02-01 22:48
ReporterTiKuAssigned 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

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:

  • <a href="//plugin.php?page=myPlugin/entry1.php"> <i class="menu-icon fa fa-plug"> <span class="menu-text"> Entry 1 </span> </a> <b class="arrow">
  • <a href="//plugin.php?page=myPlugin/entry2.php"> <i class="menu-icon fa fa-plug"> <span class="menu-text"> Entry 2 </span> </a> <b class="arrow">
  • <a href="//plugin.php?page=myPlugin/entry3.php"> <i class="menu-icon fa fa-plug"> <span class="menu-text"> Entry 3 </span> </a> <b class="arrow">
  • [/code]
    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.



    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

    mod - core/helper_api.php Diff File

    Issue History

    Date Modified Username Field Change
    2017-01-03 18:58 TiKu New Issue
    2017-01-04 04:21 dregad Status new => feedback
    2017-01-04 04:21 dregad Note Added: 0054914
    2017-01-04 05:34 TiKu Note Added: 0054920
    2017-01-04 05:34 TiKu Status feedback => new
    2017-01-04 07:35 dregad Assigned To => dregad
    2017-01-04 07:35 dregad Status new => feedback
    2017-01-04 07:35 dregad Note Added: 0054921
    2017-01-04 07:49 TiKu Note Added: 0054922
    2017-01-04 07:49 TiKu Status feedback => assigned
    2017-01-04 08:40 dregad Note Added: 0054923
    2017-01-04 08:42 dregad Product Version 2.0.0 => 2.0.0-beta.1
    2017-01-04 08:42 dregad Target Version => 2.0.1
    2017-01-06 18:22 dregad Note Added: 0054968
    2017-01-09 09:05 dregad Changeset attached => MantisBT master-2.0.x bbf4cac7
    2017-01-09 09:05 dregad Status assigned => resolved
    2017-01-09 09:05 dregad Resolution open => fixed
    2017-01-09 09:06 dregad Fixed in Version => 2.0.1
    2017-02-01 04:48 TiKu Note Added: 0055430
    2017-02-01 05:24 dregad Note Added: 0055434
    2017-02-01 05:29 TiKu Note Added: 0055435
    2017-02-01 22:48 vboctor Status resolved => closed