int selectedURLIndex = indexOfUrlInURLStringArray(conf_wikiURLs, text.getWikiURL());
UIRequest[] overviewRequestArray = new UIRequest[] {
new UIRequest_Selection("url", str("mediaWikiWrite"), str("helpMediaWikiWrite"), selectedURLIndex, wikiURLs),
new UIRequest_String("label", str("articleName"), str("helpArticleName"), text.getLabel()),
new UIRequest_String("text", str("articleText"), str("helpArticleText"), text.getText(),multipleLines,lineWrap),
new UIRequest_String("summary", str("summary"), str("helpSummary"), text.getEditSummary()),
new UIRequest_Boolean("minor", str("minor"), str("helpMinor"), text.isMinorEdit())
};
NamedDataSet overviewReply = uiForRequests.request(overviewRequestArray);
if ( overviewReply == null ) {
text = null;
completed = true;
} else {
try {
createBot(conf_wikiURLs[overviewReply.<Integer>get("url")]);
text.setLabel(overviewReply.<String>get("label"));
text.setText(overviewReply.<String>get("text"));
text.setEditSummary(overviewReply.<String>get("summary"));
text.setMinorEdit(overviewReply.<Boolean>get("minor"));
completed = true;
} catch (MalformedURLException e) {
uiForRequests.request(
new UIRequest_Output(
str("errorMalformedURL", e.getMessage())));
} catch (NamedDataNotAvailableException e) {
uiForRequests.request(new UIRequest_Output(str("errorUserInput")));
}
}
}
} else {
if (text.getWikiURL() != null) {
try {
createBot(text.getWikiURL().toString());
} catch (MalformedURLException e) {
//do nothing, user will be asked
}
}
if (bot == null || alwaysAskForOutputWiki) {
int selectedURLIndex = indexOfUrlInURLStringArray(wikiURLs, text.getWikiURL());
UIRequest[] requestArray = new UIRequest[] {
new UIRequest_Selection("url", str("mediaWikiWrite"), str("helpMediaWikiWrite"), selectedURLIndex, conf_wikiURLs)
};
NamedDataSet reply = uiForRequests.request(requestArray);
try {
createBot(conf_wikiURLs[reply.<Integer>get("url")]);
} catch (MalformedURLException e) {
uiForRequests.request(
new UIRequest_Output(
str("errorMalformedURL", e.getMessage())));
} catch (NamedDataNotAvailableException e) {
uiForRequests.request(new UIRequest_Output(str("errorUserInput")));
}
}
}
/* write the article to the wiki (after logging in) */
if( text != null ){
/*
* if the bot is not logged in,
* but all information is available to log in, do so
*/
if( !bot.isLoggedIn()
&& username != null && !username.equals("")
&& password != null ){
try {
bot.login(username, password);
} catch (ActionException e) {
/* the "Login failed" message will be printed */
}
if ( !bot.isLoggedIn() && !password.equals("") ) {
uiForRequests.request(
new UIRequest_Output(str("errorLoginFailed")) );
}
}
/*
* if bot (still) not logged in, ask for username and password
* until the bot is logged in or the user gives up
*/
boolean tryAgain = true;
while( !bot.isLoggedIn() && tryAgain ){
UIRequest requestArray[] = {
new UIRequest_String("username", str("username"),
str("helpUsername"), username),
new UIRequest_String("password", str("password"),
str("helpPassword"),
UIRequest_String.LayoutFlag.hideInput)
};
NamedDataSet reply = uiForRequests.request(requestArray);