Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6152796
urlGenerator.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
urlGenerator.js
View Options
/**
* @typedef {Record<string,string>} UrlParams
* @param {string} title
* @param {string} fulltext
*/
/**
* @callback generateUrl
* @param {RestResult|SearchResult|string} searchResult
* @param {UrlParams} [params]
* @param {string} [articlePath]
* @return {string}
*/
/**
* @typedef {Object} UrlGenerator
* @property {generateUrl} generateUrl
*/
/**
* Generates URLs for suggestions like those in MediaWiki's mediawiki.searchSuggest implementation.
*
* @param {string} articlePath
* @return {UrlGenerator}
*/
function
urlGenerator
(
articlePath
)
{
return
{
/**
* @param {RestResult|SearchResult|string} suggestion
* @param {UrlParams} params
* @return {string}
*/
generateUrl
(
suggestion
,
params
=
{
title
:
'Special:Search'
}
)
{
if
(
typeof
suggestion
!==
'string'
)
{
suggestion
=
suggestion
.
title
+
(
suggestion
.
anchor
?
`#
${
suggestion
.
anchor
}
`
:
''
);
}
else
{
// Add `fulltext` query param to search within pages and for navigation
// to the search results page (prevents being redirected to a certain
// article).
params
=
Object
.
assign
(
{},
params
,
{
fulltext
:
'1'
}
);
}
const
searchParams
=
new
URLSearchParams
(
Object
.
assign
(
{},
params
,
{
search
:
suggestion
}
)
);
return
`
${
articlePath
}
?
${
searchParams
.
toString
()
}
`
;
}
};
}
/** @module urlGenerator */
module
.
exports
=
urlGenerator
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Oct 8 2026, 03:47 (6 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
58/c9/2f6fc095a0b1676c89e54a76f0a6
Default Alt Text
urlGenerator.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment