1 /** 2 * ==================================================================== 3 * About Sarissa: http://dev.abiss.gr/sarissa 4 * ==================================================================== 5 * Sarissa cross browser XML library - IE XPath Emulation 6 * @version 0.9.9.4 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 this.format + 59 "&prop=revisions&rvprop=content&titles=" + 60 encodeURIComponent(sFor), 61 callback); 62 }; 63 64 /** 65 * Asynchronously obtain an article's backlinks from the Wiki, then pass those to the given 66 * callback function as JSON data. This method does any required URL encoding for you. 67 * @param {String} sFor the article name 68 * @param {int} iLimit the maximum number of results to retreive 69 * @param {Function} callback the callback function to use 70 */ 71 SarissaMediaWikiContext.prototype.doBacklinksGet = function(sFor, iLimit, callback){ 72 Sarissa.setRemoteJsonCallback( 73 this.baseUrl + 74 "?&generator=backlinks&format=" + 75 this.format + 76 "&gbllimit=" + 77 iLimit + 78 "&gbltitle" + 79 encodeURIComponent(sFor), 80 callback); 81 }; 82 83 /** 84 * Asynchronously perform a Wiki Search, passing the results to the given 85 * callback function as JSON data. This method does any required URL encoding for you. 86 * @param {String} sFor the terms to look for 87 * @param {int} iLimit the maximum number of results to retreive 88 * @param {Function} callback the callback function to use 89 */ 90 SarissaMediaWikiContext.prototype.doSearch = function(sFor, iLimit, callback){ 91 Sarissa.setRemoteJsonCallback( 92 this.baseUrl + 93 "?action=query&list=search&srsearch=" + 94 encodeURIComponent(sFor) + 95 "&srwhat=text&srnamespace=0&format=" + 96 this.format + 97 "&srlimit=" + 98 iLimit, 99 callback); 100 }; 101 102 /** 103 * Asynchronously obtain the articles belonging to a category from the Wiki, 104 * then pass those to the given callback function as JSON data. This method 105 * does any required URL encoding for you. 106 * @param {String} sFor the article name 107 * @param {int} iLimit the maximum number of results to retreive 108 * @param {Function} callback the callback function to use 109 */ 110 SarissaMediaWikiContext.prototype.doCategorySearch = function(sFor, iLimit, callback){ 111 Sarissa.setRemoteJsonCallback( 112 this.baseUrl + 113 "?format=" + 114 this.format + 115 "&list=categorymembers&action=query&cmlimit=" + 116 iLimit + 117 "&cmtitle=Category:" + 118 encodeURIComponent(sFor), 119 callback); 120 }; 121 /** 122 * Asynchronously obtain the Wiki categories an article belongs to, 123 * then pass those to the given callback function as JSON data. This method 124 * does any required URL encoding for you. 125 * @param {String} sFor the article name 126 * @param {int} iLimit the maximum number of results to retreive 127 * @param {Function} callback the callback function to use 128 */ 129 SarissaMediaWikiContext.prototype.doArticleCategoriesGet = function(sFor, iLimit, callback){ 130 Sarissa.setRemoteJsonCallback( 131 this.baseUrl + 132 "?format=" + 133 this.format + 134 "&action=query&prop=categories&titles=" + 135 encodeURIComponent(sFor), 136 callback); 137 }; 138 139 140 141