15 private static $cache = [];
17 private static $priorityCache;
24 $missing = array_keys( array_diff_key( array_flip( $groups ), self::$cache ) );
29 $fname = __METHOD__ .
" (for $caller)";
31 self::$cache += array_fill_keys( $missing,
null );
33 $dbr = TranslateUtils::getSafeReadDB();
34 $conds = count( $missing ) <= 500 ? [
'tmd_group' => array_map(
'strval', $missing ) ] : [];
37 [
'tmd_group',
'tmd_key',
'tmd_value' ],
41 foreach ( $res as $row ) {
42 self::$cache[$row->tmd_group][$row->tmd_key] = $row->tmd_value;
52 public static function get( $group, $key ) {
53 self::preloadGroups( [ $group ], __METHOD__ );
55 return self::$cache[$group][$key] ??
false;
67 string $group,
string $key,
string $defaultValue
69 $value = self::
get( $group, $key );
70 return $value ===
false ? $defaultValue : $value;
80 public static function set( $group, $key, $value ) {
81 $dbw = wfGetDB( DB_PRIMARY );
82 $data = [
'tmd_group' => $group,
'tmd_key' => $key,
'tmd_value' => $value ];
83 if ( $value ===
false ) {
84 unset( $data[
'tmd_value'] );
85 $dbw->delete(
'translate_metadata', $data, __METHOD__ );
86 unset( self::$cache[$group][$key] );
90 [ [
'tmd_group',
'tmd_key' ] ],
94 self::$cache[$group][$key] = $value;
97 self::$priorityCache =
null;
107 $groups = self::get( $groupId,
'subgroups' );
108 if ( is_string( $groups ) ) {
109 if ( strpos( $groups,
'|' ) !==
false ) {
110 $groups = explode(
'|', $groups );
112 $groups = array_map(
'trim', explode(
',', $groups ) );
115 foreach ( $groups as $index => $id ) {
116 if ( trim( $id ) ===
'' ) {
117 unset( $groups[$index] );
134 $subgroups = implode(
'|', $subgroupIds );
135 self::set( $groupId,
'subgroups', $subgroups );
144 $dbw = wfGetDB( DB_PRIMARY );
145 $conds = [
'tmd_group' => $groupId ];
146 $dbw->delete(
'translate_metadata', $conds, __METHOD__ );
147 self::$cache[$groupId] =
null;
148 unset( self::$priorityCache[ $groupId ] );
151 public static function isExcluded(
string $groupId,
string $code ): bool {
152 if ( self::$priorityCache === null ) {
153 $db = TranslateUtils::getSafeReadDB();
156 'a' =>
'translate_metadata',
157 'b' =>
'translate_metadata'
160 'group' =>
'b.tmd_group',
161 'langs' =>
'b.tmd_value',
170 'a.tmd_group = b.tmd_group',
171 'a.tmd_key' =>
'priorityforce',
172 'a.tmd_value' =>
'on',
173 'b.tmd_key' =>
'prioritylangs',
179 self::$priorityCache = [];
180 foreach ( $res as $row ) {
181 self::$priorityCache[$row->group] =
182 array_flip( explode(
',', $row->langs ) );
187 $hasLimitedLanguages = isset( self::$priorityCache[$groupId] );
188 $isLanguageIncluded = isset( self::$priorityCache[$groupId][$code] );
190 return $isDiscouraged || ( $hasLimitedLanguages && !$isLanguageIncluded );
202 'translate_metadata',
203 [
'tmd_group',
'tmd_key',
'tmd_value' ],
205 'tmd_group' => $groupIds,
212 foreach ( $res as $row ) {
213 $ret[$row->tmd_group][$row->tmd_key] = $row->tmd_value;
228 array $metadataKeysToMove
230 self::preloadGroups( [ $oldGroupId, $newGroupId ], __METHOD__ );
231 foreach ( $metadataKeysToMove as $type ) {
232 $value = self::get( $oldGroupId, $type );
233 if ( $value !==
false ) {
234 self::set( $oldGroupId, $type,
false );
235 self::set( $newGroupId, $type, $value );
245 public static function clearMetadata(
string $groupId, array $metadataKeys ): void {
247 foreach ( $metadataKeys as $type ) {
248 self::set( $groupId, $type,
false );
static getPriority( $group)
We want to de-emphasize time sensitive groups like news for 2009.
Essentially random collection of helper functions, similar to GlobalFunctions.php.