mantisbt-plugins / source-integration

Source control integration plugin framework for MantisBT, including support for Github, Gitlab, Bitbucket, Gitea, Gitweb, Cgit, Subversion, Mercurial and more
http://noswap.com/projects/source-integration/
MIT License
181 stars 130 forks source link

How to setup "Diff" and "File" Button #315

Closed promat1 closed 4 years ago

promat1 commented 5 years ago

Hey, I am using the source SVN plugin and it is set up and working. But I don't find a way to configure the "Diff" and "File" Button. I think I just need to set up the correct path to binary, but I tried several paths and it is not working.

Thank you in advance. BR

dregad commented 5 years ago

Unfortunately I do not use SVN so I'm afraid I can't help you there.

serby2016 commented 5 years ago

Seems that SourceWebSVN extending SourceSVN doesn't work. A quick solution is to merge SourceWebSVN + SourceSVN > SourceSVN, and rename all keys in lang/* files.

promat01 commented 5 years ago

Thank you serby2016 for the quick solution. What do you mean by "rename all keys in lang/* files"? I don't understand what to do after merge... Thanks in advance.

serby2016 commented 5 years ago

All pairs key=value from lang/.txt from folder SourceWebSVN must be copied to lang/.txt (eq. strings_english.txt) into SourceSVN but eliminate "Web" from key name so if a key is named let's say "$s_plugin_SourceWebSVN_websvn" you must rename it to "$s_plugin_SourceSVN_websvn" since the key is not related to SourceWebSVN plugin but SourceSVN after merging. Sorry for my brief ness but I'm on holiday from my phone, hope to solve the issue till I'll reach my pc.

promat01 commented 4 years ago

Hey serby2016 could you please explain the process more in detail. I still don't understand exactly what to do. Hope you had a good holiday. Thanks in advance.

serby2016 commented 4 years ago

step 1. In SourceSVN.php I've replaced this lines (from 76 to 82):

        public function url_repo( $p_repo, $p_changeset=null ) {}

    public function url_changeset( $p_repo, $p_changeset ) {}

    public function url_file( $p_repo, $p_changeset, $p_file ) {}

    public function url_diff( $p_repo, $p_changeset, $p_file ) {}

with these ones:

/**
     * Retrieves the repository's multiviews setting (set to true if WebSVN is
     * configured to use Apache Multiviews link format)
     * @param object $p_repo repository
     * @return bool
     */
    private function is_multiviews( $p_repo ) {
        return isset( $p_repo->info['websvn_multiviews'] )
            ? $p_repo->info['websvn_multiviews']
            : false;
    }

    private function get_websvn_url( $p_repo ) {
        return isset( $p_repo->info['websvn_url'] )
            ? $p_repo->info['websvn_url']
            : '';
    }

    private function get_websvn_name( $p_repo ) {
        return isset( $p_repo->info['websvn_name'] )
            ? $p_repo->info['websvn_name']
            : '';
    }

    private function get_websvn_path( $p_repo ) {
        return isset( $p_repo->info['websvn_path'] )
            ? $p_repo->info['websvn_path']
            : '';
    }
/**
     * Builds the WebSVN URL base string
     * @param object $p_repo repository
     * @param string $p_op optional WebSVN operation
     * @param string $p_file optional filename (as absolute path from root)
     * @param array $p_opts optional additional WebSVN URL parameters
     * @return string WebSVN URL
     */
    private function url_base( $p_repo, $p_op = '', $p_file = '', $p_opts=array() ) {
        $t_name = urlencode( $this->get_websvn_name( $p_repo ) );

        # The 'sc' (show change) option is obsolete since WebSVN 2.1.0 (r621)
        # we keep it for Compatibility with oder releases
        if( !isset( $p_opts['sc'] ) ) {
            $p_opts['sc'] = 1;
        }

        if( $this->is_multiviews( $p_repo ) ) {
            $t_url = $this->get_websvn_url( $p_repo ) . $t_name;

            if( is_blank( $p_file ) ) {
                $t_url .= $this->get_websvn_path( $p_repo );
            } else {
                $t_url .= $p_file;
            }

            $t_url = rtrim( $t_url, '/' );

            if( !is_blank( $p_op ) ) {
                $p_opts['op'] = $p_op;
            }
        } else {
            $t_url = $this->get_websvn_url( $p_repo );

            if( !is_blank( $p_op ) ) {
                $t_url .= "$p_op.php";
            }

            if( is_blank( $p_file ) ) {
                $t_path = $this->get_websvn_path( $p_repo );
            } else {
                $t_path = $p_file;
            }
            if( !is_blank( $t_path ) ) {
                $p_opts['path'] = $t_path;
            }

            $p_opts['repname'] = $t_name;
        }

        return $t_url . '?' . http_build_query( $p_opts );
    }
    public function url_repo( $p_repo, $p_changeset=null ) {
        $t_opts = array();

        if ( !is_null( $p_changeset ) ) {
            $t_opts['rev'] = $p_changeset->revision;
        }

        $t_op = $this->is_multiviews( $p_repo ) ? '' : 'listing';

        return $this->url_base( $p_repo, $t_op, '', $t_opts);
}

public function url_changeset( $p_repo, $p_changeset ) {
        $t_rev = $p_changeset->revision;
        $t_path = $this->get_websvn_path( $p_repo );
        $t_opts = array();
        $t_opts['compare[0]'] = $t_path . '@' . ($t_rev - 1);
        $t_opts['compare[1]'] = $t_path . '@' . $t_rev;

        return $this->url_base( $p_repo, 'comp', '', $t_opts );
    }

    public function url_file( $p_repo, $p_changeset, $p_file ) {
        # if the file has been removed, it doesn't exist in current revision
        # so we generate a link to (current revision - 1)
        $t_revision = ($p_file->action == 'rm')
                    ? $p_changeset->revision - 1
                    : $p_changeset->revision;

        $t_opts = array();
        $t_opts['rev'] = $t_revision;
        $t_opts['peg'] = $t_revision;

        return $this->url_base( $p_repo, 'filedetails', $p_file->filename, $t_opts );
    }

    public function url_diff( $p_repo, $p_changeset, $p_file ) {
        if ( $p_file->action == 'rm' || $p_file->action == 'add' ) {
            return '';
        }

        $t_opts = array();
        $t_opts['rev'] = $p_changeset->revision;
        $t_opts['peg'] = $p_changeset->revision;

        return $this->url_base( $p_repo, 'diff', $p_file->filename, $t_opts );
    }

step 2. In function public function update_repo_form( $p_repo ) at the end put these lines starting from line 92

        $t_url  = $this->get_websvn_url( $p_repo );
        $t_name = $this->get_websvn_name( $p_repo );
        $t_path = $this->get_websvn_path( $p_repo );

step 3. Stating from line 141 added these :

<!-- websvn -->
<tr>
    <td class="category"><?php echo plugin_lang_get( 'websvn_url' ) ?></td>
    <td>
        <input type="text" name="websvn_url" maxlength="250" size="40" value="<?php echo string_attribute( $t_url ) ?>"/>
    </td>
</tr>
<tr>
    <td class="category"><?php echo plugin_lang_get( 'websvn_multiviews' ) ?></td>
    <td>
        <label>
            <input name="websvn_multiviews" type="checkbox" class="ace" <?php echo ($this->is_multiviews( $p_repo ) ? 'checked="checked"' : '') ?>/>
            <span class="lbl"></span>
        </label>
    </td>
</tr>
<tr>
    <td class="category"><?php echo plugin_lang_get( 'websvn_name' ) ?></td>
    <td>
        <input type="text" name="websvn_name" maxlength="250" size="40" value="<?php echo string_attribute( $t_name ) ?>"/>
    </td>
</tr>
<tr>
    <td class="category"><?php echo plugin_lang_get( 'websvn_path' ) ?></td>
    <td>
        <input type="text" name="websvn_path" maxlength="250" size="40" value="<?php echo string_attribute( $t_path ) ?>"/>
    </td>
</tr>

All lines references are from original source of SourceSVN.php Now for lang*: step 4. Copy these lines:

$s_plugin_SourceWebSVN_websvn_url = 'WebSVN URL<br/><span class="small">(With trailing slash)</span>';
$s_plugin_SourceWebSVN_websvn_multiviews = 'WebSVN Multiviews Mode<br/><span class="small" display>(Check if WebSVN runs under<br />&nbsp;Apache in Multiviews mode)</span>';
$s_plugin_SourceWebSVN_websvn_name = 'WebSVN Name<br/><span class="small">(Repository directory)</span>';
$s_plugin_SourceWebSVN_websvn_path = 'WebSVN Path<br/><span class="small">(From repository root)</span>';

