setFunctionHook( 'babel', [ 'Babel', 'Render' ] ); } /** * @param DatabaseUpdater $updater */ public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) { $dir = dirname( __DIR__ ) . '/'; $updater->addExtensionTable( 'babel', $dir . 'babel.sql' ); if ( $updater->getDB()->getType() === 'mysql' ) { $updater->modifyExtensionField( 'babel', 'babel_lang', $dir . 'sql/babel-babel_lang-length-type.sql' ); $updater->modifyExtensionField( 'babel', 'babel_level', $dir . 'sql/babel-babel_level-type.sql' ); } elseif ( $updater->getDB()->getType() === 'sqlite' ) { $updater->modifyExtensionField( 'babel', 'babel_lang', $dir . 'sql/babel-babel_lang-length.sqlite.sql' ); } } /** * @param LinksUpdate $linksUpdate */ public static function onLinksUpdate( LinksUpdate $linksUpdate ) { global $wgBabelCentralDb; $title = $linksUpdate->getTitle(); // Has to be a root userpage if ( !$title->inNamespace( NS_USER ) || !$title->getRootTitle()->equals( $title ) ) { return; } // And the user has to exist $user = User::newFromName( $title->getText() ); if ( !$user || !$user->getId() ) { return; } $babelDB = new MediaWiki\Babel\Database(); $data = $linksUpdate->getParserOutput()->getExtensionData( 'babel' ) ?: []; $changed = $babelDB->setForUser( $user->getId(), $data ); if ( $changed ) { $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $cache->touchCheckKey( $cache->makeKey( 'babel-local-languages', $user->getId() ) ); if ( $wgBabelCentralDb === wfWikiID() ) { // If this is the central wiki, invalidate all of the local caches $centralId = CentralIdLookup::factory()->centralIdFromLocalUser( $user ); if ( $centralId ) { $cache->touchCheckKey( $cache->makeGlobalKey( 'babel-central-languages', $centralId ) ); } } } } }