Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4114188
searchAction.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
searchAction.js
View Options
const
config
=
require
(
'./config.json'
);
const
urlGenerator
=
require
(
'./urlGenerator.js'
);
const
fulltextParam
=
{
fulltext
:
'1'
};
const
mediasearchParam
=
{
type
:
'image'
};
const
editpageParam
=
{
action
:
'edit'
};
function
searchAction
()
{
return
{
urlGeneratorInstance
:
urlGenerator
(
config
),
// Assume user can't edit by default
userCanEdit
:
false
,
userRights
:
undefined
,
render
:
function
(
searchQuery
,
templates
)
{
const
items
=
[];
// TODO: Save this in a separate JSON file
// Fulltext search
fulltextParam
.
search
=
searchQuery
.
value
;
items
.
push
(
{
id
:
'fulltext'
,
href
:
this
.
urlGeneratorInstance
.
generateUrl
(
'Special:Search'
,
fulltextParam
),
icon
:
'articleSearch'
,
text
:
mw
.
message
(
config
.
isAdvancedSearchExtensionEnabled
?
'citizen-search-advancedsearch'
:
'citizen-search-fulltext'
)
}
);
// MediaSearch
if
(
config
.
isMediaSearchExtensionEnabled
)
{
mediasearchParam
.
search
=
searchQuery
.
value
;
items
.
push
(
{
id
:
'mediasearch'
,
href
:
this
.
urlGeneratorInstance
.
generateUrl
(
'Special:MediaSearch'
,
mediasearchParam
),
icon
:
'imageGallery'
,
text
:
mw
.
message
(
'citizen-search-mediasearch'
)
}
);
}
/*
For some reason title.exists() always returns null
const title = mw.Title.newFromUserInput( searchQuery.value );
console.log( title.exists() );
*/
if
(
this
.
userCanEdit
)
{
// Edit/create page
// TODO: Check whether the page exists
items
.
push
(
{
id
:
'editpage'
,
href
:
this
.
urlGeneratorInstance
.
generateUrl
(
searchQuery
.
value
,
editpageParam
),
icon
:
'edit'
,
text
:
mw
.
message
(
'citizen-search-editpage'
)
}
);
}
const
data
=
{
type
:
'action'
,
'array-list-items'
:
items
};
const
partials
=
{
TypeaheadListItem
:
templates
.
TypeaheadListItem
};
document
.
getElementById
(
'citizen-typeahead-list-action'
).
outerHTML
=
templates
.
TypeaheadList
.
render
(
data
,
partials
).
html
();
document
.
getElementById
(
'citizen-typeahead-group-action'
).
hidden
=
false
;
},
clear
:
function
()
{
document
.
getElementById
(
'citizen-typeahead-list-action'
).
innerHTML
=
''
;
document
.
getElementById
(
'citizen-typeahead-group-action'
).
hidden
=
true
;
},
init
:
function
()
{
mw
.
user
.
getRights
().
done
(
(
rights
)
=>
{
this
.
userCanEdit
=
rights
.
includes
(
'createpage'
,
'edit'
);
}
);
}
};
}
/** @module searchAction */
module
.
exports
=
searchAction
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Aug 18, 23:54 (17 h, 57 s ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
96/3d/bd1785321f15952522e043b5aea9
Default Alt Text
searchAction.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment