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_148_dj  

WikiHUD_148_dj

WikiHUD_148_dj

Category: WIKI Reader
By : dgrovesjr
Created: 2011-08-22 Edited: 2011-08-22
Worlds: Second Life

the Zip file

Download all files for WikiHUD_148_dj
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. WikiHUD_148_dj_1.lsl
1 // Author: Lillie Yifu
2 //WikiHUD is a simple utility that reads pages from a wiki into Second Life.
3
4 // Downloaded from : http://www.free-lsl-scripts.com/freescripts.plx?ID=1324
5
6 // This program is free software; you can redistribute it and/or modify it.
7 // License information must be included in any script you give out or use.
8 // This script is licensed under the Creative Commons Attribution-Share Alike 3.0 License
9 // from http://creativecommons.org/licenses/by-sa/3.0 unless licenses are
10 // included in the script or comments by the original author,in which case
11 // the authors license must be followed.
12
13 // Please leave any authors credits intact in any script you use or publish.
14 ////////////////////////////////////////////////////////////////////
15 // wiki reader 1.05 Lillie Yifu
16 // http://sexsecond.blogspot.com
17 // chat on channel 4 the name of an article to get the top of the entry text
18 // permission is granted to distribute this script free and open source with the header attached
19
20 // adding second channel to listen for mode changes
21 // adding category mode
22
23 // Heavey modified(rewritten) by Donjr Spiegeblatt
24
25 // configuration variables
26 float TIMEOUT = 30.; // Http_request call timeout (note: the limit is about 59 seconds)
27
28 integer achan = 4; // query channel
29 integer mchan = 5; // command channel
30
31 integer ShortWikiLength = 3; // +1 equals number of characters that must match a wikis name
32 integer ShortLength = 2; // +1 equals number of characters that must match a command
33
34 string wiki = ""; // default to the first wiki entry in the urls table
35
36 key image = "f07b2853-6aa2-7819-cbde-a1bf4187091d";
37 vector large = <0.01,0.3,.3>;
38 vector small = <0.01,0.1,0.1>;
39 float alpha = 1.; // greater then .5 use LARGE else Small as the default
40
41 integer showrecent = FALSE; // default to not showing recent
42 integer recentlimit = 5; // maxim number of recent entries to keep (display)
43
44 // wiki names and there matching urls
45 list urls = [
46 "wikia", "http://secondlife.wikia.com",
47 "lindenlab","http://wiki.secondlife.com",
48 "caledon","http://caledonwiki.com"
49 ];
50 // end of configuration settings
51
52 // All working code from here on
53 string url; // gets set to matching url for that entry for "wiki"
54 list shortwikis = []; // filled in state_entry
55 string help = "WikiHUD (Help)";
56 list recent = [];
57
58 //action=query & list=search & srsearch=wikipedia & srlimit=10
59 string ModeSummary = "summary";
60 string ModeCategories = "categories";
61 string ModeWord = "word";
62 string ModeFull = "full";
63 string ModeSource = "source";
64 string ModeWikis = "wikis";
65 string ModeHelp = "help";
66 string ModeRecent = "recent";
67 list modenames = [ModeSummary,ModeCategories,ModeWord,ModeFull,ModeSource,ModeWikis,ModeHelp,ModeRecent];
68 list shortnames = []; // filled in state_entry
69
70 string mode; // current command mode
71
72 list phps = [
73 ModeSummary, "/index.php?action=raw&title=", // Summary
74 ModeCategories, "/api.php?format=xml&prop=categories&action=query&titles=", // Categories
75 ModeWord, "/api.php?format=xml&action=query&list=search&srlimit=20&srsearch=", // Word
76 ModeFull, "/index.php?action=raw&title=", // Full
77 ModeHelp, "/index.php?action=raw&title=" // Help
78 ];
79
80 list meta = [HTTP_MIMETYPE,"text/plain;charset=utf-8"]; // note [] would yeild the same default values
81 key hid;
82 // used for commication btween query() with the http_response() and timer() events.
83 string oldbody = "";
84 integer section = 0;
85 integer follow= 0;
86
87 string qmode; //mode of query
88 string qname;
89 query(string article, string mode)
90 {
91 qmode = mode;
92 qname=url+llList2String(phps,llListFindList(phps,[mode])+1)+llEscapeURL(article);
93 string name = qname;
94 if( ModeSummary==mode || ModeFull==mode )
95 {
96 name += "§ion=0"; // section postpend
97 recent = [wiki+":"+article]+llList2List(recent,0,recentlimit);
98 if(showrecent)
99 llSetText(llDumpList2String(recent,"\n"),<1.,1.,1.>,alpha);
100 }
101 llOwnerSay(qmode+":"+wiki+":"+article);
102 // llOwnerSay(qname+" "+ mode); // debug version
103 hid = llHTTPRequest(name, meta, "");
104 // reset local state variables
105 section = 0;
106 follow = 0;
107 oldbody = "";
108 llSetTimerEvent(TIMEOUT);
109 }
110
111 string str_replace(string src, string from, string to)
112 {
113 //replaces all occurrences of 'from' with 'to' in 'src'.
114 integer len = (~-(llStringLength(from)));
115 if(~len)
116 {
117 string buffer = src;
118 integer b_pos = -1;
119 integer to_len = (~-(llStringLength(to)));
120
121 @loop; //instead of a while loop, saves 5 bytes (and run faster).
122 integer to_pos = ~llSubStringIndex(buffer, from);
123 if(to_pos)
124 {
125 buffer = llGetSubString(src = llInsertString(llDeleteSubString(src, b_pos -= to_pos, b_pos + len), b_pos, to), (-~(b_pos += to_len)), 0x8000);
126 jump loop;
127 }
128 }
129 return src;
130 }
131
132 ToggleScale()
133 {
134 vector cur = small;
135 if(alpha > 0.5)
136 alpha = .3;
137 else
138 {
139 cur = large;
140 alpha = 1.;
141 }
142 llSetScale(cur);
143 llSetAlpha(alpha,ALL_SIDES);
144 }
145
146 default
147 {
148 on_rez(integer xxx)
149 {
151 }
152
154 {
155 // reverse alpha setting to toggle scale and alpha to the right settings
156 if( alpha > 0.5 )
157 alpha = 0.1;
158 else
159 alpha = 1.;
160 ToggleScale();
161 llSetText("",<1.,1.,1.>,alpha);
163
164 integer i;
165 // build shor wiki name table
166 integer len = llGetListLength(urls);
167 shortwikis = [];
168 for(i=0; i < len; i+=2)
169 shortwikis += llGetSubString(llList2String(urls,i),0,ShortWikiLength);
170 i = llListFindList(shortwikis, [llGetSubString(wiki,0,ShortWikiLength)]);
171 if(i < 0)
172 i = 0;
173 i *= 2;
174 wiki = llList2String(urls,i); // set wiki to full matching value
175 url = llList2String(urls,i+1); // set url to matching value
176
177 llOwnerSay("Chat on channel "+(string)achan+" the name of an article to reference the Second Life Wiki.");
178 llOwnerSay("Chat on channel "+(string)mchan+" to change query mode.");
179
180 // build short command names table (and display startup help)
181 len = llGetListLength(modenames);
182 shortnames = [];
183 for(i=0;i<len;i++)
184 {
185 string m = llList2String(modenames, i);
186 shortnames += llGetSubString(m,0,ShortLength);
187 llOwnerSay(m);
188 }
189 mode = ModeSummary; // set to default mode "summary"
190
191 llListen(achan,"",llGetOwner(),"");
192 llListen(mchan,"",llGetOwner(),"");
193 }
194
196 {
197 if(achan == c)
198 query(str_replace(m," ","_"), mode);
199 else if(mchan == c)
200 {
201 // defaults to tmode = mode when no match found
202 string tmode = llList2String([mode]+modenames, llListFindList(shortnames,[llGetSubString(m,0,ShortLength)])+1);
203 // end of look for mode
204
205 if(ModeSource == tmode)
206 {
207 // set source
208 string newsource = llGetSubString(llList2String(llParseString2List(m,[" "],[]),1),0,ShortWikiLength);
209 integer i = llListFindList(shortwikis,[newsource]);
210 if( i > -1 )
211 {
212 i *= 2;
213 wiki = llList2String(urls,i);
214 url = llList2String(urls,i+1);
215 llOwnerSay("Setting source to " + url);
216 }
217 }
218 else if(ModeWikis == tmode)
219 {
220 llOwnerSay("To change source chat /" + (string)mchan + " source <wiki name>");
221 integer i;
222 integer len = llGetListLength(urls);
223 for(i=0;i<len;i+=2)
224 llOwnerSay(llList2String(urls,i) + "\t\t @ " + llList2String(urls,i+1));
225 }
226 else if(ModeHelp == tmode)
227 {
228 llOwnerSay("Requesting help...");
229 query(help, ModeHelp);
230 }
231 else if(ModeRecent == tmode)
232 {
233 string text = "";
234 if(!showrecent)
235 text = llDumpList2String(recent,"\n");
236 llSetText(text,<1,1,1>,1.);
237 showrecent = (!showrecent);
238 }
239 else if(tmode != mode)
240 {
241 mode = tmode;
242 llOwnerSay("Setting mode to "+mode);
243 }
244 }// end channel 5
245 }
246
248 {
249 if(1==p && llDetectedKey(0) == llGetOwner())
250 ToggleScale();
251 }
252
253 timer()
254 {
255 follow = 0;
256 if( qmode == ModeHelp )
257 {
258 llOwnerSay(help+" timed out.");
259 qmode = ModeFull;
260 hid = llHTTPRequest(help,meta,"");
261 }
262 else
263 {
264 hid = NULL_KEY;
265 llOwnerSay("Query timed out.");
267 }
268 }
269
270 http_response(key request_id, integer status, list metadata, string body)
271 {
272 if(request_id == hid)
273 {
274 hid = NULL_KEY;
276 if(ModeSummary==qmode || ModeFull==qmode || ModeHelp == qmode)
277 {
278 // article or full
279
280 // junk
281 // image = (key)llGetSubString(body,5,40); // image key if available
282 // llSetTexture(image,ALL_SIDES);
283
284 if(llSubStringIndex(body,"#REDIRECT")!=0)
285 {
286 // no redirect
287 if( ModeSummary == qmode)
288 {
289 // if summary mode,
290 llOwnerSay(body);
291 }
292 else if( oldbody != body)
293 {
294 oldbody = body;
295 // if(0 == section && llSubStringIndex(body,"=")!=0)
296 llOwnerSay(llGetSubString(body,0,llSubStringIndex(body,"\n="))); //truncate at first line that starts with =
297 // else // if(section >0)
298 // llOwnerSay(body);
299 if(body != "")
300 {
301 ++section ; // increment section, will now be greater then 0
302 hid = llHTTPRequest(qname + "&templates=expand§ion=" + (string)section, meta, ""); // query name more
303 llSetTimerEvent(TIMEOUT);
304 }
305 }
306 }
307 else if(follow< 3)
308 {
309 // if redirect and less than 3 jumps
310 integer start = llSubStringIndex(body,"[[") + 2;
311 integer end = llSubStringIndex(body,"]]") -1;
312 ++follow;
313 llSetTimerEvent(TIMEOUT);
314 string name = url+str_replace(llGetSubString(body,start, end)," ","_");
315 // llOwnerSay("Redirecting to: "+name);
316 hid = llHTTPRequest(name, meta, "");
317 }
318 else
319 llOwnerSay("Too many redirects");
320 }
321 else if(ModeCategories == qmode || ModeWord == qmode)
322 {
323 string temp = "Category:";
324 if( ModeWord == qmode)
325 temp = "title=\"";
326 // xml categories or titles
327 list catraw = llParseString2List(body,[temp],[]);
328 while(catraw != [])
329 {
330 temp = llList2String(catraw,0);
331 catraw = llDeleteSubList(catraw, 0, 0);
332 llOwnerSay(llGetSubString(temp,0,llSubStringIndex(temp,"\"")-1));
333 }
334 }
335 }
336 }
337 }

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