Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4112456
extendSearchParams.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
extendSearchParams.js
View Options
const
util
=
require
(
'./util'
),
actionParams
=
require
(
'./actionParams.js'
);
/**
* Extends the API query parameters to include those parameters required to also fetch Wikibase
* descriptions and appropriately sized thumbnail images as well as those required to make a query.
*
* This function wraps `util.extend` with some Wikibase-specific configuration
* variable management
* but, like `util.extend`, is variadic and so can be used as a replacement for it in search
* gateways, e.g.
*
* ```
* var params = extendSearchParams(
* 'search',
* baseParams,
* specializedParams,
* moreSpecializedParams
* );
* ```
*
* @param {string} feature The name of the feature
* @throws {Error} If `feature` isn't one that shows Wikidata descriptions. See the
* `wgMFDisplayWikibaseDescriptions` configuration variable for detail
* @return {Object}
*/
module
.
exports
=
function
extendSearchParams
(
feature
)
{
const
displayWikibaseDescriptions
=
mw
.
config
.
get
(
'wgMFDisplayWikibaseDescriptions'
)
||
{
// These must be defined, as these are all the features that this can be used on.
// If not defined, all these features will see their API calls broken
search
:
true
,
watchlist
:
true
,
tagline
:
false
},
scriptPath
=
mw
.
config
.
get
(
'wgMFScriptPath'
);
if
(
!
Object
.
prototype
.
hasOwnProperty
.
call
(
displayWikibaseDescriptions
,
feature
)
)
{
throw
new
Error
(
'"'
+
feature
+
'" isn\'t a feature that shows Wikibase descriptions.'
);
}
// Construct the arguments for a call to `util.extend`
// such that if it were hand-written, then it
// would look like the following:
//
// ```
// var result = util.extend( {
// prop: []
// }, params, /* ..., */ mw.config.get( 'wgMFSearchAPIParams' ) );
// ```
const
args
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
args
.
unshift
(
{
prop
:
[]
}
);
args
.
push
(
mw
.
config
.
get
(
'wgMFSearchAPIParams'
)
);
const
result
=
util
.
extend
.
apply
(
{},
args
);
result
.
prop
=
result
.
prop
.
concat
(
mw
.
config
.
get
(
'wgMFQueryPropModules'
)
);
if
(
displayWikibaseDescriptions
[
feature
]
)
{
if
(
result
.
prop
.
indexOf
(
'description'
)
===
-
1
)
{
result
.
prop
.
push
(
'description'
);
}
}
if
(
scriptPath
)
{
// A foreign api is being accessed! Enable anonymous CORS queries!
result
.
origin
=
'*'
;
}
return
actionParams
(
result
);
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Aug 18, 22:51 (13 h, 18 m ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
6d/ce/5f8e3d2b1e2b5206dab852ff744d
Default Alt Text
extendSearchParams.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment