wiki.techinc.nl/includes/language/dependency/MainConfigDependency.php
David Lynch 94755e2643 language: switch LocalisationCache back to MainConfigDependency
This should fix inability to detect changes in messages, e.g. after
enabling a new extension, and thus serving stale cache.

ConfigDependency's isExpired method was always comparing the cached
value to itself, because it stored a PHP-serialized copy of the
ServiceOptions object (via LCStore::encode).

MainConfigDependency's implementation knows which service can be used
to refetch the config to check for changes.

As such, switch to using MainConfigDependency again, and undeprecate it
since it's still in use.

Follow-up to I66207f1a217249c596df4edabbd16e8cc7745fb7.

Bug: T358784
Change-Id: I70613143b3621033c2447574d889a0866e03255e
2024-03-14 00:03:15 +00:00

47 lines
1.4 KiB
PHP

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
use MediaWiki\MediaWikiServices;
/**
* Depend on a MediaWiki configuration variable from the global config.
*
* @ingroup Language
*/
class MainConfigDependency extends CacheDependency {
private $name;
private $value;
public function __construct( $name ) {
$this->name = $name;
$this->value = $this->getConfig()->get( $this->name );
}
private function getConfig() {
return MediaWikiServices::getInstance()->getMainConfig();
}
public function isExpired() {
if ( !$this->getConfig()->has( $this->name ) ) {
return true;
}
return $this->getConfig()->get( $this->name ) != $this->value;
}
}