Skip to content

Instantly share code, notes, and snippets.

@ernstki
Last active May 19, 2023 19:06
Show Gist options
  • Save ernstki/1c897946cfa6dd84065e1e313a9f6376 to your computer and use it in GitHub Desktop.
Save ernstki/1c897946cfa6dd84065e1e313a9f6376 to your computer and use it in GitHub Desktop.
Stop "Saved in parser cache with key" message from showing up in rendered page output; works with MediaWiki 1.30.x

Suppress MediaWiki parser cache key in rendered source

Stop messages like

<!-- Saved in parser cache with key wiki:pcache:idhash:9999-0!*!0!!en!*!* and timestamp 20180627230404 and revision id 9999
 -->

from appearing in the rendered page source for your MediaWiki articles.

This was identified as a potential liability during an internal security review within my organization, and we were asked to suppress this output if possible.

As there is no LocalSettings.php option (similar to $wgEnableParserLimitReporting for the NewPP parser report which is also rendered as an HTML comment), patching the source was the only option I could figure out.

Usage

THIS_GIST=https://gist.githubusercontent.com/ernstki/1c897946cfa6dd84065e1e313a9f6376
cd /path/to/where/your/mediawiki/installation/is
curl -sLOJ $THIS_GIST/raw/parsercache-disable-pcache-key-in-html-source.diff
patch -p0 <parsercache-disable-pcache-key-in-html-source.diff

Then keep that parsercache-disable-pcache-key-in-html-source.diff file around, because you're going to have to re-apply this patch every time you update to a new MediaWiki release (or file a bug report so that there's a config setting for it).

If (or when) the patch file stops working in the future, you'll get a message from patch about some number of "hunks" being rejected. If this happens, you can make a backup copy of the original, modify the source manually by looking at includes/parser/ParserCache.php (around line 297), then recreate the patch file like so:

cd /path/to/your/mediawiki
cp includes/parser/ParserCache.php includes/parser/ParserCache.php.orig
vim includes/parser/ParserCache.php  # or your editor of choice
diff -u includes/parser/ParserCache.php.orig \
        includes/parser/ParserCache.php >disable-pcache-key-in-html-source.diff

References

  1. https://stackoverflow.com/q/30801810
  2. https://doc.wikimedia.org/mediawiki-core/master/php/ParserCache_8php_source.html#l00297
  3. man diff
  4. man patch
--- includes/parser/ParserCache.php.orig 2018-06-27 18:53:25.144916108 -0400
+++ includes/parser/ParserCache.php 2018-06-27 19:00:22.562689464 -0400
@@ -328,7 +328,8 @@
" and revision id $revId" .
"\n";
- $parserOutput->mText .= "\n<!-- $msg -->\n";
+ // stop "Saved in parser cache" message from appearing in page source
+ //$parserOutput->mText .= "\n<!-- $msg -->\n";
wfDebug( $msg );
// Save the parser output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment