cffb8fcb4dff1693ded92803c47c317f8ed02e1b max Wed Sep 27 10:07:22 2023 -0700 switching off translation bar for DNA output, refs #32275 diff --git src/lib/htmshell.c src/lib/htmshell.c index 2614cc4..11d5b19 100644 --- src/lib/htmshell.c +++ src/lib/htmshell.c @@ -17,47 +17,56 @@ #include "errAbort.h" #include "dnautil.h" #include "base64.h" jmp_buf htmlRecover; boolean htmlWarnBoxSetUpAlready=FALSE; static bool NoEscape = FALSE; static bool errorsNoHeader = FALSE; static char *analyticsKey = NULL; +static bool doNotTranslate = FALSE; + void htmlSuppressErrors() /* Do not output a http header for error messages. Makes sure that very early * errors are not shown back to the user but trigger a 500 error, */ { errorsNoHeader = TRUE; } void htmlNoEscape() { NoEscape = TRUE; } void htmlDoEscape() { NoEscape = FALSE; } +void htmlDoNotTranslate() +/* add <html> and <head> tags to tell browsers and chrome in particular not to translate this page. + * DNA is recognized as Swedish otherwise and the translate will remove nucleotides */ +{ + doNotTranslate = TRUE; +} + void htmlVaEncodeErrorText(char *format, va_list args) /* Write an error message encoded against XSS. */ { va_list argscp; va_copy(argscp, args); char warning[1024]; struct dyString *ds = dyStringNew(1024); vaHtmlDyStringPrintf(ds, format, args); int n = ds->stringSize; int nLimit = sizeof(warning) - 1; if (ds->stringSize > nLimit) n = nLimit; safencpy(warning, sizeof warning, ds->string, n); if (ds->stringSize > nLimit) @@ -1113,32 +1122,41 @@ if (printDocType) { //#define TOO_TIMID_FOR_CURRENT_HTML_STANDARDS #ifdef TOO_TIMID_FOR_CURRENT_HTML_STANDARDS fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n", f); #else///ifndef TOO_TIMID_FOR_CURRENT_HTML_STANDARDS char *browserVersion; if (btIE == cgiClientBrowser(&browserVersion, NULL, NULL) && *browserVersion < '8') fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n", f); else fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " "\"http://www.w3.org/TR/html4/loose.dtd\">\n",f); // Strict would be nice since it fixes atleast one IE problem (use of :hover CSS pseudoclass) #endif///ndef TOO_TIMID_FOR_CURRENT_HTML_STANDARDS } + +if (doNotTranslate) + fputs("<HTML lang='en' class='notranslate' translate='no'>\n", f); // switches off auto-translation question +else fputs("<HTML>\n", f); + fputs("<HEAD>\n", f); + +if (doNotTranslate) + fputs("<meta name='google' content='notranslate' />\n", f); // switches off translation bar in Chrome and related browsers + // CSP header generateCspMetaHeader(f); fputs(head, f); htmlFprintf(f,"<TITLE>%s</TITLE>\n", title); if (endsWith(title,"Login - UCSC Genome Browser")) fprintf(f,"\t<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;CHARSET=iso-8859-1\">\n"); fprintf(f, "\t<META http-equiv=\"Content-Script-Type\" content=\"text/javascript\">\n"); if (htmlStyle != NULL) fputs(htmlStyle, f); if (htmlStyleSheet != NULL) fprintf(f,"<link href=\"%s\" rel=\"stylesheet\" type=\"text/css\">\n", htmlStyleSheet); if (htmlStyleTheme != NULL) fputs(htmlStyleTheme, f); if (analyticsKey)