jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/261758 )
Change subject: Update code that hides site notice from search engines
......................................................................
Update code that hides site notice from search engines
While it might work for Bing, document.write() does not seem to be
enough to hide text from Google, as evident from a Google Search results
page that listed various pages from frr.wikipedia.org when searching
for the text of an active site notice
Additionally, core commit d861c6593a55 has broken document.write() logic
as the mediawiki.legacy.wikibits module now replaces it with its own code,
which can cause the site notice to end up at the bottom of the page (just
after #content, the last child of the body element at the time the script is
executed) instead of in its proper place (inside #siteNotice).
Instead of document.write(), use a temporary placeholder element and replace
it with parsed HTML directly using proper DOM methods.
Bug: T108811
Bug: T125323
Change-Id: I8052f01519f22558630489f97fc0ce126bf76dac
---
M DismissableSiteNotice.hooks.php
1 file changed, 21 insertions(+), 2 deletions(-)
Approvals:
Florianschmidtwelzow: Looks good to me, approved
jenkins-bot: Verified
diff --git a/DismissableSiteNotice.hooks.php b/DismissableSiteNotice.hooks.php
index d5b5c91..38475e5 100644
--- a/DismissableSiteNotice.hooks.php
+++ b/DismissableSiteNotice.hooks.php
@@ -39,8 +39,27 @@
if ( $skin->getUser()->isAnon() ) {
// Hide the sitenotice from search engines (see bug
T11209 comment 4)
- // XXX: Does this actually work?
- $notice = Html::inlineScript( Xml::encodeJsCall(
'document.write', array( $notice ) ) );
+ // NOTE: Is this actually effective?
+ // NOTE: Avoid document.write (T125323)
+ // NOTE: Must be compatible with JavaScript in ancient
Grade C browsers.
+ $jsWrapped =
+ '<div
id="mw-dismissablenotice-anonplace"></div>' .
+ Html::inlineScript(
+ '(function(){' .
+ 'var
node=document.getElementById("mw-dismissablenotice-anonplace");' .
+ 'if(node){'.
+ // Replace placeholder with parsed HTML
from $notice.
+ // Setting outerHTML is supported in
all Grade C browsers
+ // and gracefully fallsback to just
setting a property.
+ // It is short for:
+ // - Create temporary element or
document fragment
+ // - Set innerHTML.
+ // - Replace node with wrapper's child
nodes.
+ 'node.outerHTML=' . Xml::encodeJsVar(
$notice ) . ';' .
+ '}' .
+ '}());'
+ );
+ $notice = $jsWrapped;
}
return true;
--
To view, visit https://gerrit.wikimedia.org/r/261758
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8052f01519f22558630489f97fc0ce126bf76dac
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/DismissableSiteNotice
Gerrit-Branch: master
Gerrit-Owner: PleaseStand <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits