Topic on Project:Support desk

How to use IsFileCacheable hook

3
T0lk (talkcontribs)

Extension:AccessControl (https://github.com/wikimedia/mediawiki-extensions-AccessControl/tree/REL1_34) should probably not let rebuildFileCache.php cache pages that are supposed to be access restricted. I see Manual:Hooks/IsFileCacheable can be used.

Unfortunatey there are no examples of this hook Category:IsFileCacheable extensions, is this correct in AccessControl.hooks.php:

<?php
use MediaWiki\MediaWikiServices;
class AccessControlHooks {
        public static function isFileCacheable (&$article) {
        $matches = [];

        $text = $article->getParserOutput(
            // 0 gets the current ID
            0, // $article->mOldId,
            // Don't have a user (and hopefully shouldn't need one as just grabbing tags)
            null
        )->getRawText();

        $parser = MediaWikiServices::getInstance()->getParser();
        $parser->extractTagsAndParams(['accesscontrol'], $text, $matches);

        return !count($matches);
        }
        ...
}
MarkAHershberger (talkcontribs)
Bawolff (talkcontribs)

well at the very least it would be better to call $parser->getOutput()->setExtensionData() in the parser tag handler, and then check ->getExtensionData() inside this hook