Package org.fastily.jwiki.core
Class MQuery
java.lang.Object
org.fastily.jwiki.core.MQuery
public final class MQuery extends Object
Perform multi-title queries. Use of these methods is intended for
advanced users who wish to make queries to the server over a large
data set. These methods are optimized for performance, and will consolidate titles into single queries to fetch the
most data possible per query. If you're looking to make simple, single-item queries, (which is suitable for most
users) please use the methods in Wiki.java.
- Author:
- Fastily
- See Also:
Wiki
-
Method Summary
Modifier and Type Method Description static ArrayList<String>
exists(Wiki wiki, boolean exists, Collection<String> titles)
Checks if a title exists.static HashMap<String,Boolean>
exists(Wiki wiki, Collection<String> titles)
Checks if list of titles exists.static HashMap<String,ArrayList<String>>
fileUsage(Wiki wiki, Collection<String> titles)
Gets a list of pages linking (displaying/thumbnailing) a file.static HashMap<String,ArrayList<String>>
getCategoriesOnPage(Wiki wiki, Collection<String> titles)
Gets the list of categories on a page.static HashMap<String,Integer>
getCategorySize(Wiki wiki, Collection<String> titles)
Gets the number of elements contained in a category.static HashMap<String,ArrayList<String>>
getDuplicatesOf(Wiki wiki, boolean localOnly, Collection<String> titles)
Gets duplicates of a file.static HashMap<String,ArrayList<String>>
getExternalLinks(Wiki wiki, Collection<String> titles)
Gets a list of external (non-interwiki) links on the specified titles.static HashMap<String,ArrayList<ImageInfo>>
getImageInfo(Wiki wiki, Collection<String> titles)
Gets ImageInfo objects for each revision of a File.static HashMap<String,ArrayList<String>>
getImagesOnPage(Wiki wiki, Collection<String> titles)
Gets titles of images linked on a page.static HashMap<String,ArrayList<String>>
getLinksOnPage(Wiki wiki, Collection<String> titles, NS... ns)
Get wiki links on a page.static HashMap<String,String>
getPageText(Wiki wiki, Collection<String> titles)
Gets the text of a page.static HashMap<String,ArrayList<String>>
getSharedDuplicatesOf(Wiki wiki, Collection<String> titles)
Gets shared (non-local) duplicates of a file.static HashMap<String,ArrayList<String>>
getTemplatesOnPage(Wiki wiki, Collection<String> titles)
Get templates transcluded on a page.static HashMap<String,String>
getTextExtracts(Wiki wiki, Collection<String> titles)
Gets a text extract (the lead paragraph) of a page.static HashMap<String,ArrayList<Tuple<String,String>>>
globalUsage(Wiki wiki, Collection<String> titles)
Gets the global usage of a file.static HashMap<String,ArrayList<String>>
linksHere(Wiki wiki, boolean redirects, Collection<String> titles)
Get pages redirecting to or linking to a page.static HashMap<String,ArrayList<String>>
listUserRights(Wiki wiki, Collection<String> users)
Gets the list of usergroups (rights) users belong to.static HashMap<String,String>
resolveRedirects(Wiki wiki, Collection<String> titles)
Resolves title redirects on a Wiki.static HashMap<String,ArrayList<String>>
transcludesIn(Wiki wiki, Collection<String> titles, NS... ns)
Gets a list of pages transcluding a template.
-
Method Details
-
listUserRights
public static HashMap<String,ArrayList<String>> listUserRights(Wiki wiki, Collection<String> users)Gets the list of usergroups (rights) users belong to. Sample groups: sysop, user, autoconfirmed, editor.- Parameters:
wiki
- The Wiki object to use.users
- Users to get rights information for. Do not includeUser:
prefix.- Returns:
- A Map such that the key is the user and the value a List of the user's rights (or null if the user does not exist)
-
getImageInfo
public static HashMap<String,ArrayList<ImageInfo>> getImageInfo(Wiki wiki, Collection<String> titles)Gets ImageInfo objects for each revision of a File.- Parameters:
wiki
- The Wiki object to usetitles
- The titles to query- Returns:
- A map with titles keyed to respective lists of ImageInfo.
-
getCategoriesOnPage
public static HashMap<String,ArrayList<String>> getCategoriesOnPage(Wiki wiki, Collection<String> titles)Gets the list of categories on a page.- Parameters:
wiki
- The wiki object to usetitles
- The titles to query.- Returns:
- A list of results keyed by title.
-
getCategorySize
Gets the number of elements contained in a category.- Parameters:
wiki
- The wiki object to usetitles
- The titles to query. PRECONDITION: Titles *must* begin with the "Category:" prefix- Returns:
- A list of results keyed by title. Value returned will be -1 if Category entered was empty and non-existent.
-
getPageText
Gets the text of a page.- Parameters:
wiki
- The wiki to usetitles
- The titles to query- Returns:
- A list of results keyed by title.
-
getLinksOnPage
public static HashMap<String,ArrayList<String>> getLinksOnPage(Wiki wiki, Collection<String> titles, NS... ns)Get wiki links on a page.- Parameters:
wiki
- The wiki object to usetitles
- The titles to query.ns
- Namespaces to include-only. Optional param: leave blank to disable.- Returns:
- A list of results keyed by title.
-
linksHere
public static HashMap<String,ArrayList<String>> linksHere(Wiki wiki, boolean redirects, Collection<String> titles)Get pages redirecting to or linking to a page.- Parameters:
wiki
- The wiki object to useredirects
- Set to true to search for redirects. False searches for non-redirects.titles
- The titles to query- Returns:
- A list of results keyed by title.
-
transcludesIn
public static HashMap<String,ArrayList<String>> transcludesIn(Wiki wiki, Collection<String> titles, NS... ns)Gets a list of pages transcluding a template.- Parameters:
wiki
- The wiki object to usetitles
- The titles to queryns
- Only return results from this/these namespace(s). Optional param: leave blank to disable.- Returns:
- A list of results keyed by title.
-
fileUsage
Gets a list of pages linking (displaying/thumbnailing) a file.- Parameters:
wiki
- The wiki to usetitles
- The titles to query. PRECONDITION: These must be valid file names prefixed with the "File:" prefix.- Returns:
- A Map of results keyed by title.
-
getExternalLinks
public static HashMap<String,ArrayList<String>> getExternalLinks(Wiki wiki, Collection<String> titles)Gets a list of external (non-interwiki) links on the specified titles.- Parameters:
wiki
- The Wiki object to usetitles
- The titles to query- Returns:
- A Map of results keyed by title.
-
exists
Checks if list of titles exists.- Parameters:
wiki
- The wiki object to usetitles
- The titles to query.- Returns:
- Results keyed by title.
true
means the title exists.
-
exists
Checks if a title exists. Can filter results based on whether pages exist.- Parameters:
wiki
- The wiki object to useexists
- Set to true to select all pages that exist. False selects all that don't existtitles
- The titles to query.- Returns:
- A list of titles that exist or don't exist.
-
getImagesOnPage
public static HashMap<String,ArrayList<String>> getImagesOnPage(Wiki wiki, Collection<String> titles)Gets titles of images linked on a page.- Parameters:
wiki
- The wiki object to usetitles
- The titles to query- Returns:
- A list of results keyed by title.
-
getTemplatesOnPage
public static HashMap<String,ArrayList<String>> getTemplatesOnPage(Wiki wiki, Collection<String> titles)Get templates transcluded on a page.- Parameters:
wiki
- The wiki object to usetitles
- The titles to query- Returns:
- A list of results keyed by title.
-
globalUsage
public static HashMap<String,ArrayList<Tuple<String,String>>> globalUsage(Wiki wiki, Collection<String> titles)Gets the global usage of a file.- Parameters:
wiki
- The wiki object to usetitles
- The titles to query- Returns:
- A list of results keyed by title. The inner tuple is of the form (title, shorthand url notation).
-
resolveRedirects
Resolves title redirects on a Wiki.- Parameters:
wiki
- The Wiki to run the query againsttitles
- The titles to attempt resolving.- Returns:
- A HashMap where each key is the original title, and the value is the resolved title.
-
getDuplicatesOf
public static HashMap<String,ArrayList<String>> getDuplicatesOf(Wiki wiki, boolean localOnly, Collection<String> titles)Gets duplicates of a file.- Parameters:
wiki
- The wiki object to uselocalOnly
- Set to true if you only want to look for files in the local repository.titles
- The titles to query- Returns:
- A list of results keyed by title.
-
getSharedDuplicatesOf
public static HashMap<String,ArrayList<String>> getSharedDuplicatesOf(Wiki wiki, Collection<String> titles)Gets shared (non-local) duplicates of a file. PRECONDITION: The Wiki this query is run against has the GlobalUsage extension installed.- Parameters:
wiki
- The wiki object to usetitles
- The titles to query- Returns:
- A list of results keyed by title.
-
getTextExtracts
Gets a text extract (the lead paragraph) of a page.- Parameters:
wiki
- The Wiki object to use.titles
- The titles to get a text extract for.- Returns:
- A Map of results keyed by title. A null mapping means that the page doesn't exist or is not eligble for text extract.
-