/* Methods */
public MediaWikiText getInput(UIComponent uiForRequests) {
MediaWikiText result = null;
//check if there are still articles left, if yes, return the next one of them
if( titleIterator != null && titleIterator.hasNext() ){
String articleName = titleIterator.next();
result = readArticle(articleName);
} else { //if no articles are left
/* ask for input type (article, category ...),
* name of the article/cat./... and
* restrictions to selected articles
*/
String helpString = str("selectionHelp_Base");
// Is the prefix for image pages specified in the configuration file?
if (!imagePrefix.equals("")) {
helpString += str("selectionHelp_ImagePrefixYes",
imagePrefix);
} else if (!templatePrefix.equals("")) {
// No, but the template prefix is.
helpString += str("selectionHelp_ImagePrefixNo");
}
// Is the prefix for template pages specified in the configuration file?
if (!templatePrefix.equals("")) {
helpString += str("selectionHelp_TemplatePrefixYes",
templatePrefix);
} else if (!imagePrefix.equals("")) {
// Same here ...
helpString += str("selectionHelp_TemplatePrefixNo");
}
// Both prefixes are not specified
if (imagePrefix.equals("") && templatePrefix.equals("")) {
helpString += str("selectionHelp_BothNo");
}
helpString += str("selectionHelp_Restrictions");
List<UIRequest> requestList = new LinkedList<UIRequest>();
int selectedURLIndex = indexOfUrlInURLStringArray(conf_wikiURLs, currentURL);
if (selectedURLIndex == -1) {selectedURLIndex = 0;} //use first one by default
requestList.add(new UIRequest_Selection("url", str("mediaWikiRead"), str("helpMediaWikiRead"), selectedURLIndex, conf_wikiURLs));
requestList.add(new UIRequest_Selection("type", str("inputType"), str("helpInputType"), 0,
new String[]{str("inputSingleArticle"),
str("inputFrom"),
str("inputPrefix"),
str("inputCategory"),
str("inputLinkingTo"),
str("inputUsingImage"),
str("inputEmbeddingTemplate")}));
requestList.add(new UIRequest_String("name", str("inputName"), str("helpInputName")));
for (int i = 0; i < restrictionsInArticleSelection; i++ ) {
requestList.add(new UIRequest_Selection(
"restriction_type_" + i,
str("restrictionType", (i+1)),
str("helpRestrictionType"),
0,
new String[]{str("restrictionNone"),
str("inputFrom"),
str("inputPrefix")}));
requestList.add(new UIRequest_String(
"restriction_value_" + i,
str("restrictionValue", (i+1)),
str("helpRestrictionValue")));
}
requestList.add(new UIRequest_Output(helpString));
UIRequest[] requestArray = new UIRequest[requestList.size()];
requestArray = requestList.toArray(requestArray);
NamedDataSet reply = uiForRequests.request(requestArray);
if (reply == null) { return null; } //cancelled - #### !! return-point !! ####
try { //catch MalformedURLException and NamedDataNotAvailableException
createBot(conf_wikiURLs[reply.<Integer>get("url")]);
Integer type = reply.get("type");
String name = reply.get("name");
if ( type == 0 /*article*/ ){
result = readArticle(name);
}
else { //one of the iterator-generating types
try { //catch JWBFExceptions
/* get the appropriate iterator */
switch (type) {
case 1: /*articles from*/
titleIterator = new AllPageTitles(bot, name,null,nonredirects).iterator();
break;
case 2: /*articles starting with*/
titleIterator = new AllPageTitles(bot,null,name,nonredirects).iterator();
break;
case 3: /*category*/
titleIterator = new CategoryMembersSimple(bot, name).iterator();
break;
case 4: /*backlinks*/
titleIterator = new BacklinkTitles(bot, name).iterator();
break;
case 5: /*imagelinks*/
if (!imagePrefix.equals("")) {
name = imagePrefix + name;
}
titleIterator = new ImageUsageTitles(bot, name).iterator();
break;
case 6: /*template users*/
if (!templatePrefix.equals("")) {
name = templatePrefix + name;
}
titleIterator = new TemplateUserTitles(bot, name).iterator();
break;
}
/* apply the restrictions */
for (int i = 0; i < restrictionsInArticleSelection;
i ++) {
Integer restrictionType =
reply.get("restriction_type_" + i);
String restrictionValue =
reply.get("restriction_value_" + i);
if (restrictionType > 0 &&
restrictionValue != null) {
switch (restrictionType) {
case 1: /* articles from */
titleIterator =
new RestrictedIterator_StartFrom(
titleIterator,
restrictionValue);
break;
case 2: /* articles starting with */
titleIterator =
new RestrictedIterator_Prefix(
titleIterator,
restrictionValue);
break;
}
}
}
} catch (VersionException ve) {
String error = str("errorReceivingInfoWithExceptionName", "VersionException", ve.getMessage());
uiForRequests.request(new UIRequest_Output(error));
} catch (CookieException ce) {
String error = str("errorReceivingInfoWithExceptionName", "CookieException", ce.getMessage());
uiForRequests.request(new UIRequest_Output(error));
} catch (JwbfException je) {
String error = str("errorReceivingInfo", je.getMessage());
uiForRequests.request(new UIRequest_Output(error));
}
//return the first article
if (titleIterator.hasNext()) {
result = readArticle(titleIterator.next());
} else {
result = null;
}
}
} catch (MalformedURLException e) {
uiForRequests.request(
new UIRequest_Output(
str("errorMalformedURL") + e.getMessage() ));
} catch (NamedDataNotAvailableException e) {
uiForRequests.request(new UIRequest_Output(str("errorUserInput")));
}
}
/* optionally show read article in browser, then return text */
if (showArticleInBrowser && result != null) {
openArticleInBrowser(uiForRequests, result.getLabel());
}
return result;
}