From 404dc5496967203c5f99755340f43d712420446a Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Thu, 14 Jun 2018 17:50:08 -0700 Subject: Bug 1468848 - Change presentation of show_bug.cgi urls to be /bug/ID or /bug/ALIAS. --- .htaccess | 3 ++- Bugzilla/Install/Localconfig.pm | 13 ++++++++++--- README.rst | 5 ++++- .../hook/global/header-additional_header.html.tmpl | 2 +- .../template/en/default/bug_modal/header.html.tmpl | 1 + extensions/BugModal/web/bug_modal.js | 18 +++++++++++------- .../en/default/hook/global/header-start.html.tmpl | 2 +- template/en/default/global/header.html.tmpl | 1 + template/en/default/setup/strings.txt.pl | 4 ++++ 9 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.htaccess b/.htaccess index ee7d296b0..ac0e40d88 100644 --- a/.htaccess +++ b/.htaccess @@ -42,7 +42,6 @@ RewriteRule ^template_cache.deleteme/ - [F,L,NC] RewriteRule ^review$ page.cgi?id=splinter.html$1 [QSA] RewriteRule ^user_?profile$ page.cgi?id=user_profile.html$1 [QSA] RewriteRule ^request_defer$ page.cgi?id=request_defer.html$1 [QSA] -RewriteRule ^([0-9]+)$ show_bug.cgi?id=$1 [QSA] RewriteRule ^favicon\.ico$ extensions/BMO/web/images/favicon.ico RewriteRule ^form[\.:]itrequest$ enter_bug.cgi?product=Infrastructure+\%26+Operations&format=itrequest [QSA] RewriteRule ^form[\.:](mozlist|poweredby|presentation|trademark|recoverykey)$ enter_bug.cgi?product=mozilla.org&format=$1 [QSA] @@ -84,6 +83,8 @@ RewriteRule ^form[\.:]shield[\.:]studies$ enter_bug.cgi?product=Shield&format=sh RewriteRule ^form[\.:]client[\.:]bounty$ enter_bug.cgi?product=Firefox&format=client-bounty [QSA] RewriteRule ^rest - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteRule ^rest/(.*)$ rest.cgi/$1 [NE] +RewriteRule ^bug/([^/]+)$ show_bug.cgi?id=$1 [NE] +RewriteRule ^([0-9]+)$ show_bug.cgi?id=$1 [QSA] RewriteRule ^(?:latest|1\.2|1\.3)/(.*)$ extensions/BzAPI/bin/rest.cgi/$1 [NE] RewriteRule ^bzapi/(.*)$ extensions/BzAPI/bin/rest.cgi/$1 [NE] RewriteRule ^login$ index.cgi?GoAheadAndLogIn=1 [NE] diff --git a/Bugzilla/Install/Localconfig.pm b/Bugzilla/Install/Localconfig.pm index e1a8e0909..f6333f218 100644 --- a/Bugzilla/Install/Localconfig.pm +++ b/Bugzilla/Install/Localconfig.pm @@ -163,6 +163,10 @@ use constant LOCALCONFIG_VARS => ( name => 'urlbase', default => _migrate_param( "urlbase", "" ), }, + { + name => 'canonical_urlbase', + default => '', + }, { name => 'attachment_base', default => _migrate_param( "attachment_base", '' ), @@ -286,13 +290,16 @@ sub _read_localconfig_from_file { sub read_localconfig { my ($include_deprecated) = @_; - + my $lc; if ($ENV{LOCALCONFIG_ENV}) { - return _read_localconfig_from_env(); + $lc = _read_localconfig_from_env(); } else { - return _read_localconfig_from_file($include_deprecated); + $lc = _read_localconfig_from_file($include_deprecated); } + $lc->{canonical_urlbase} //= $lc->{urlbase}; + + return $lc; } # diff --git a/README.rst b/README.rst index d8986fc73..bbc91bff2 100644 --- a/README.rst +++ b/README.rst @@ -246,9 +246,12 @@ BUGZILLA_UNSAFE_AUTH_DELEGATION BMO_urlbase The public url for this instance. Note that if this begins with https:// - abd BMO_inbound_proxies is set to '*' Bugzilla will believe the connection to it + and BMO_inbound_proxies is set to '*' Bugzilla will believe the connection to it is using SSL. +BMO_canonical_urlbase + The public url for the production instance, if different from urlbase above. + BMO_attachment_base This is the url for attachments. When the allow_attachment_display parameter is on, it is possible for a diff --git a/extensions/BMO/template/en/default/hook/global/header-additional_header.html.tmpl b/extensions/BMO/template/en/default/hook/global/header-additional_header.html.tmpl index f1896dccc..d7a4cc2a5 100644 --- a/extensions/BMO/template/en/default/hook/global/header-additional_header.html.tmpl +++ b/extensions/BMO/template/en/default/hook/global/header-additional_header.html.tmpl @@ -21,7 +21,7 @@ [% IF bug %] - + [% END %] [%# *** Bug List Navigation *** %] diff --git a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl index 38b6b572f..a21e9c268 100644 --- a/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/header.html.tmpl @@ -94,6 +94,7 @@ [%# expose useful data to js %] BUGZILLA.bug_id = [% bug.id FILTER none %]; BUGZILLA.bug_title = '[% unfiltered_title FILTER js %]'; + BUGZILLA.bug_alias = '[% bug.alias FILTER js %]'; BUGZILLA.user = { id: [% user.id FILTER none %], login: '[% user.login FILTER js %]', diff --git a/extensions/BugModal/web/bug_modal.js b/extensions/BugModal/web/bug_modal.js index bf5c300e1..9d2701e51 100644 --- a/extensions/BugModal/web/bug_modal.js +++ b/extensions/BugModal/web/bug_modal.js @@ -1344,15 +1344,19 @@ function confirmUnsafeURL(url) { // fix url after bug creation/update if (history && history.replaceState) { - var href = document.location.href; - if (!href.match(/show_bug\.cgi/)) { - history.replaceState(null, BUGZILLA.bug_title, 'show_bug.cgi?id=' + BUGZILLA.bug_id); + let bug_id = BUGZILLA.bug_id; + let bug_alias = BUGZILLA.bug_alias; + let bug_slug = bug_alias || bug_id; + let url = new URL(document.location.href); + if (!url.pathname.match(/^bug\/[0-9]+/)) { + url.searchParams.delete("id"); + let new_url = url.search ? `/bug/${bug_slug}${url.search}` : `/bug/${bug_slug}`; + if (url.hash) { + new_url += url.hash; + } + history.replaceState(null, BUGZILLA.bug_title, new_url); document.title = BUGZILLA.bug_title; } - if (href.match(/show_bug\.cgi\?.*list_id=/)) { - href = href.replace(/[\?&]+list_id=(\d+|cookie)/, ''); - history.replaceState(null, BUGZILLA.bug_title, href); - } } // ajax wrapper, to simplify error handling and auth diff --git a/extensions/OpenGraph/template/en/default/hook/global/header-start.html.tmpl b/extensions/OpenGraph/template/en/default/hook/global/header-start.html.tmpl index 51c388d42..247e44ea9 100644 --- a/extensions/OpenGraph/template/en/default/hook/global/header-start.html.tmpl +++ b/extensions/OpenGraph/template/en/default/hook/global/header-start.html.tmpl @@ -9,7 +9,7 @@ [% USE Bugzilla %] - + [% IF bug %] diff --git a/template/en/default/global/header.html.tmpl b/template/en/default/global/header.html.tmpl index 6b56a5d30..771fa801b 100644 --- a/template/en/default/global/header.html.tmpl +++ b/template/en/default/global/header.html.tmpl @@ -136,6 +136,7 @@ + [% title %] diff --git a/template/en/default/setup/strings.txt.pl b/template/en/default/setup/strings.txt.pl index 8726a8b13..fe375400d 100644 --- a/template/en/default/setup/strings.txt.pl +++ b/template/en/default/setup/strings.txt.pl @@ -230,6 +230,10 @@ Only the keys listed below can be overridden. END localconfig_urlbase => <<'END', The URL that is the common initial leading part of all URLs. +END + localconfig_canonical_urlbase => <<'END', +The URL that is the canonical initial leading part of all URLs. +This will be the production url for a dev site, for instance. END localconfig_use_suexec => <<'END', Set this to 1 if Bugzilla runs in an Apache SuexecUserGroup environment. -- cgit v1.2.3-24-g4f1b