Bücher online kostenlos Kostenlos Online Lesen
Working With MediaWiki

Working With MediaWiki

Titel: Working With MediaWiki
Autoren: Yaron Koren
Vom Netzwerk:
SMW should be done with caution, since if the data being retrieved gets changed, the SMW representation of it won’t be updated until and unless it’s manually refreshed in the wiki in some way.
Displaying and storing a table of data
    If the data that was retrieved contains more one than row, i.e. it’s a table of data, displaying it is slightly more complicated. For that, we use the function #for_external_table, which takes in a string that holds one or more variables, and loop through the values for them, printing out the string for each row. For example, let’s say there’s a web page holding information on books and their authors in CSV format, and we want to display the entire set of information in a wiki page. We can accomplish that using the following two calls:
{{#get_web_data:url=http://example.com/books_data.csv |format=csv with header |data=book name=title,author=author}}
{{#for_external_table:The book ''{{{book name}}}'' was written by {{{author}}}. }}
    This will print out text in the form:
The book Shadow of Paradise was written by Vicente Aleixandre. The book The Family Moskat was written by Isaac Bashevis Singer. The book The Sovereign Sun was written by Odysseas Elytis.
    Within #for_external_table, each field is displayed by putting its name in triple curly brackets; #for_external_table then loops all the way through the arrays of these values from start to finish, printing out the string for each.
    Interestingly, there’s no reference in the #for_external_table call to the #get_web_data query that created the arrays of these two values — they could have even come from two different #get_web_data calls. In general, though, it’s assumed that a call to #for_external_table will handle the values retrieved from a single #get_web_data call, and that all the arrays will hold the same number of rows. If the two arrays are of different sizes — i.e. if there are more book rows than author rows, or vice versa — then you’ll probably get some strangely-formatted results.
    Chances are good that you wouldn’t want to print out a table of data as a long series of sentences — instead, you’ll probably want to display them as a table. That can be done via a minor hack. First, you’ll need to create the “!" template to hold a “|”, as described here . Then, you can have a call that looks like the following:
{| class="wikitable"
! Book
! Author {{#for_external_table:
{{!}}-
{{!}} {{{book name}}}
{{!}} {{{author}}}
|}
    This will print out the correct wikitext for a table, including header rows.
    There’s one other interesting feature of #for_external_table, which is that it lets you URL-encode specific values, by calling them with {{{field-name.urlencode}}} instead of just {{{field-name}}}. For instance, if you wanted to show links to Google searches on a set of terms retrieved, you could call:
{{#for_external_table: http://google.com/search?q={{{ term.urlencode}}} }}
    It’s also possible to store the table of data semantically, though it requires having the Semantic Internal Objects extension ( see here ) also installed, since table data is n-ary data. Instead of using #for_external_table, you would use a separate parser function, #store_external_table, which is defined within External Data but also requires Semantic Internal Objects to work. It functions like a cross between #for_external_table and SIO’s #set_internal. Here’s how a call for the previous set of data would look:
{{#store_external_table:Is book in list |Has title=book name |Has author=author}}
    If you’re familiar with #set_internal, this should look familiar. “Is book in list” is a property that points from each internal object to the main page, while “Has title” and “Has author” are additional properties for each internal object. A new internal object is created for each row of original data. Just as with #set_internal, #store_external_table doesn’t display anything to the screen; so to display the data, you would have to make another call — presumably either a call to #for_external_table or simply a query of the data, using #ask. In fact, this presents another way to display a table of data on the screen — instead of using #for_external_table and the table-display hack, you could use the #store_external_table call above and then call the following, on the same page:
{{#ask:[[Is book in list::{{PAGENAME}}]] |?Has title=Book |?Has author=Author |format=table}}
Secret keys and whitelists
    Some
Vom Netzwerk:

Weitere Kostenlose Bücher