Module Configuration
Module Name:skins.citizen.search
Dependencies:
mediawiki.storagemediawiki.template.mustachemediawiki.usermediawiki.util
resources/skins.citizen.search/main.js
Core Components
Main Initialization
The search module auto-initializes on page load:Typeahead System
The typeahead component manages the search interface, keyboard navigation, and result display.typeahead.init(formEl, inputEl)
Initializes the typeahead interface. Parameters:formEl(HTMLFormElement) - The search form elementinputEl(HTMLInputElement) - The search input element
Typeahead Properties
formelement(HTMLFormElement | undefined) - The form elementisLoading(boolean) - Loading stateinit(formEl)- Initialize the formsetLoadingState(state)- Set loading state
element(HTMLInputElement | undefined) - The input elementdisplayElement(HTMLElement | undefined) - Overlay element for displayisComposing(boolean) - IME composition stateinit(inputEl)- Initialize the inputonFocus()- Focus event handleronInput()- Input event handleronKeydown(event)- Keydown event handler
elements(NodeList | undefined) - Suggestion item elementsindex(number) - Currently highlighted indexmax(number) - Maximum number of itemssetMax(x)- Set maximum itemsincrement(i)- Move selection by i positionssetIndex(i)- Set selection indexclearIndex()- Clear selectiontoggle(item)- Toggle active state on itembindMouseHoverEvent()- Bind hover eventsset()- Update items list
Keyboard Navigation
The typeahead supports:- ArrowUp/ArrowDown - Navigate through suggestions
- Enter - Select highlighted suggestion
- Escape - Close suggestions (via blur)
Search Client
Manages different search API backends.searchClient(config)
Factory function that creates a search client manager. Returns: Search client object with:active(Object | null) - Currently active search clientgetData(key, value)- Find client data by key/valuesetActive(id)- Set active search client by ID
mwActionApi- MediaWiki Action APImwRestApi- MediaWiki REST APIsmwAskApi- Semantic MediaWiki Ask API
Client Configuration
Search clients are configured insearchClients/searchClients.json and loaded dynamically.
Search History
Manages local storage of search queries.searchHistory(config)
Factory function for search history management. Returns: History manager with:data(Array) - History itemslimit(number) - Maximum items (from config.wgCitizenMaxSearchResults)get()- Get history arrayset(arr)- Set history arrayadd(query)- Add query to historyclear()- Clear all historyinit()- Load from storage
skin-citizen-search-history
Example:
Search Results
Handles fetching and rendering search results.searchResults()
Factory function that returns result handler. Methods: getRedirectLabel(title, matchedTitle, queryValue) Generates redirect label HTML for suggestions. Parameters:title(string) - Target page titlematchedTitle(string) - Matched redirect titlequeryValue(string) - User’s query
title(string) - Page titlematch(string) - Text to highlight
queryValue(string) - User’s querytemplates(Object) - Compiled Mustache templates
results(Array) - Search result objectsqueryValue(string) - User’s querytemplates(Object) - Compiled Mustache templates
queryValue(string) - Search queryactiveSearchClient(Object) - Active search client
abort function and fetch promise
render(searchQuery, templates)
Renders search action elements.
clear()
Clears results from DOM.
init()
Initializes the results handler.
Example:
Search Query
Manages the current search query state.searchQuery()
Factory function for query state management. Properties:value(string) - Current queryvalueHtml(string) - HTML-encoded queryisValid(boolean) - Whether query is valid (non-empty)
setValue(value)- Set query valueremove(pattern)- Remove pattern from queryreplace(pattern, replacement)- Replace pattern in query
Configuration Variables
Fromskin.json configuration:
- wgCitizenSearchGateway (string) - Default search client (
mwActionApi|mwRestApi|custom) - wgCitizenSearchDescriptionSource (string) - Source for descriptions (default:
textextracts) - wgCitizenMaxSearchResults (number) - Maximum results to show (default: 10)
Templates
The module uses Mustache templates for rendering:TypeaheadElement.mustache- Main typeahead containerTypeaheadPlaceholder.mustache- Loading/empty state placeholderTypeaheadList.mustache- Results list wrapperTypeaheadListItem.mustache- Individual result item
Special Features
Command Mode
Search supports special syntax for enhanced functionality: Template Search:Composition Mode (CJK)
The typeahead respects IME composition state and only updates after composition is complete:Events
The module responds to standard input events:focus- Expands search card and refreshes typeaheadinput- Updates query and fetches suggestionsblur- Collapses search cardkeydown- Handles keyboard navigationcompositionstart/compositionend- Handles IME input
Styling
CSS classes for customization:.citizen-typeahead-input-group- Input wrapper.citizen-typeahead-input- Search input.citizen-typeahead-input-overlay- Display overlay.citizen-typeahead-group- Result group container.citizen-typeahead-list-item- Individual result.citizen-typeahead__highlight- Highlighted match text.citizen-loading- Loading state indicator
Related Modules
- Command Palette - Advanced search interface
- Scripts - Core skin scripts