本文整理汇总了Java中org.wikipedia.Wiki类的典型用法代码示例。如果您正苦于以下问题:Java Wiki类的具体用法?Java Wiki怎么用?Java Wiki使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Wiki类属于org.wikipedia包,在下文中一共展示了Wiki类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.wikipedia.Wiki; //导入依赖的package包/类
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String wiki = "commons.wikimedia.org";
String protocol = "https://";
String scriptPath = "/w";
for (String arg : args) {
String[] pair = arg.split("=");
if (pair[0].contains("wiki")) {
wiki = pair[1];
} else if (pair[0].contains("protocol")) {
protocol = pair[1];
} else if (pair[0].contains("scriptPath")) {
scriptPath = pair[1];
}
}
LOGGER.log(Level.INFO,
"Wiki set as: {0}\nProtocol set as: {1}\nScript path set as: {2}",
new String[]{wiki, protocol, scriptPath}
);
Session.WIKI = new Wiki(wiki, scriptPath, protocol);
launch(args);
}
示例2: templateReplace
import org.wikipedia.Wiki; //导入依赖的package包/类
/**
* Replaces all transclusions of a template/page with specified text
*
* @param template The template (including namespace prefix) to be replaced
* @param replacementText The text to replace the template with (can include subst:XXXX)
* @param reason Edit summary to use
* @param wiki The wiki object to use.
*
* @throws IOException If network error.
*
*
*/
public static void templateReplace(String template, String replacementText, String reason, Wiki wiki) throws IOException
{
String[] list = wiki.whatTranscludesHere(template);
if (template.startsWith("Template:"))
template = namespaceStrip(template, wiki);
for (String page : list)
{
try
{
wiki.edit(page, wiki.getPageText(page).replaceAll("(?i)(" + template + ")", replacementText), reason);
}
catch (Throwable e)
{
e.printStackTrace();
}
}
}
示例3: nullEdit
import org.wikipedia.Wiki; //导入依赖的package包/类
/**
* Performs null edit on a list of pages by wiki. PRECONDITION: wiki object must be logged in
*
* @param wiki The wiki object to use
* @param l The list of pages to null edit.
*/
public static void nullEdit(Wiki wiki, String... l)
{
for (String s : l)
{
try
{
System.err.println("Attempting null edit on '" + s + "'");
wiki.edit(s, wiki.getPageText(s), "");
}
catch (Throwable e)
{
e.printStackTrace();
}
}
}
示例4: namespaceFilter
import org.wikipedia.Wiki; //导入依赖的package包/类
/**
* Removes all titles of a certain namespace.
*
* @param wiki The wiki object to use.
* @param titles The list of titles to use.
* @param ns The namespaces to filter out.
* @return A new list of titles with this change.
* @throws IOException Eh?
*/
public static String[] namespaceFilter(Wiki wiki, String[] titles, int... ns) throws IOException
{
ArrayList<String> l = new ArrayList<String>();
for(String s : titles)
{
boolean flag = false;
for(int i : ns)
if(wiki.namespace(s) == i)
{
flag = true;
break;
}
if(!flag)
l.add(s);
}
return l.toArray(new String[0]);
}
示例5: guiLogin
import org.wikipedia.Wiki; //导入依赖的package包/类
public static void guiLogin(Wiki wiki) {
JTextField u = new JTextField(12);
JPasswordField px = new JPasswordField(12);
do {
JPanel pl = FbotUtil.buildForm("Login",
new JLabel("Username:", 11), u,
new JLabel("Password:", 11), px);
if (JOptionPane.showConfirmDialog(null, pl, "Login", 2, -1) != 0) {
System.exit(0);
}
} while (!Fbot.loginAndSetPrefs(wiki, u.getText().trim(),
px.getPassword()));
wiki.setThrottle(5);
}
示例6: fileReplace
import org.wikipedia.Wiki; //导入依赖的package包/类
public static void fileReplace(String[] list, String file,
String replacement, String summary, Wiki wiki) {
file = file.replace((CharSequence) "_", (CharSequence) " ");
String regex = "(?i)(" + file + "|"
+ file.replace((CharSequence) " ", (CharSequence) "_") + ")";
for (String page : list) {
try {
wiki.edit(page,
wiki.getPageText(page).replaceAll(regex, replacement),
summary);
continue;
} catch (Throwable e) {
e.printStackTrace();
}
}
}
示例7: findAndReplace
import org.wikipedia.Wiki; //导入依赖的package包/类
/**
* Generic find and replace method.
*
* @param find The text to be found. You can use a regex for this
* @param replacement The text to replace any text matching the <tt>find</tt> field
* @param summary The edit summary to use
* @param wiki The wiki object to use
* @param pages The wiki pages to act upon.
*/
public static void findAndReplace(String find, String replacement, String summary, Wiki wiki, String... pages)
{
for (String s : pages)
{
try
{
wiki.edit(s, wiki.getPageText(s).replaceAll(find, replacement), summary);
}
catch (Throwable e)
{
e.printStackTrace();
}
}
}
示例8: categoryIsEmpty
import org.wikipedia.Wiki; //导入依赖的package包/类
/**
* Determines if a category is empty.
*
* @param wiki The wiki object to use
* @param cat Category name, with or without "Category:" prefix, in any language, is fine.
*
* @return True if the category is empty.
*/
public static boolean categoryIsEmpty(Wiki wiki, String cat)
{
try
{
return wiki.getCategoryMembers(ParseUtils.namespaceStrip(cat, wiki)).length == 0;
}
catch (Throwable e)
{
return false;
}
}
示例9: intersectEditors
import org.wikipedia.Wiki; //导入依赖的package包/类
/**
* Given a set of <var>users</var>, find the list of articles they have
* edited. Includes deleted contributions if {@link #isUsingAdminPrivileges()}
* is <code>true</code> and ignores minor edits if {@link #isIgnoringMinorEdits()}
* is <code>true</code>.
*
* @param users the list of users to fetch contributions for
* @return a map with page → list of revisions made
* @throws IOException if a network error occurs
*/
public Map<String, List<Wiki.Revision>> intersectEditors(String[] users) throws IOException
{
// fetch the list of (deleted) edits
List<Wiki.Revision>[] revisions = wiki.contribs(users, "", null, null, null);
Stream<Wiki.Revision> revstream = Arrays.stream(revisions).flatMap(List::stream);
if (adminmode)
{
Stream<Wiki.Revision> revstream2 = Arrays.stream(users).flatMap(user ->
{
try
{
return Arrays.stream(wiki.deletedContribs(user));
}
catch (IOException | CredentialNotFoundException ex)
{
// If a network or privilege error occurs when fetching
// deleted contributions, that will be skipped with live
// edits returned.
return Stream.empty();
}
});
revstream = Stream.concat(revstream, revstream2);
}
// we cannot filter by sizediff here, the MediaWiki API does not return
// this information for deleted revisions
if (nominor)
revstream = revstream.filter(rev -> !rev.isMinor());
return revstream.collect(Collectors.groupingBy(Wiki.Revision::getPage));
}
示例10: parseDiff
import org.wikipedia.Wiki; //导入依赖的package包/类
@Test
public void parseDiff() throws IOException
{
Wiki.Revision[] revs = testWiki.getRevisions(new long[]
{
244169L, 244170L, 244171L, 320307L
});
// https://test.wikipedia.org/w/index.php?oldid=244169&diff=prev
Map<Wiki.Revision, List<String>> results = UserLinkAdditionFinder.parseDiff(revs[0]);
List<String> links = results.get(revs[0]);
assertNotNull(links);
assertEquals(1, links.size());
assertEquals("http://spam.example.com", links.get(0));
// https://test.wikipedia.org/w/index.php?oldid=244170&diff=prev
results = UserLinkAdditionFinder.parseDiff(revs[1]);
links = results.get(revs[1]);
assertEquals("https://en.wikipedia.org", links.get(0));
// https://test.wikipedia.org/w/index.php?oldid=244171&diff=prev
results = UserLinkAdditionFinder.parseDiff(revs[2]);
links = results.get(revs[2]);
assertEquals("http://www.example.net", links.get(0));
// dummy edit
// https://test.wikipedia.org/w/index.php?oldid=320307&diff=prev
results = UserLinkAdditionFinder.parseDiff(revs[3]);
links = results.get(revs[3]);
assertEquals(0, links.size());
}
示例11: setUpClass
import org.wikipedia.Wiki; //导入依赖的package包/类
/**
* Initializes intersector object.
* @throws Exception if a network error occurs
*/
@BeforeClass
public static void setUpClass() throws Exception
{
Wiki testWiki = Wiki.createInstance("test.wikipedia.org");
testWiki.setMaxLag(-1);
intersector = new ArticleEditorIntersector(testWiki);
}
示例12: MBot
import org.wikipedia.Wiki; //导入依赖的package包/类
public /* varargs */ MBot(String user, char[] px, String domain, int instances, String[] list, String ... reason) throws FailedLoginException, IOException {
Wiki t = new Wiki(domain);
t.setMaxLag(-1);
t.login(user, px);
this.lists = FbotUtil.arraySplitter(list, instances);
this.wikis = new Wiki[this.lists.length];
for (int i = 0; i < this.lists.length; ++i) {
this.wikis[i] = Fbot.wikiFactory(user, px, domain);
}
this.reason = reason;
}
示例13: getRedirectsAsRegex
import org.wikipedia.Wiki; //导入依赖的package包/类
public static String getRedirectsAsRegex(String template, Wiki wiki) throws IOException {
String r = "(?si)\\{{2}?\\s*?(Template:)??\\s*?(" + FbotParse.namespaceStrip(template);
for (String str : wiki.whatLinksHere(template, true, 10)) {
r = r + "|" + FbotParse.namespaceStrip(str);
}
r = r + ").*?\\}{2}?";
return r;
}
示例14: templateReplace
import org.wikipedia.Wiki; //导入依赖的package包/类
public static void templateReplace(String template, String replacementText, String reason, Wiki wiki) throws IOException {
String[] list = wiki.whatTranscludesHere(template, new int[0]);
if (template.startsWith("Template:")) {
template = FbotParse.namespaceStrip(template);
}
for (String page : list) {
try {
wiki.edit(page, wiki.getPageText(page).replaceAll("(?i)(" + template + ")", replacementText), reason);
continue;
}
catch (Throwable e) {
e.printStackTrace();
}
}
}
示例15: getRedirectTarget
import org.wikipedia.Wiki; //导入依赖的package包/类
public static String getRedirectTarget(String redirect, Wiki wiki)
throws IOException {
String text = wiki.getPageText(redirect).trim();
if (text.matches("(?si)^#(redirect)\\s*?\\[\\[.+?\\]\\].*?")) {
return text.substring(text.indexOf("[[") + 2, text.indexOf("]]"));
}
throw new UnsupportedOperationException(
"Parameter passed in is not a redirect page!");
}