Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4144559
ContextUtils.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ContextUtils.js
View Options
/**
* @type {StreamProducerContextAttribute[]}
* @see https://wikitech.wikimedia.org/wiki/Metrics_Platform/Contextual_attributes
*/
const
VALID_ATTRIBUTE_NAMES
=
[
'agent_client_platform'
,
'agent_client_platform_family'
,
'page_id'
,
'page_title'
,
'page_namespace'
,
'page_namespace_name'
,
'page_revision_id'
,
'page_wikidata_id'
,
'page_wikidata_qid'
,
'page_content_language'
,
'page_is_redirect'
,
'page_user_groups_allowed_to_move'
,
'page_user_groups_allowed_to_edit'
,
'mediawiki_skin'
,
'mediawiki_version'
,
'mediawiki_is_production'
,
'mediawiki_is_debug_mode'
,
'mediawiki_database'
,
'mediawiki_site_content_language'
,
'mediawiki_site_content_language_variant'
,
'performer_is_logged_in'
,
'performer_id'
,
'performer_name'
,
'performer_session_id'
,
'performer_active_browsing_session_token'
,
'performer_pageview_id'
,
'performer_groups'
,
'performer_is_bot'
,
'performer_is_temp'
,
'performer_language'
,
'performer_language_variant'
,
'performer_can_probably_edit_page'
,
'performer_edit_count'
,
'performer_edit_count_bucket'
,
'performer_registration_dt'
];
/**
* @param {ContextAttributes} from
* @param {StreamProducerContextAttribute} name
* @return {*}
*/
function
getAttributeByName
(
from
,
name
)
{
const
index
=
name
.
indexOf
(
'_'
);
const
primaryKey
=
name
.
slice
(
0
,
index
);
// @ts-ignore TS7053
if
(
!
from
[
primaryKey
]
)
{
return
null
;
}
const
secondaryKey
=
name
.
slice
(
index
+
1
);
// @ts-ignore TS7053
const
value
=
from
[
primaryKey
][
secondaryKey
];
return
(
value
===
undefined
||
value
===
null
)
?
null
:
value
;
}
/**
* @param {ContextAttributes} from
* @param {ContextAttributes} to
* @param {StreamProducerContextAttribute} name
*/
function
copyAttributeByName
(
from
,
to
,
name
)
{
const
index
=
name
.
indexOf
(
'_'
);
const
primaryKey
=
name
.
slice
(
0
,
index
);
const
secondaryKey
=
name
.
slice
(
index
+
1
);
// @ts-ignore TS7053
const
value
=
from
[
primaryKey
]
?
from
[
primaryKey
][
secondaryKey
]
:
null
;
if
(
value
===
undefined
||
value
===
null
)
{
return
;
}
// @ts-ignore TS7053
to
[
primaryKey
]
=
to
[
primaryKey
]
||
{};
// @ts-ignore TS7053
to
[
primaryKey
][
secondaryKey
]
=
value
;
}
/**
* @param {ContextAttributes} from
* @param {ContextAttributes} to
*/
function
copyAttributes
(
from
,
to
)
{
VALID_ATTRIBUTE_NAMES
.
forEach
(
(
name
)
=>
copyAttributeByName
(
from
,
to
,
name
)
);
}
module
.
exports
=
{
getAttributeByName
:
getAttributeByName
,
copyAttributeByName
:
copyAttributeByName
,
copyAttributes
:
copyAttributes
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Aug 19 2026, 17:17 (5 w, 1 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
94/76/9583db9d2a04de54ff98e4ca4ddd
Default Alt Text
ContextUtils.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment