it unset should treat it as being MIGRATION_NEW.
* $wgAuth – This old setting, deprecated in 1.27, has been removed as part of
the removal of AuthPlugin.
+* $wgSitesCacheFile has been removed. It was introduced in 1.25 to allow sites
+ to configure a file in which to cache the SiteStore database table.
+ This was never used. SiteStore already caches its information by default
+ using BagOStuff (e.g. Memcached or APC).
=== New features in 1.33 ===
* (T96041) __EXPECTUNUSEDCATEGORY__ on a category page causes the category
check block behaviour.
* The api-feature-usage log channel now has log context. The text message is
deprecated and will be removed in the future.
+* The FileBasedSiteLookup class has been deprecated. For a cacheable SiteLookup
+ implementation, use CachingSiteStore instead.
=== Other changes in 1.33 ===
* (T201747) Html::openElement() warns if given an element name with a space
'RebuildLocalisationCache' => __DIR__ . '/maintenance/rebuildLocalisationCache.php',
'RebuildMessages' => __DIR__ . '/maintenance/rebuildmessages.php',
'RebuildRecentchanges' => __DIR__ . '/maintenance/rebuildrecentchanges.php',
- 'RebuildSitesCache' => __DIR__ . '/maintenance/rebuildSitesCache.php',
'RebuildTextIndex' => __DIR__ . '/maintenance/rebuildtextindex.php',
'RecentChange' => __DIR__ . '/includes/changes/RecentChange.php',
'RecentChangesUpdateJob' => __DIR__ . '/includes/jobqueue/jobs/RecentChangesUpdateJob.php',
'SiteStatsInit' => __DIR__ . '/includes/SiteStatsInit.php',
'SiteStatsUpdate' => __DIR__ . '/includes/deferred/SiteStatsUpdate.php',
'SiteStore' => __DIR__ . '/includes/site/SiteStore.php',
- 'SitesCacheFileBuilder' => __DIR__ . '/includes/site/SitesCacheFileBuilder.php',
'Skin' => __DIR__ . '/includes/skins/Skin.php',
'SkinApi' => __DIR__ . '/includes/skins/SkinApi.php',
'SkinApiTemplate' => __DIR__ . '/includes/skins/SkinApiTemplate.php',
+++ /dev/null
-MediaWiki's SiteStore can be cached and stored in a flat file,
-in a json format. If the SiteStore is frequently accessed, the
-file cache may provide a performance benefit over a database
-store, even with memcached in front of it.
-
-Configuration:
-
-File-based caching can be enabled by setting $wgSitesCacheFile
-to the file path of the cache file.
-
-The file can then be generated with the rebuildSitesCache.php
-maintenance script.
-
-Format:
-
-In the sites cache file, sites are listed in a key-value
-map, with the key being the site's global id (e.g. "enwiki")
-and a key-value map as the value. The site list is wrapped
-with in a "sites" key.
-
-Example:
-
-"sites": {
- "aawiktionary": {
- "globalid": "aawiktionary",
- "type": "mediawiki",
- "group": "wiktionary",
- "source": "local",
- "language": "aa",
- "localids": [],
- "config": [],
- "data": {
- "paths": {
- "file_path": "http:\/\/aa.wiktionary.org\/w\/$1",
- "page_path": "http:\/\/aa.wiktionary.org\/wiki\/$1"
- }
- },
- "forward": false,
- "internalid": 2666,
- "identifiers": []
- }
-}
/** @} */ # end of Interwiki caching settings.
-/**
- * @name SiteStore caching settings.
- * @{
- */
-
-/**
- * Specify the file location for the Sites json cache file.
- */
-$wgSitesCacheFile = false;
-
-/** @} */ # end of SiteStore caching settings.
-
/**
* If local interwikis are set up which allow redirects,
* set this regexp to restrict URLs which will be displayed
},
'SiteLookup' => function ( MediaWikiServices $services ) : SiteLookup {
- $cacheFile = $services->getMainConfig()->get( 'SitesCacheFile' );
-
- if ( $cacheFile !== false ) {
- return new FileBasedSiteLookup( $cacheFile );
- } else {
- // Use the default SiteStore as the SiteLookup implementation for now
- return $services->getSiteStore();
- }
+ // Use SiteStore as the SiteLookup as well. This was originally separated
+ // to allow for a cacheable read-only interface (using FileBasedSiteLookup),
+ // but this was never used. SiteStore has caching (see below).
+ return $services->getSiteStore();
},
'SiteStore' => function ( MediaWikiServices $services ) : SiteStore {
*/
/**
- * Provides a file-based cache of a SiteStore. The sites are stored in
- * a json file. (see docs/sitescache.txt regarding format)
- *
- * The cache can be built with the rebuildSitesCache.php maintenance script,
- * and a MediaWiki instance can be setup to use this by setting the
- * 'wgSitesCacheFile' configuration to the cache file location.
+ * Provides a file-based cache of a SiteStore, using a json file.
*
* @since 1.25
+ * @deprecated since 1.33 Use CachingSiteStore instead.
*/
class FileBasedSiteLookup implements SiteLookup {
* @param string $cacheFile
*/
public function __construct( $cacheFile ) {
+ wfDeprecated( __CLASS__, '1.33' );
$this->cacheFile = $cacheFile;
}
+++ /dev/null
-<?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
- *
- * @since 1.25
- *
- * @file
- *
- * @license GPL-2.0-or-later
- */
-class SitesCacheFileBuilder {
-
- /**
- * @var SiteLookup
- */
- private $siteLookup;
-
- /**
- * @var string
- */
- private $cacheFile;
-
- /**
- * @param SiteLookup $siteLookup
- * @param string $cacheFile
- */
- public function __construct( SiteLookup $siteLookup, $cacheFile ) {
- $this->siteLookup = $siteLookup;
- $this->cacheFile = $cacheFile;
- }
-
- public function build() {
- $this->sites = $this->siteLookup->getSites();
- $this->cacheSites( $this->sites->getArrayCopy() );
- }
-
- /**
- * @param Site[] $sites
- *
- * @throws MWException if in manualRecache mode
- * @return bool
- */
- private function cacheSites( array $sites ) {
- $sitesArray = [];
-
- foreach ( $sites as $site ) {
- $globalId = $site->getGlobalId();
- $sitesArray[$globalId] = $this->getSiteAsArray( $site );
- }
-
- $json = json_encode( [
- 'sites' => $sitesArray
- ] );
-
- $result = file_put_contents( $this->cacheFile, $json );
-
- return $result !== false;
- }
-
- /**
- * @param Site $site
- *
- * @return array
- */
- private function getSiteAsArray( Site $site ) {
- $siteEntry = unserialize( $site->serialize() );
- $siteIdentifiers = $this->buildLocalIdentifiers( $site );
- $identifiersArray = [];
-
- foreach ( $siteIdentifiers as $identifier ) {
- $identifiersArray[] = $identifier;
- }
-
- $siteEntry['identifiers'] = $identifiersArray;
-
- return $siteEntry;
- }
-
- /**
- * @param Site $site
- *
- * @return array Site local identifiers
- */
- private function buildLocalIdentifiers( Site $site ) {
- $localIds = [];
-
- foreach ( $site->getLocalIds() as $idType => $ids ) {
- foreach ( $ids as $id ) {
- $localIds[] = [
- 'type' => $idType,
- 'key' => $id
- ];
- }
- }
-
- return $localIds;
- }
-
-}
+++ /dev/null
-<?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
- * @ingroup Maintenance
- */
-
-require_once __DIR__ . '/Maintenance.php';
-
-/**
- * Maintenance script to dump a SiteStore as a static json file.
- *
- * @ingroup Maintenance
- */
-class RebuildSitesCache extends Maintenance {
-
- public function __construct() {
- parent::__construct();
-
- $this->addDescription( 'Cache sites as json for file-based lookup.' );
- $this->addOption( 'file', 'File to output the json to', false, true );
- }
-
- public function execute() {
- $sitesCacheFileBuilder = new SitesCacheFileBuilder(
- \MediaWiki\MediaWikiServices::getInstance()->getSiteLookup(),
- $this->getCacheFile()
- );
-
- $sitesCacheFileBuilder->build();
- }
-
- /**
- * @return string
- */
- private function getCacheFile() {
- if ( $this->hasOption( 'file' ) ) {
- $jsonFile = $this->getOption( 'file' );
- } else {
- $jsonFile = $this->getConfig()->get( 'SitesCacheFile' );
-
- if ( $jsonFile === false ) {
- $this->fatalError( 'Error: No file set in configuration for SitesCacheFile.' );
- }
- }
-
- return $jsonFile;
- }
-
-}
-
-$maintClass = RebuildSitesCache::class;
-require_once RUN_MAINTENANCE_IF_MAIN;
+++ /dev/null
-<?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
- * @since 1.25
- *
- * @ingroup Site
- * @ingroup Test
- *
- * @covers FileBasedSiteLookup
- * @group Site
- *
- * @author Katie Filbert < aude.wiki@gmail.com >
- */
-class FileBasedSiteLookupTest extends PHPUnit\Framework\TestCase {
-
- use MediaWikiCoversValidator;
-
- protected function setUp() {
- $this->cacheFile = $this->getCacheFile();
- }
-
- protected function tearDown() {
- unlink( $this->cacheFile );
- }
-
- public function testGetSites() {
- $sites = $this->getSites();
- $cacheBuilder = $this->newSitesCacheFileBuilder( $sites );
- $cacheBuilder->build();
-
- $cache = new FileBasedSiteLookup( $this->cacheFile );
- $this->assertEquals( $sites, $cache->getSites() );
- }
-
- public function testGetSite() {
- $sites = $this->getSites();
- $cacheBuilder = $this->newSitesCacheFileBuilder( $sites );
- $cacheBuilder->build();
-
- $cache = new FileBasedSiteLookup( $this->cacheFile );
-
- $this->assertEquals( $sites->getSite( 'enwiktionary' ), $cache->getSite( 'enwiktionary' ) );
- }
-
- private function newSitesCacheFileBuilder( SiteList $sites ) {
- return new SitesCacheFileBuilder(
- $this->getSiteLookup( $sites ),
- $this->cacheFile
- );
- }
-
- private function getSiteLookup( SiteList $sites ) {
- $siteLookup = $this->getMockBuilder( SiteLookup::class )
- ->disableOriginalConstructor()
- ->getMock();
-
- $siteLookup->expects( $this->any() )
- ->method( 'getSites' )
- ->will( $this->returnValue( $sites ) );
-
- return $siteLookup;
- }
-
- private function getSites() {
- $sites = [];
-
- $site = new Site();
- $site->setGlobalId( 'foobar' );
- $sites[] = $site;
-
- $site = new MediaWikiSite();
- $site->setGlobalId( 'enwiktionary' );
- $site->setGroup( 'wiktionary' );
- $site->setLanguageCode( 'en' );
- $site->addNavigationId( 'enwiktionary' );
- $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
- $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
- $sites[] = $site;
-
- return new SiteList( $sites );
- }
-
- private function getCacheFile() {
- return tempnam( sys_get_temp_dir(), 'mw-test-sitelist' );
- }
-
-}
+++ /dev/null
-<?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
- * @since 1.25
- *
- * @ingroup Site
- * @ingroup Test
- *
- * @covers SitesCacheFileBuilder
- * @group Site
- *
- * @author Katie Filbert < aude.wiki@gmail.com >
- */
-class SitesCacheFileBuilderTest extends PHPUnit\Framework\TestCase {
-
- use MediaWikiCoversValidator;
-
- protected function setUp() {
- $this->cacheFile = $this->getCacheFile();
- }
-
- protected function tearDown() {
- unlink( $this->cacheFile );
- }
-
- public function testBuild() {
- $cacheBuilder = $this->newSitesCacheFileBuilder( $this->getSites() );
- $cacheBuilder->build();
-
- $contents = file_get_contents( $this->cacheFile );
- $this->assertEquals( json_encode( $this->getExpectedData() ), $contents );
- }
-
- private function getExpectedData() {
- return [
- 'sites' => [
- 'foobar' => [
- 'globalid' => 'foobar',
- 'type' => 'unknown',
- 'group' => 'none',
- 'source' => 'local',
- 'language' => null,
- 'localids' => [],
- 'config' => [],
- 'data' => [],
- 'forward' => false,
- 'internalid' => null,
- 'identifiers' => []
- ],
- 'enwiktionary' => [
- 'globalid' => 'enwiktionary',
- 'type' => 'mediawiki',
- 'group' => 'wiktionary',
- 'source' => 'local',
- 'language' => 'en',
- 'localids' => [
- 'equivalent' => [ 'enwiktionary' ]
- ],
- 'config' => [],
- 'data' => [
- 'paths' => [
- 'page_path' => 'https://en.wiktionary.org/wiki/$1',
- 'file_path' => 'https://en.wiktionary.org/w/$1'
- ]
- ],
- 'forward' => false,
- 'internalid' => null,
- 'identifiers' => [
- [
- 'type' => 'equivalent',
- 'key' => 'enwiktionary'
- ]
- ]
- ]
- ]
- ];
- }
-
- private function newSitesCacheFileBuilder( SiteList $sites ) {
- return new SitesCacheFileBuilder(
- $this->getSiteLookup( $sites ),
- $this->cacheFile
- );
- }
-
- private function getSiteLookup( SiteList $sites ) {
- $siteLookup = $this->getMockBuilder( SiteLookup::class )
- ->disableOriginalConstructor()
- ->getMock();
-
- $siteLookup->expects( $this->any() )
- ->method( 'getSites' )
- ->will( $this->returnValue( $sites ) );
-
- return $siteLookup;
- }
-
- private function getSites() {
- $sites = [];
-
- $site = new Site();
- $site->setGlobalId( 'foobar' );
- $sites[] = $site;
-
- $site = new MediaWikiSite();
- $site->setGlobalId( 'enwiktionary' );
- $site->setGroup( 'wiktionary' );
- $site->setLanguageCode( 'en' );
- $site->addNavigationId( 'enwiktionary' );
- $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
- $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
- $sites[] = $site;
-
- return new SiteList( $sites );
- }
-
- private function getCacheFile() {
- return tempnam( sys_get_temp_dir(), 'mw-test-sitelist' );
- }
-
-}