View Issue Details

IDProjectCategoryView StatusLast Update
0022107mantisbtplug-inspublic2017-01-09 09:06
Assigned Todregad 
Status resolvedResolutionfixed 
Product Version2.0.0-beta.1 
Target Version2.0.xFixed in Version2.0.x 
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.

Im 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

Its not really clear how youre trying to set your link, maybe a code snippet would help. Posting the generated HTML may also be useful, as well as your instances 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. Ive 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, Im 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


    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.x
    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.x