$s_plugin_SourceWebSVN_svn_username = 'WebSVN Username';
$s_plugin_SourceWebSVN_svn_password = 'WebSVN Password';
$s_plugin_SourceWebSVN_standard_repo = 'Standard Repository<br/><span class="small">(trunk/branches/tags)</span>';
$s_plugin_SourceWebSVN_trunk_path = 'Trunk Path<br/><span class="small">(Non-standard repository)</span>';
$s_plugin_SourceWebSVN_branch_path = 'Branch Path<br/><span class="small">(Non-standard repository)</span>';
$s_plugin_SourceWebSVN_tag_path = 'Tag Path<br/><span class="small">(Non-standard repository)</span>';
$s_plugin_SourceWebSVN_ignore_paths = 'Ignore Other Paths<br/><span class="small">(Non-standard repository)</span>';

from "plugins/SourceWebSVN/lang/strings_english.txt" to "plugins/SourceSVN/lang/strings_english.txt" but replacing $s_plugin_SourceWebSVN_ with $s_plugin_SourceSVN_

serby2016 commented 4 years ago

step 1. In SourceSVN.php I've replaced this lines (from 76 to 82):

        public function url_repo( $p_repo, $p_changeset=null ) {}

    public function url_changeset( $p_repo, $p_changeset ) {}

    public function url_file( $p_repo, $p_changeset, $p_file ) {}

    public function url_diff( $p_repo, $p_changeset, $p_file ) {}

with these ones:

/**
     * Retrieves the repository's multiviews setting (set to true if WebSVN is
     * configured to use Apache Multiviews link format)
     * @param object $p_repo repository
     * @return bool
     */
    private function is_multiviews( $p_repo ) {
        return isset( $p_repo->info['websvn_multiviews'] )
            ? $p_repo->info['websvn_multiviews']
            : false;
    }

    private function get_websvn_url( $p_repo ) {
        return isset( $p_repo->info['websvn_url'] )
            ? $p_repo->info['websvn_url']
            : '';
    }

    private function get_websvn_name( $p_repo ) {
        return isset( $p_repo->info['websvn_name'] )
            ? $p_repo->info['websvn_name']
            : '';
    }

    private function get_websvn_path( $p_repo ) {
        return isset( $p_repo->info['websvn_path'] )
            ? $p_repo->info['websvn_path']
            : '';
    }
/**
     * Builds the WebSVN URL base string
     * @param object $p_repo repository
     * @param string $p_op optional WebSVN operation
     * @param string $p_file optional filename (as absolute path from root)
     * @param array $p_opts optional additional WebSVN URL parameters
     * @return string WebSVN URL
     */
    private function url_base( $p_repo, $p_op = '', $p_file = '', $p_opts=array() ) {
        $t_name = urlencode( $this->get_websvn_name( $p_repo ) );

        # The 'sc' (show change) option is obsolete since WebSVN 2.1.0 (r621)
        # we keep it for Compatibility with oder releases
        if( !isset( $p_opts['sc'] ) ) {
            $p_opts['sc'] = 1;
        }

        if( $this->is_multiviews( $p_repo ) ) {
            $t_url = $this->get_websvn_url( $p_repo ) . $t_name;

            if( is_blank( $p_file ) ) {
                $t_url .= $this->get_websvn_path( $p_repo );
            } else {
                $t_url .= $p_file;
            }

            $t_url = rtrim( $t_url, '/' );

            if( !is_blank( $p_op ) ) {
                $p_opts['op'] = $p_op;
            }
        } else {
            $t_url = $this->get_websvn_url( $p_repo );

            if( !is_blank( $p_op ) ) {
                $t_url .= "$p_op.php";
            }

            if( is_blank( $p_file ) ) {
                $t_path = $this->get_websvn_path( $p_repo );
            } else {
                $t_path = $p_file;
            }
            if( !is_blank( $t_path ) ) {
                $p_opts['path'] = $t_path;
            }

            $p_opts['repname'] = $t_name;
        }

        return $t_url . '?' . http_build_query( $p_opts );
    }
    public function url_repo( $p_repo, $p_changeset=null ) {
        $t_opts = array();

        if ( !is_null( $p_changeset ) ) {
            $t_opts['rev'] = $p_changeset->revision;
        }

        $t_op = $this->is_multiviews( $p_repo ) ? '' : 'listing';

        return $this->url_base( $p_repo, $t_op, '', $t_opts);
}

