MediaWiki 1.26自定义皮肤搜索表单自动补全功能失效求助
Hey there, let's troubleshoot why the search autocomplete isn't working in your custom MediaWiki 1.26 skin. I've tackled similar issues before, so here are the key checks and fixes to try out:
Make sure required JavaScript modules are loaded
MediaWiki's search autocomplete relies on themediawiki.searchSuggestmodule, which bundles jQuery UI Autocomplete and the necessary wiki-specific logic. In your skin's PHP code (usually in theinitPagemethod of your skin class), add this line to load the module:$this->getOutput()->addModules( 'mediawiki.searchSuggest' );Don't skip this—without the right JS, autocomplete can't function at all.
Verify the search input's HTML attributes
When usingmakeSearchInput, double-check the generated HTML (via your browser's "View Page Source") to ensure the input has the correct identifiers and flags. It should look something like this:<input type="search" name="search" id="searchInput" class="mw-searchInput" data-autocomplete="true">If your custom template is overriding or removing attributes like
id="searchInput"ordata-autocomplete="true", the autocomplete script won't be able to find and bind to the input.Check if the OpenSearch API is working
Autocomplete pulls suggestions via MediaWiki's API endpoint. Test this directly by visitingyour-wiki-domain/api.php?action=opensearch&search=testin your browser—you should get a JSON response with search suggestions. If this fails:- Confirm
$wgEnableOpenSearch = true;is set in yourLocalSettings.php(it's enabled by default in 1.26, but worth checking). - Make sure your wiki's API isn't restricted by permissions or firewall rules.
- Confirm
Rule out JavaScript conflicts
Custom skins often bring in external JS or jQuery versions that clash with MediaWiki's built-in scripts. Open your browser's developer console (F12 > Console tab) and look for errors like:jQuery is not defined$(...).autocomplete is not a function
If you see these, ensure MediaWiki's jQuery loads before your custom JS, and avoid overwriting the globaljQueryor$variables.
Validate the search form structure
The search input needs to be wrapped in a properly configured form pointing toSpecial:Search. UsemakeSearchInputalongsidemakeSearchButtonto ensure the structure is correct:<form action="<?php echo $this->getTitle( 'Special:Search' )->getLocalURL(); ?>" method="get" class="mw-search-form"> <?php echo $this->makeSearchInput( array( 'id' => 'searchInput' ) ); ?> <?php echo $this->makeSearchButton( 'go' ); ?> </form>The
mw-search-formclass helps MediaWiki's scripts target the form correctly—don't omit it unless you're explicitly handling the binding yourself.Clear MediaWiki's cache
MediaWiki's caching can sometimes prevent new resources from loading. Purge the cache by:- Adding
?action=purgeto the end of your wiki's URL and reloading. - Deleting files in your wiki's
cachedirectory (if you have server access).
- Adding
If you've tried all these steps and still have issues, sharing snippets of your skin's PHP code and the generated HTML for the search form would help narrow down the problem further.
内容的提问来源于stack exchange,提问作者Jose

