protected $mFieldTree;
protected $mShowReset = false;
+ protected $mShowSubmit = true;
public $mFieldData;
protected $mSubmitCallback;
*/
function getButtons() {
$html = '';
- $attribs = array();
- if ( isset( $this->mSubmitID ) ) {
- $attribs['id'] = $this->mSubmitID;
- }
+ if ( $this->mShowSubmit ) {
+ $attribs = array();
- if ( isset( $this->mSubmitName ) ) {
- $attribs['name'] = $this->mSubmitName;
- }
+ if ( isset( $this->mSubmitID ) ) {
+ $attribs['id'] = $this->mSubmitID;
+ }
- if ( isset( $this->mSubmitTooltip ) ) {
- $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
- }
+ if ( isset( $this->mSubmitName ) ) {
+ $attribs['name'] = $this->mSubmitName;
+ }
- $attribs['class'] = 'mw-htmlform-submit';
+ if ( isset( $this->mSubmitTooltip ) ) {
+ $attribs += Linker::tooltipAndAccesskeyAttribs( $this->mSubmitTooltip );
+ }
+
+ $attribs['class'] = 'mw-htmlform-submit';
- $html .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
+ $html .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
+ }
if ( $this->mShowReset ) {
$html .= Html::element(
return $this;
}
+ /**
+ * Stop a default submit button being shown for this form. This implies that an
+ * alternate submit method must be provided manually.
+ *
+ * @since 1.22
+ *
+ * @param bool $suppressSubmit Set to false to re-enable the button again
+ *
+ * @return HTMLForm $this for chaining calls
+ */
+ function suppressDefaultSubmit( $suppressSubmit = true ) {
+ $this->mShowSubmit = !$suppressSubmit;
+ return $this;
+ }
+
/**
* @param string $id DOM id for the form
* @return HTMLForm $this for chaining calls (since 1.20)
}
public function getInputHTML( $value ) {
- return Xml::submitButton(
- $value,
- array(
- 'class' => 'mw-htmlform-submit ' . $this->mClass,
- 'name' => $this->mName,
- 'id' => $this->mID,
- )
+ $attr = array(
+ 'class' => 'mw-htmlform-submit ' . $this->mClass,
+ 'name' => $this->mName,
+ 'id' => $this->mID,
);
+
+ if ( !empty( $this->mParams['disabled'] ) ) {
+ $attr['disabled'] = 'disabled';
+ }
+
+ return Xml::submitButton( $value, $attr );
}
protected function needsLabel() {
*
* If called with no arguments, all values will be returned.
*
- * @param selection mixed String key or array of keys to get values for.
- * @param fallback mixed Value to use in case key(s) do not exist (optional).
+ * @param {string|Array} selection String key or array of keys to get values for.
+ * @param {Mixed} [fallback] Value to use in case key(s) do not exist.
* @return mixed If selection was a string returns the value or null,
* If selection was an array, returns an object of key/values (value is null if not found),
* If selection was not passed or invalid, will return the 'values' object member (be careful as
/**
* Sets one or multiple key/value pairs.
*
- * @param selection {mixed} String key or array of keys to set values for.
- * @param value {mixed} Value to set (optional, only in use when key is a string)
+ * @param {string|Object} selection String key to set value for, or object mapping keys to values.
+ * @param {Mixed} [value] Value to set (optional, only in use when key is a string)
* @return {Boolean} This returns true on success, false on failure.
*/
set: function ( selection, value ) {
/**
* Checks if one or multiple keys exist.
*
- * @param selection {mixed} String key or array of keys to check
+ * @param {Mixed} selection String key or array of keys to check
* @return {boolean} Existence of key(s)
*/
exists: function ( selection ) {
Message.prototype = {
/**
- * Simple message parser, does $N replacement, HTML-escaping (only for
- * 'escaped' format), and nothing else.
+ * Simple message parser, does $N replacement and nothing else.
*
* This may be overridden to provide a more complex message parser.
*
*
* @private
* @param {string|string[]} states Module states to filter by
- * @param {Array} modules List of module names to filter (optional, by default the entire
+ * @param {Array} [modules] List of module names to filter (optional, by default the entire
* registry is used)
* @return {Array} List of filtered module names
*/
* Registers a module, letting the system know about it and its
* properties. Startup modules contain calls to this function.
*
- * @param module {String}: Module name
- * @param version {Number}: Module version number as a timestamp (falls backs to 0)
- * @param dependencies {String|Array|Function}: One string or array of strings of module
+ * @param {string} module Module name
+ * @param {number} version Module version number as a timestamp (falls backs to 0)
+ * @param {string|Array|Function} dependencies One string or array of strings of module
* names on which this module depends, or a function that returns that array.
- * @param group {String}: Group which the module is in (optional, defaults to null)
- * @param source {String}: Name of the source. Defaults to local.
+ * @param {string} [group=null] Group which the module is in
+ * @param {string} [source='local'] Name of the source
*/
register: function ( module, version, dependencies, group, source ) {
var m;
/**
* Executes a function as soon as one or more required modules are ready
*
- * @param dependencies {String|Array} Module name or array of modules names the callback
+ * @param {string|Array} dependencies Module name or array of modules names the callback
* dependends on to be ready before executing
- * @param ready {Function} callback to execute when all dependencies are ready (optional)
- * @param error {Function} callback to execute when if dependencies have a errors (optional)
+ * @param {Function} [ready] callback to execute when all dependencies are ready
+ * @param {Function} [error] callback to execute when if dependencies have a errors
*/
using: function ( dependencies, ready, error ) {
var tod = typeof dependencies;
/**
* Loads an external script or one or more modules for future use
*
- * @param modules {mixed} Either the name of a module, array of modules,
+ * @param {string|Array} modules Either the name of a module, array of modules,
* or a URL of an external script or style
- * @param type {String} mime-type to use if calling with a URL of an
+ * @param {string} [type='text/javascript'] mime-type to use if calling with a URL of an
* external script or style; acceptable values are "text/css" and
* "text/javascript"; if no type is provided, text/javascript is assumed.
- * @param async {Boolean} (optional) If true, load modules asynchronously
- * even if document ready has not yet occurred. If false (default),
- * block before document ready and load async after. If not set, true will
- * be assumed if loading a URL, and false will be assumed otherwise.
+ * @param {boolean} [async] If true, load modules asynchronously
+ * even if document ready has not yet occurred. If false, block before
+ * document ready and load async after. If not set, true will be
+ * assumed if loading a URL, and false will be assumed otherwise.
*/
load: function ( modules, type, async ) {
var filtered, m, module, l;
/**
* Changes the state of a module
*
- * @param module {String|Object} module name or object of module name/state pairs
- * @param state {String} state name
+ * @param {string|Object} module module name or object of module name/state pairs
+ * @param {string} state state name
*/
state: function ( module, state ) {
var m;
/**
* Gets the version of a module
*
- * @param module string name of module to get version for
+ * @param {string} module name of module to get version for
*/
getVersion: function ( module ) {
if ( registry[module] !== undefined && registry[module].version !== undefined ) {
/**
* Gets the state of a module
*
- * @param module string name of module to get state for
+ * @param {string} module name of module to get state for
*/
getState: function ( module ) {
if ( registry[module] !== undefined && registry[module].state !== undefined ) {
/**
* Create an HTML element string, with safe escaping.
*
- * @param name The tag name.
- * @param attrs An object with members mapping element names to values
- * @param contents The contents of the element. May be either:
+ * @param {string} name The tag name.
+ * @param {Object} attrs An object with members mapping element names to values
+ * @param {Mixed} contents The contents of the element. May be either:
* - string: The string is escaped.
* - null or undefined: The short closing form is used, e.g. <br/>.
* - this.Raw: The value attribute is included without escaping.
( function ( mw, $ ) {
- var mwLanguageCache = {}, oldGetOuterHtml, formatnumTests, specialCharactersPageName,
+ var mwLanguageCache = {}, formatnumTests, specialCharactersPageName,
expectedListUsers, expectedEntrypoints;
QUnit.module( 'mediawiki.jqueryMsg', QUnit.newMwEnvironment( {
setup: function () {
this.orgMwLangauge = mw.language;
mw.language = $.extend( true, {}, this.orgMwLangauge );
- oldGetOuterHtml = $.fn.getOuterHtml;
- $.fn.getOuterHtml = function () {
- var $div = $( '<div>' ), html;
- $div.append( $( this ).eq( 0 ).clone() );
- html = $div.html();
- $div.empty();
- $div = undefined;
- return html;
- };
// Messages that are reused in multiple tests
mw.messages.set( {
'external-link-replace': 'Foo [$1 bar]'
} );
+ mw.config.set( {
+ wgArticlePath: '/wiki/$1'
+ } );
+
specialCharactersPageName = '"Who" wants to be a millionaire & live on \'Exotic Island\'?';
- expectedListUsers = '注册' + $( '<a>' ).attr( {
- title: 'Special:ListUsers',
- href: mw.util.wikiGetlink( 'Special:ListUsers' )
- } ).text( '用户' ).getOuterHtml();
+ expectedListUsers = '注册<a title="Special:ListUsers" href="/wiki/Special:ListUsers">用户</a>';
expectedEntrypoints = '<a href="https://www.mediawiki.org/wiki/Manual:index.php">index.php</a>';
},
teardown: function () {
mw.language = this.orgMwLangauge;
- $.fn.getOuterHtml = oldGetOuterHtml;
}
} ) );
the bold was removed because it is not yet implemented.
*/
- assert.equal(
+ assert.htmlEqual(
parser( 'jquerymsg-test-statistics-users' ),
expectedListUsers,
'Piped wikilink'
);
expectedDisambiguationsText = 'The following pages contain at least one link to a disambiguation page.\nThey may have to link to a more appropriate page instead.\nA page is treated as a disambiguation page if it uses a template that is linked from ' +
- $( '<a>' ).attr( {
- title: 'MediaWiki:Disambiguationspage',
- href: mw.util.wikiGetlink( 'MediaWiki:Disambiguationspage' )
- } ).text( 'MediaWiki:Disambiguationspage' ).getOuterHtml() + '.';
+ '<a title="MediaWiki:Disambiguationspage" href="/wiki/MediaWiki:Disambiguationspage">MediaWiki:Disambiguationspage</a>.';
+
mw.messages.set( 'disambiguations-text', 'The following pages contain at least one link to a disambiguation page.\nThey may have to link to a more appropriate page instead.\nA page is treated as a disambiguation page if it uses a template that is linked from [[MediaWiki:Disambiguationspage]].' );
- assert.equal(
+ assert.htmlEqual(
parser( 'disambiguations-text' ),
expectedDisambiguationsText,
'Wikilink without pipe'
);
- assert.equal(
+ assert.htmlEqual(
parser( 'jquerymsg-test-version-entrypoints-index-php' ),
expectedEntrypoints,
'External link'
'Pipe trick should return error string.'
);
- expectedMultipleBars = $( '<a>' ).attr( {
- title: 'Main Page',
- href: mw.util.wikiGetlink( 'Main Page' )
- } ).text( 'Main|Page' ).getOuterHtml();
+ expectedMultipleBars = '<a title="Main Page" href="/wiki/Main_Page">Main|Page</a>';
mw.messages.set( 'multiple-bars', '[[Main Page|Main|Page]]' );
- assert.equal(
+ assert.htmlEqual(
parser( 'multiple-bars' ),
expectedMultipleBars,
'Bar in anchor'
);
- expectedSpecialCharacters = $( '<a>' ).attr( {
- title: specialCharactersPageName,
- href: mw.util.wikiGetlink( specialCharactersPageName )
- } ).text( specialCharactersPageName ).getOuterHtml();
+ expectedSpecialCharacters = '<a title=""Who" wants to be a millionaire & live on 'Exotic Island'?" href="/wiki/%22Who%22_wants_to_be_a_millionaire_%26_live_on_%27Exotic_Island%27%3F">"Who" wants to be a millionaire & live on 'Exotic Island'?</a>';
mw.messages.set( 'special-characters', '[[' + specialCharactersPageName + ']]' );
- assert.equal(
+ assert.htmlEqual(
parser( 'special-characters' ),
expectedSpecialCharacters,
'Special characters'
mw.messages.get( 'jquerymsg-test-statistics-users' ),
'Internal link message unchanged when format is \'text\''
);
- assert.equal(
+ assert.htmlEqual(
formatParse( 'jquerymsg-test-statistics-users' ),
expectedListUsers,
'Internal link message parsed when format is \'parse\''
mw.messages.get( 'jquerymsg-test-version-entrypoints-index-php' ),
'External link message unchanged when format is \'text\''
);
- assert.equal(
+ assert.htmlEqual(
formatParse( 'jquerymsg-test-version-entrypoints-index-php' ),
expectedEntrypoints,
'External link message processed when format is \'parse\''
'Foo [http://example.com bar]',
'External link message only substitutes parameter when format is \'text\''
);
- assert.equal(
+ assert.htmlEqual(
formatParse( 'external-link-replace', 'http://example.com' ),
'Foo <a href="http://example.com">bar</a>',
'External link message processed when format is \'parse\''
QUnit.test( 'Int', 4, function ( assert ) {
var parser = mw.jqueryMsg.getMessageFunction(),
newarticletextSource = 'You have followed a link to a page that does not exist yet. To create the page, start typing in the box below (see the [[{{Int:Helppage}}|help page]] for more info). If you are here by mistake, click your browser\'s back button.',
- expectedNewarticletext;
+ expectedNewarticletext,
+ helpPageTitle = 'Help:Contents';
- mw.messages.set( 'helppage', 'Help:Contents' );
+ mw.messages.set( 'helppage', helpPageTitle );
expectedNewarticletext = 'You have followed a link to a page that does not exist yet. To create the page, start typing in the box below (see the ' +
- $( '<a>' ).attr( {
- title: mw.msg( 'helppage' ),
- href: mw.util.wikiGetlink( mw.msg( 'helppage' ) )
- } ).text( 'help page' ).getOuterHtml() + ' for more info). If you are here by mistake, click your browser\'s back button.';
+ '<a title="Help:Contents" href="/wiki/Help:Contents">help page</a> for more info). If you are here by mistake, click your browser\'s back button.';
mw.messages.set( 'newarticletext', newarticletextSource );
- assert.equal(
+ assert.htmlEqual(
parser( 'newarticletext' ),
expectedNewarticletext,
'Link with nested message'
mw.messages.set( 'newarticletext-lowercase',
newarticletextSource.replace( 'Int:Helppage', 'int:helppage' ) );
- assert.equal(
+ assert.htmlEqual(
parser( 'newarticletext-lowercase' ),
expectedNewarticletext,
'Link with nested message, lowercase include'
'gender-plural-msg': '{{GENDER:$1|he|she|they}} {{PLURAL:$2|is|are}} awesome',
'grammar-msg': 'Przeszukaj {{GRAMMAR:grammar_case_foo|{{SITENAME}}}}',
'formatnum-msg': '{{formatnum:$1}}',
- 'int-msg': 'Some {{int:other-message}}'
+ 'int-msg': 'Some {{int:other-message}}',
+ 'mediawiki-test-version-entrypoints-index-php': '[https://www.mediawiki.org/wiki/Manual:index.php index.php]',
+ 'external-link-replace': 'Foo [$1 bar]'
} );
- // For formatnum tests
- mw.config.set( 'wgUserLanguage', 'en' );
+ mw.config.set( {
+ wgArticlePath: '/wiki/$1',
+
+ // For formatnum tests
+ wgUserLanguage: 'en'
+ } );
specialCharactersPageName = '"Who" wants to be a millionaire & live on \'Exotic Island\'?';
}
assert.ok( mw.config instanceof mw.Map, 'mw.config instance of mw.Map' );
} );
- QUnit.test( 'mw.message & mw.messages', 54, function ( assert ) {
+ QUnit.test( 'mw.message & mw.messages', 68, function ( assert ) {
var goodbye, hello;
// Convenience method for asserting the same result for multiple formats
assert.equal( hello.escaped(), 'Hello <b>awesome</b> world', 'Message.escaped returns the escaped message' );
assert.equal( hello.format, 'escaped', 'Message.escaped correctly updated the "format" property' );
- assert.ok( mw.messages.set( 'escaped-with-curly-brace', '"{{SITENAME}}" is the home of {{int:other-message}}' ) );
- assert.equal( mw.message( 'escaped-with-curly-brace' ).escaped(), mw.html.escape( '"' + mw.config.get( 'wgSiteName' ) + '" is the home of Other Message' ), 'Escaped format works correctly for curly brace message' );
+ assert.ok( mw.messages.set( 'multiple-curly-brace', '"{{SITENAME}}" is the home of {{int:other-message}}' ), 'mw.messages.set: Register' );
+ assertMultipleFormats( ['multiple-curly-brace'], ['text', 'parse'], '"' + mw.config.get( 'wgSiteName') + '" is the home of Other Message', 'Curly brace format works correctly' );
+ assert.equal( mw.message( 'multiple-curly-brace' ).plain(), mw.messages.get( 'multiple-curly-brace' ), 'Plain format works correctly for curly brace message' );
+ assert.equal( mw.message( 'multiple-curly-brace' ).escaped(), mw.html.escape( '"' + mw.config.get( 'wgSiteName') + '" is the home of Other Message' ), 'Escaped format works correctly for curly brace message' );
+
+ assert.ok( mw.messages.set( 'multiple-square-brackets-and-ampersand', 'Visit the [[Project:Community portal|community portal]] & [[Project:Help desk|help desk]]' ), 'mw.messages.set: Register' );
+ assertMultipleFormats( ['multiple-square-brackets-and-ampersand'], ['plain', 'text'], mw.messages.get( 'multiple-square-brackets-and-ampersand' ), 'Square bracket message is not processed' );
+ assert.equal( mw.message( 'multiple-square-brackets-and-ampersand' ).escaped(), 'Visit the [[Project:Community portal|community portal]] & [[Project:Help desk|help desk]]', 'Escaped format works correctly for square bracket message' );
+ assert.htmlEqual( mw.message( 'multiple-square-brackets-and-ampersand' ).parse(), 'Visit the ' +
+ '<a title="Project:Community portal" href="/wiki/Project:Community_portal">community portal</a>' +
+ ' & <a title="Project:Help desk" href="/wiki/Project:Help_desk">help desk</a>', 'Internal links work with parse' );
+
+ assertMultipleFormats( ['mediawiki-test-version-entrypoints-index-php'], ['plain', 'text', 'escaped'], mw.messages.get( 'mediawiki-test-version-entrypoints-index-php' ), 'External link markup is unprocessed' );
+ assert.htmlEqual( mw.message( 'mediawiki-test-version-entrypoints-index-php' ).parse(), '<a href="https://www.mediawiki.org/wiki/Manual:index.php">index.php</a>', 'External link works correctly in parse mode' );
- assert.ok( mw.messages.set( 'escaped-with-square-brackets', 'Visit the [[Project:Community portal|community portal]] & [[Project:Help desk|help desk]]' ) );
- assert.equal( mw.message( 'escaped-with-square-brackets' ).escaped(), 'Visit the [[Project:Community portal|community portal]] & [[Project:Help desk|help desk]]', 'Escaped format works correctly for square bracket message' );
+ assertMultipleFormats( ['external-link-replace', 'http://example.org/?x=y&z'], ['plain', 'text'] , 'Foo [http://example.org/?x=y&z bar]', 'Parameters are substituted but external link is not processed' );
+ assert.equal( mw.message( 'external-link-replace', 'http://example.org/?x=y&z' ).escaped(), 'Foo [http://example.org/?x=y&z bar]', 'In escaped mode, parameters are substituted and ampersand is escaped, but external link is not processed' );
+ assert.htmlEqual( mw.message( 'external-link-replace', 'http://example.org/?x=y&z' ).parse(), 'Foo <a href="http://example.org/?x=y&z">bar</a>', 'External link with replacement works in parse mode without double-escaping' );
hello.parse();
assert.equal( hello.format, 'parse', 'Message.parse correctly updated the "format" property' );
assert.ok( mw.messages.set( 'mediawiki-test-categorytree-collapse-bullet', '[<b>−</b>]' ), 'mw.messages.set: Register' );
assert.equal( mw.message( 'mediawiki-test-categorytree-collapse-bullet' ).plain(), mw.messages.get( 'mediawiki-test-categorytree-collapse-bullet' ), 'Single square brackets unchanged in plain mode' );
- assert.ok( mw.messages.set( 'mediawiki-test-wikieditor-toolbar-help-content-signature-result', '<a href=\'#\' title=\'{{#special:mypage}}\'>Username</a> (<a href=\'#\' title=\'{{#special:mytalk}}\'>talk</a>)' ) );
+ assert.ok( mw.messages.set( 'mediawiki-test-wikieditor-toolbar-help-content-signature-result', '<a href=\'#\' title=\'{{#special:mypage}}\'>Username</a> (<a href=\'#\' title=\'{{#special:mytalk}}\'>talk</a>)' ), 'mw.messages.set: Register' );
assert.equal( mw.message( 'mediawiki-test-wikieditor-toolbar-help-content-signature-result' ).plain(), mw.messages.get( 'mediawiki-test-wikieditor-toolbar-help-content-signature-result' ), 'HTML message with curly braces is not changed in plain mode' );
assertMultipleFormats( ['gender-plural-msg', 'male', 1], ['text', 'parse', 'escaped'], 'he is awesome', 'Gender and plural are resolved' );
assert.equal( mw.msg( 'hello' ), 'Hello <b>awesome</b> world', 'Gets message with default options (existing message)' );
assert.equal( mw.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (nonexistent message)' );
- assert.ok( mw.messages.set( 'plural-item', 'Found $1 {{PLURAL:$1|item|items}}' ) );
+ assert.ok( mw.messages.set( 'plural-item' , 'Found $1 {{PLURAL:$1|item|items}}' ), 'mw.messages.set: Register' );
assert.equal( mw.msg( 'plural-item', 5 ), 'Found 5 items', 'Apply plural for count 5' );
assert.equal( mw.msg( 'plural-item', 0 ), 'Found 0 items', 'Apply plural for count 0' );
assert.equal( mw.msg( 'plural-item', 1 ), 'Found 1 item', 'Apply plural for count 1' );