* can override the parameter defaults and ajax default options.
* XXX document!
*
+ * TODO share api objects with exact same config.
+ *
* ajax options can also be overriden on every get() or post()
*
* @param options {Mixed} can take many options, but must include at minimum the API url.
*/
mw.Api = function( options ) {
+ if ( options === undefined ) {
+ options = {};
+ }
+
// make sure we at least have a URL endpoint for the API
if ( options.url === undefined ) {
- throw new Error( 'Configuration error - needs url property' );
+ options.url = mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api' + mw.config.get( 'wgScriptExtension' );
}
this.url = options.url;
/**
* Thingy for collecting user feedback on a wiki page
- * @param {mw.api} api properly configured to talk to this wiki
- * @param {mw.Title} the title of the page where you collect feedback
- * @param {String} optional - message key for the title of the dialog box
+ * @param {Array} options -- optional, all properties optional.
+ * api: {mw.Api} if omitted, will just create a standard API
+ * title: {mw.Title} the title of the page where you collect feedback. Defaults to "Feedback".
+ * dialogTitleMessageKey: {String} message key for the title of the dialog box
*/
- mw.Feedback = function( api, feedbackTitle, dialogTitleMessageKey ) {
- var _this = this;
- this.api = api;
- this.feedbackTitle = feedbackTitle;
- this.dialogTitleMessageKey = dialogTitleMessageKey;
- if ( this.dialogTitleMessageKey === undefined ) {
- this.dialogTitleMessageKey = 'feedback-submit';
+ mw.Feedback = function( options ) {
+
+ if ( options === undefined ) {
+ options = {};
+ }
+
+ if ( options.api === undefined ) {
+ options.api = new mw.Api();
+ }
+
+ if ( options.title === undefined ) {
+ options.title = new mw.Title( 'Feedback' );
+ }
+
+ if ( options.dialogTitleMessageKey === undefined ) {
+ options.dialogTitleMessageKey = 'feedback-submit';
}
+
+ this.api = options.api;
+ this.feedbackTitle = options.title;
+ this.dialogTitleMessageKey = options.dialogTitleMessageKey;
this.setup();
};