Use the search title if configured

Allow commons to use Special:MediaSearch

Depends-On: 	I37b9d3a2b263f496a283f4bfdc769b7dc880ab06
Bug: T287540
Change-Id: I2a2463d704ef5b2264574cdf186836ba00a639f5
This commit is contained in:
jdlrobson 2021-07-28 09:15:57 -07:00 committed by Jdlrobson
parent bf68ce9555
commit aebb3fb522
2 changed files with 13 additions and 2 deletions

View file

@ -10,6 +10,7 @@
:title="searchTitle" :title="searchTitle"
:placeholder="searchPlaceholder" :placeholder="searchPlaceholder"
:aria-label="searchPlaceholder" :aria-label="searchPlaceholder"
:search-page-title="searchPageTitle"
:initial-input-value="searchQuery" :initial-input-value="searchQuery"
:button-label="$i18n( 'searchbutton' ).text()" :button-label="$i18n( 'searchbutton' ).text()"
:form-action="action" :form-action="action"
@ -74,6 +75,10 @@ module.exports = {
} }
}, },
props: { props: {
searchPageTitle: {
type: String,
default: 'Special:Search'
},
autofocusInput: { autofocusInput: {
type: Boolean, type: Boolean,
default: false default: false

View file

@ -7,9 +7,11 @@ var
/** /**
* @param {HTMLElement} searchForm * @param {HTMLElement} searchForm
* @param {HTMLInputElement} search * @param {HTMLInputElement} search
* @param {string|null} searchPageTitle title of page used for searching e.g. Special:Search
* If null then this will default to Special:Search.
* @return {void} * @return {void}
*/ */
function initApp( searchForm, search ) { function initApp( searchForm, search, searchPageTitle ) {
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue( { new Vue( {
el: searchForm, el: searchForm,
@ -24,6 +26,7 @@ function initApp( searchForm, search ) {
autofocusInput: search === document.activeElement, autofocusInput: search === document.activeElement,
action: searchForm.getAttribute( 'action' ), action: searchForm.getAttribute( 'action' ),
searchAccessKey: search.getAttribute( 'accessKey' ), searchAccessKey: search.getAttribute( 'accessKey' ),
searchPageTitle: searchPageTitle,
searchTitle: search.getAttribute( 'title' ), searchTitle: search.getAttribute( 'title' ),
searchPlaceholder: search.getAttribute( 'placeholder' ), searchPlaceholder: search.getAttribute( 'placeholder' ),
searchQuery: search.value searchQuery: search.value
@ -42,9 +45,12 @@ function initApp( searchForm, search ) {
function main( document ) { function main( document ) {
var var
searchForm = /** @type {HTMLElement} */ ( document.querySelector( '#searchform' ) ), searchForm = /** @type {HTMLElement} */ ( document.querySelector( '#searchform' ) ),
titleInput = /** @type {HTMLInputElement|null} */ (
searchForm.querySelector( 'input[name=title]' )
),
search = /** @type {HTMLInputElement|null} */ ( document.getElementById( 'searchInput' ) ); search = /** @type {HTMLInputElement|null} */ ( document.getElementById( 'searchInput' ) );
if ( search && searchForm ) { if ( search && searchForm ) {
initApp( searchForm, search ); initApp( searchForm, search, titleInput && titleInput.value );
} }
} }
main( document ); main( document );