1 /**
  2  * ====================================================================
  3  * About Sarissa: http://dev.abiss.gr/sarissa
  4  * ====================================================================
  5  * Sarissa cross browser XML library - IE XPath Emulation 
  6  * @version ${project.version}
  7  * @author: Copyright 2004-2008 Emmanouil Batsis, mailto: mbatsis at users full stop sourceforge full stop net
  8  *
  9  * This script depends on sarissa.js and provides an API for remote MediaWiki
 10  * JSON API calls.
 11  * 
 12  * @author: Copyright 2003-2008 Emmanouil Batsis, mailto: mbatsis at users full stop sourceforge full stop net
 13  * ====================================================================
 14  * Licence
 15  * ====================================================================
 16  * Sarissa is free software distributed under the GNU GPL version 2 (see <a href="gpl.txt">gpl.txt</a>) or higher, 
 17  * GNU LGPL version 2.1 (see <a href="lgpl.txt">lgpl.txt</a>) or higher and Apache Software License 2.0 or higher 
 18  * (see <a href="asl.txt">asl.txt</a>). This means you can choose one of the three and use that if you like. If 
 19  * you make modifications under the ASL, i would appreciate it if you submitted those.
 20  * In case your copy of Sarissa does not include the license texts, you may find
 21  * them online in various formats at <a href="http://www.gnu.org">http://www.gnu.org</a> and 
 22  * <a href="http://www.apache.org">http://www.apache.org</a>.
 23  *
 24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 
 25  * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
 26  * WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE 
 27  * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 
 28  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
 30  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
 31  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 32  */
 33 
 34 /**
 35  * Class that can be used to perform queries against a MediaWiki instance 
 36  * @constructor
 37  * @requires Sarissa
 38  * @param {String} apiUrl the base API URL, e.g. <a href="http://en.wikipedia.org/w/api.php" title="Link to Wikipedia's MediaWiki API Instance">http://en.wikipedia.org/w/api.php</a>
 39  * @param {Function} callback the callback function to use
 40  */ 
 41 function SarissaMediaWikiContext(apiUrl, arrLanguages){
 42 	this.baseUrl = apiUrl;
 43 	this.format = "json";
 44 	this.languages = arrLanguages;
 45 };
 46 
 47 
 48 /**
 49  * Asynchronously obtain an article from the Wiki, then pass it to the given 
 50  * callback function as JSON data. This method does any required URL encoding for you.
 51  * @param {String} sFor the article name
 52  * @param {int} iLimit the maximum number of results to retreive
 53  */ 
 54 SarissaMediaWikiContext.prototype.doArticleGet = function(sFor, callback){
 55 	Sarissa.setRemoteJsonCallback(
 56 		this.baseUrl + 
 57 			//"?action=query&redirects&format=" + 
 58 			"?action=parse&redirects&format=" +
 59 			this.format + 
 60 			"&page" + 
 61 			encodeURIComponent(sFor), 
 62 		callback);
 63 };
 64 
 65 /**
 66  * Asynchronously obtain an article's backlinks from the Wiki, then pass those to the given 
 67  * callback function as JSON data. This method does any required URL encoding for you.
 68  * @param {String} sFor the article name
 69  * @param {int} iLimit the maximum number of results to retreive
 70  * @param {Function} callback the callback function to use
 71  */ 
 72 SarissaMediaWikiContext.prototype.doBacklinksGet = function(sFor, iLimit, callback){
 73 	Sarissa.setRemoteJsonCallback(
 74 		this.baseUrl + 
 75 			"?&generator=backlinks&format=" + 
 76 			this.format + 
 77 			"&gbllimit=" + 
 78 			iLimit + 
 79 			"&gbltitle" + 
 80 			encodeURIComponent(sFor), 
 81 		callback);
 82 };
 83 
 84 /**
 85  * Asynchronously perform a Wiki Search, passing the results to the given 
 86  * callback function as JSON data. This method does any required URL encoding for you.
 87  * @param {String} sFor the terms to look for
 88  * @param {int} iLimit the maximum number of results to retreive
 89  * @param {Function} callback the callback function to use
 90  */ 
 91 SarissaMediaWikiContext.prototype.doSearch = function(sFor, iLimit, callback){
 92 	Sarissa.setRemoteJsonCallback(
 93 		this.baseUrl + 
 94 			"?action=query&list=search&srsearch=" + 
 95 			encodeURIComponent(sFor) + 
 96 			"&srwhat=text&srnamespace=0&format=" +
 97 			this.format + 
 98 			"&srlimit=" + 
 99 			iLimit, 
100 		callback);
101 };
102 
103 /**
104  * Asynchronously obtain the articles belonging to a category from the Wiki, 
105  * then pass those to the given callback function as JSON data. This method 
106  * does any required URL encoding for you.
107  * @param {String} sFor the article name
108  * @param {int} iLimit the maximum number of results to retreive
109  * @param {Function} callback the callback function to use
110  */ 
111 SarissaMediaWikiContext.prototype.doCategorySearch = function(sFor, iLimit, callback){
112 	Sarissa.setRemoteJsonCallback(
113 		this.baseUrl + 
114 			"?format=" + 
115 			this.format + 
116 			"&list=categorymembers&action=query&cmlimit=" + 
117 			iLimit + 
118 			"&cmtitle=Category:" + 
119 			encodeURIComponent(sFor), 
120 		callback);
121 };
122 /**
123  * Asynchronously obtain the Wiki categories an article belongs to, 
124  * then pass those to the given callback function as JSON data. This method 
125  * does any required URL encoding for you.
126  * @param {String} sFor the article name
127  * @param {int} iLimit the maximum number of results to retreive
128  * @param {Function} callback the callback function to use
129  */ 
130 SarissaMediaWikiContext.prototype.doArticleCategoriesGet = function(sFor, iLimit, callback){
131 	Sarissa.setRemoteJsonCallback(
132 		this.baseUrl + 
133 			"?format=" + 
134 			this.format + 
135 			"&action=query&prop=categories&titles=" + 
136 			encodeURIComponent(sFor), 
137 		callback);
138 };
139 
140 
141 
142