Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
WIKI Reader WikiHUD  

WikiHUD

WikiHUD is a simple utility that reads p...

Category: WIKI Reader
By : Lillie Yifu
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for WikiHUD
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. WikiHUD_1.lsl
1 // wiki reader 1.05 Lillie Yifu
2 // http://sexsecond.blogspot.com
3 // chat on channel 4 the name of an article to get the top of the entry text
4 // permission is granted to distribute this script free and open source with the header attached
5
6
7 // adding second channel to listen for mode changes
8 // adding category mode
9
10 list wikis = ["wikia","lindenlab","caledon"];
11 list urls = ["http://secondlife.wikia.com","http://wiki.secondlife.com","http://caledonwiki.com"];
12 string help = "WikiHUD (Help)";
13 integer sources;
14 integer oldmode;
15 integer wiki = 0;
16
17 string oldbody = "";
18 float alpha = 1.;
19 string redirect = "#REDIRECT";
20 integer section ;
21 integer follow= 0;
22 integer redirlen;
23 string qname;
24 list meta = [HTTP_MIMETYPE,"text/plain;charset=utf-8"];
25 key hid;
26 string name;
27
28 key image = "f07b2853-6aa2-7819-cbde-a1bf4187091d";
29 vector large = <0.01,0.3,.3>;
30 vector small = <0.01,0.1,0.1>;
31 integer islarge =TRUE;
32 integer qmode = 0;//mode of query
33 integer oldqmode = 0;
34 integer mode = 0;//mode of command
35
36 list recent = [];
37 integer showrecent = FALSE;
38 integer recentlimit = 5;
39
40
41 string url;
42 integer modes;
43 //action=query & list=search & srsearch=wikipedia & srlimit=10
44 list modenames = ["summary","categories","word","full","source","wikis","help","recent"];
45 list phps = [
46 "/index.php?action=raw&title=",
47 "/api.php?format=xml&prop=categories&action=query&titles=",
48 "/api.php?format=xml&action=query&list=search&srlimit=20&srsearch=",
49 "/index.php?action=raw&title="
50 ];
51 //string url = "http://en.wikipedia.org/index.php?action=raw&title=";
52 integer achan = 4;
53 integer mchan = 5;
54
55 integer query(string article)
56 {
57 qmode = mode;
58 qname=url+llList2String(phps,qmode)+article;
59 name = qname +"§ion=0"; // section postpend
60 llOwnerSay(name+" "+ llList2String(modenames,mode));
61 hid = llHTTPRequest(name, meta, "");
62 recent = llList2String(wikis,wiki)+":"+llUnescapeURL(article)+llList2List(recent,0,recentlimit);
63 if(showrecent) {
64 llSetText(llDumpList2String(recent,"\n"),<1.,1.,1.>,alpha);
65 }
66 section =-1;
67 return 0;
68 }
69
70
71 string str_replace(string src, string from, string to)
72 {//replaces all occurrences of 'from' with 'to' in 'src'.
73 integer len = (~-(llStringLength(from)));
74 if(~len)
75 {
76 string buffer = src;
77 integer b_pos = -1;
78 integer to_len = (~-(llStringLength(to)));
79 @loop; //instead of a while loop, saves 5 bytes (and run faster).
80 integer to_pos = ~llSubStringIndex(buffer, from);
81 if(to_pos)
82 {
83 buffer = llGetSubString(src = llInsertString(llDeleteSubString(src, b_pos -= to_pos, b_pos + len), b_pos, to), (-~(b_pos += to_len)), 0x8000);
84 jump loop;
85 }
86 }
87 return src;
88 }
89
90 default
91 {
93 {
94 llSetText("",<1.,1.,1.>,alpha);
95 integer i = 0;
96 url = llList2String(urls,wiki);
97 sources = llGetListLength(wikis);
98 modes = llGetListLength(modenames);
100 llOwnerSay("Chat on channel "+(string) achan+" the name of an article to reference the Second Life Wiki.");
101 llOwnerSay("Chat on channel "+(string) mchan+" to change query mode.");
102 for(;i<modes;++i) {
103 llOwnerSay(llList2String(modenames, i));
104 }
105
106 llListen(achan,"",llGetOwner(),"");
107 llListen(mchan,"",llGetOwner(),"");
108 }
109
111 {
112 string article = str_replace(m," ","_");
113 article = llEscapeURL(article);
114
115
116 if(achan==c) {
117 if(0==mode|| 3==mode) {
118 query(article);
119
120 } else if(1==mode) {
121 name = url+llList2String(phps,mode)+article;
122 llOwnerSay(name+" "+ llList2String(modenames,mode));
123 hid = llHTTPRequest(name, meta, "");
124 qmode = mode;
125 } else if(2==mode) {// will need a loop here
126 name = url+llList2String(phps,mode)+article;
127 llOwnerSay(name+" "+ llList2String(modenames,mode));
128 hid = llHTTPRequest(name, meta, "");
129 qmode = mode;
130 }
131
132 } else if(mchan ==c) {
133
134 integer i =0;
135 oldmode = mode;
136 for(;i<modes;++i) {
137 if(llGetSubString(m,0,2) == llGetSubString(llList2String(modenames,i),0,2) ){
138 mode = i;
139 i=modes;
140 }
141 }// end look for mode
142 if(4 == mode) { // set source
143 list parse = llParseString2List(m,[" "],[]);
144 string newsource = llGetSubString(llList2String(parse,1),0,3);
145 for(i=0;i<sources;++i) { // I should sort and search...
146 if(llGetSubString(llList2String(wikis,i),0,3)==newsource) {
147 wiki = i;
148 url = llList2String(urls,wiki);
149 llOwnerSay("Setting source to " + url);
150 i=sources;
151 }
152 }
153 mode = oldmode; // set mode to default, we should never stay here.
154 } else if(5 ==mode) {
155 llOwnerSay("To change source chat /" + (string)mchan + " source <wiki name>");
156 for(i=0;i<sources;++i) {
157 llOwnerSay(llList2String(wikis,i) + "\t\t @ " + llList2String(urls,i));
158 }
159 mode = oldmode; // set mode back, we should never stay here
160 } else if(6==mode) {
161 llOwnerSay("Getting help...");
162 article = help;
163 article = llEscapeURL(article);
164 mode = 3;
165 query(article);
166 oldqmode = qmode;
167 qmode = 3;
168 hid = llHTTPRequest(help,meta,"");
169 mode = oldmode;
170 } else if(7==mode) {
171 if(showrecent){
172 llSetText("",<1,1,1>,1.);
173 showrecent = FALSE;
174 } else {
175 showrecent = TRUE;
176 llSetText(llDumpList2String(recent,"\n"),<1.,1.,1.>,alpha);
177 }
178
179 mode = oldmode;
180 } // end of mode processing
181 if(mode!= oldmode) {
182 llOwnerSay("Setting mode to "+llList2String(modenames,mode));
183 }
184 }// end channel 5
185 }
186
187
188
189
191 {
193 }
195 {
196 if(1==p) {
197 if(islarge) {
198 llSetScale(small);
199 islarge = FALSE;
200 alpha = .3;
201
202 } else {
203 llSetScale(large);
204 islarge = TRUE;
205 alpha=1.;
206 }
207 llSetAlpha(alpha,ALL_SIDES);
208 }
209 }
210
211 timer()
212 {
213 if(hid){
214 hid = NULL_KEY;
215 follow = 0;
216 llOwnerSay("Query timed out.");
217 }
219 }
220
221 http_response(key request_id, integer status, list metadata, string body)
222 {
223 if(0==qmode || 3==qmode) { // article or full
224 key image;
225 if(request_id == hid) {
226
227 image = (key)llGetSubString(body,5,40); // image key if available
229 follow = TRUE;
230 if(llSubStringIndex(body,redirect)!=0) { // no redirect
231
232 if( qmode == 0) { // if summary mode,
233 llOwnerSay(body);
234 return;
235 } else {
236 if(0 == section && llSubStringIndex(body,"=")!=0) {
237 llOwnerSay(llGetSubString(body,0,llSubStringIndex(body,"\n="))); //truncate at first line that starts with =
238 oldbody = body;
239 } else if( oldbody == body) {
240 body = "";
241 oldbody = "";
242 } else if(section >0) {
243 llOwnerSay(body);
244 oldbody = body;
245 }
246 }
247 if(body !="") {
248 ++section ; // increment section, will now be 0
249 name = qname + "&templates=expand§ion=" + (string) section; // query name
250 hid = llHTTPRequest(name, meta, "");
251 }
252 }
253
254
255
256 } else if(follow< 3) {// if redirect and less than 3 jumps
257
258 integer start = llSubStringIndex(body,"[[") + 2;
259 integer end = llSubStringIndex(body,"]]") -1;
260 string m = llGetSubString(body,start, end);
261 ++follow ;
262 llSetTimerEvent(180.);
263 name=url+str_replace(m," ","_");
264 list meta = [HTTP_MIMETYPE,"text/plain;charset=utf-8"];
265 hid = llHTTPRequest(name, meta, "");
266 } else {
267 hid = NULL_KEY;
268 follow=0;
269 llOwnerSay("Too many redirects");
270 }
271 } else if(1 == qmode) {// xml categories
272 list catraw = llParseString2List(body,["Category:"],[]);
273 integer i = 1;
274 string temp;
275 for(;i<llGetListLength(catraw);++i){
276 temp = llList2String(catraw,i);
277 llOwnerSay(llGetSubString(temp,0,llSubStringIndex(temp,"\"")-1));
278 }
279 } else if(2 == qmode) {
280 list catraw = llParseString2List(body,["title=\""],[]);
281 integer i = 1;
282 string temp;
283 for(;i<llGetListLength(catraw);++i){
284 temp = llList2String(catraw,i);
285 llOwnerSay(llGetSubString(temp,0,llSubStringIndex(temp,"\"")-1));
286 }
287 }
288 }
289
290 }

Back to the Best Free Tools in Second Life and OpenSim.