public function url_changeset( $p_repo, $p_changeset ) {
        $t_rev = $p_changeset->revision;
        $t_path = $this->get_websvn_path( $p_repo );
        $t_opts = array();
        $t_opts['compare[0]'] = $t_path . '@' . ($t_rev - 1);
        $t_opts['compare[1]'] = $t_path . '@' . $t_rev;

        return $this->url_base( $p_repo, 'comp', '', $t_opts );
    }

    public function url_file( $p_repo, $p_changeset, $p_file ) {
        # if the file has been removed, it doesn't exist in current revision
        # so we generate a link to (current revision - 1)
        $t_revision = ($p_file->action == 'rm')
                    ? $p_changeset->revision - 1
                    : $p_changeset->revision;

        $t_opts = array();
        $t_opts['rev'] = $t_revision;
        $t_opts['peg'] = $t_revision;

        return $this->url_base( $p_repo, 'filedetails', $p_file->filename, $t_opts );
    }

    public function url_diff( $p_repo, $p_changeset, $p_file ) {
        if ( $p_file->action == 'rm' || $p_file->action == 'add' ) {
            return '';
        }

        $t_opts = array();
        $t_opts['rev'] = $p_changeset->revision;
        $t_opts['peg'] = $p_changeset->revision;

        return $this->url_base( $p_repo, 'diff', $p_file->filename, $t_opts );
    }

step 2. In function public function update_repo_form( $p_repo ) at the end put these lines starting from line 92

        $t_url  = $this->get_websvn_url( $p_repo );
        $t_name = $this->get_websvn_name( $p_repo );
        $t_path = $this->get_websvn_path( $p_repo );

step 3. Stating from line 141 added these :

<!-- websvn -->
<tr>
    <td class="category"><?php echo plugin_lang_get( 'websvn_url' ) ?></td>
    <td>
        <input type="text" name="websvn_url" maxlength="250" size="40" value="<?php echo string_attribute( $t_url ) ?>"/>
    </td>
</tr>
<tr>
    <td class="category"><?php echo plugin_lang_get( 'websvn_multiviews' ) ?></td>
    <td>
        <label>
            <input name="websvn_multiviews" type="checkbox" class="ace" <?php echo ($this->is_multiviews( $p_repo ) ? 'checked="checked"' : '') ?>/>
            <span class="lbl"></span>
        </label>
    </td>
</tr>
<tr>
    <td class="category"><?php echo plugin_lang_get( 'websvn_name' ) ?></td>
    <td>
        <input type="text" name="websvn_name" maxlength="250" size="40" value="<?php echo string_attribute( $t_name ) ?>"/>
    </td>
</tr>
<tr>
    <td class="category"><?php echo plugin_lang_get( 'websvn_path' ) ?></td>
    <td>
        <input type="text" name="websvn_path" maxlength="250" size="40" value="<?php echo string_attribute( $t_path ) ?>"/>
    </td>
</tr>

All lines references are from original source of SourceSVN.php Now for lang*: step 4. Copy these lines:

$s_plugin_SourceWebSVN_websvn_url = 'WebSVN URL<br/><span class="small">(With trailing slash)</span>';
$s_plugin_SourceWebSVN_websvn_multiviews = 'WebSVN Multiviews Mode<br/><span class="small" display>(Check if WebSVN runs under<br />&nbsp;Apache in Multiviews mode)</span>';
$s_plugin_SourceWebSVN_websvn_name = 'WebSVN Name<br/><span class="small">(Repository directory)</span>';
$s_plugin_SourceWebSVN_websvn_path = 'WebSVN Path<br/><span class="small">(From repository root)</span>';

$s_plugin_SourceWebSVN_svn_username = 'WebSVN Username';
$s_plugin_SourceWebSVN_svn_password = 'WebSVN Password';
$s_plugin_SourceWebSVN_standard_repo = 'Standard Repository<br/><span class="small">(trunk/branches/tags)</span>';
$s_plugin_SourceWebSVN_trunk_path = 'Trunk Path<br/><span class="small">(Non-standard repository)</span>';
$s_plugin_SourceWebSVN_branch_path = 'Branch Path<br/><span class="small">(Non-standard repository)</span>';
$s_plugin_SourceWebSVN_tag_path = 'Tag Path<br/><span class="small">(Non-standard repository)</span>';
$s_plugin_SourceWebSVN_ignore_paths = 'Ignore Other Paths<br/><span class="small">(Non-standard repository)</span>';

from "plugins/SourceWebSVN/lang/strings_english.txt" to "plugins/SourceSVN/lang/strings_english.txt" but replacing $s_plugin_SourceWebSVN_ with $s_plugin_SourceSVN_

So the final files looks like this: sourceSvn.tar.gz

promat01 commented 4 years ago

Thank you serby2016, I have tryed it and it seems to work. If I have any more problems, I will come back to you. Again thank you very much!