1
dojo.provide("dojox.data.WikipediaStore");
3
dojo.require("dojo.io.script");
4
dojo.require("dojox.rpc.Service");
5
dojo.require("dojox.data.ServiceStore");
7
dojo.experimental("dojox.data.WikipediaStore");
9
dojo.declare("dojox.data.WikipediaStore", dojox.data.ServiceStore,{
11
// Initializer for the Wikipedia data store interface.
13
// The WikipediaStore is a data store interface to Wikipedia, using the
14
// Wikipedia SMD spec from dojox.rpc. It currently is useful only for
15
// finding articles that contain some particular text or grabbing single
16
// articles by full name; no wildcards or other filtering are supported.
18
// | var store = new dojox.data.WikipediaStore();
20
// | query: {title:"Dojo Toolkit"},
21
// | onItem: function(item){
22
// | dojo.byId("somediv").innerHTML = item.text["*"];
25
constructor: function(options){
26
if(options && options.service){
27
this.service = options.service;
29
var svc = new dojox.rpc.Service(dojo.moduleUrl("dojox.rpc.SMDLibrary", "wikipedia.smd"));
30
this.service = svc.query;
33
this.idAttribute = this.labelAttribute = "title";
36
fetch: function(/* object */ request){
38
// Fetch a page or some partially-loaded search results from
39
// Wikipedia. Note that there isn't a way to sort data coming
40
// in from the API, so we just ignore the *sort* parameter.
44
// | query: {title:"Dojo Toolkit"},
45
// | // define your handlers here
48
// Searching for pages containing "dojo":
54
// | // define your handlers here
57
// Searching for the next 50 pages containing "dojo":
63
// | count: 50 // max 500; will be capped if necessary
65
// | // define your handlers here
67
var rq = dojo.mixin({}, request.query);
68
if(rq && (!rq.action || rq.action === "parse")){
69
// default to a single page fetch
74
}else if(rq.action === "query"){
75
// perform a full text search on page content
78
rq.srsearch = rq.text;
80
rq.sroffset = request.start-1;
83
rq.srlimit = request.count >= 500 ? 500 : request.count;
88
return this.inherited(arguments);
91
_processResults: function(results, def){
93
// loading a complete page
94
results.parse.title = dojo.queryToObject(def.ioArgs.url.split("?")[1]).page;
95
results = [results.parse];
97
}else if(results.query && results.query.search){
98
// loading some search results; all we have here is page titles,
99
// so we mark our items as incomplete
100
results = results.query.search;
101
var _thisStore = this;
102
for(var i in results){
103
results[i]._loadObject = function(callback){
105
query: { action:"parse", title:this.title },
108
delete this._loadObject;
112
return this.inherited(arguments);