Bücher online kostenlos Kostenlos Online Lesen
Working With MediaWiki

Working With MediaWiki

Titel: Working With MediaWiki
Autoren: Yaron Koren
Vom Netzwerk:
grouping results by the values for a field.
    Once the data is retrieved, it can be displayed and stored using #external_value, or, if the data is an array, using #for_external_table and #store_external_table — once the data is set to local variables, it’s indistinguishable from data retrieved by #get_web_data.
Getting data from an LDAP server
    You can also get data from an LDAP server, if your organization has one, in a similar manner to how data is extracted from databases. As with getting data from a database, you first need to set the connection details in LocalSettings.php, then query the data using #get_ldap_data. We won’t get into the details here, since it’s a less frequently-used feature, but you can see the full syntax and examples on the External Data homepage.
    As you would expect, though, #external_value, #for_external_table and #store_external_table can then all be called on the local values that have been set as a result.
Accessing offline data
    What about offline data — data that’s not available via the network, or perhaps is not even on a computer? The External Data extension doesn’t have any special power to bend the laws of physics, but it does offer a utility that makes it possible to put such data online with a minimum of fuss: the page “Special:GetData”. To use it, you first need to get this data into CSV format, i.e. rows of comma-separated values, with a single header row defining the name of each "column". This may or may not be a challenge, depending on the nature of the data and what form it’s currently in, but CSV is, at the very least, a data format that’s easy to create.
    Once the CSV is created, it should be put into a page in the wiki — any name will work for the page. As an example, you could have a collection of information about a company’s employees, and put it into a wiki page called ’Employee CSV data’. The page’s contents might look like this:

This page holds information about Acme Corp’s employees.

Employee name,Department,Position,Phone Number
Alice Adams,Accounting,Accountant,5-1234
Bob Benson,Sales,IT administrator,5-2345
...

    The “” and “” tags are optional — they let you set a nice explanatory display when users view the page. If those tags aren’t included, the entire page will be parsed as CSV, while if they are included, the “” sections will get ignored.
    The page Special:GetData then serves as a wrapper around that data, providing a sort of “mini-API” for accessing its content. A typical URL for ’GetData’ would look like this:
http://example.com/wiki/Special:GetData/Employee_CSV_data?Employee %20name=Alice%20Adams
    The name of the page with the CSV data is placed after "Special:GetData", with a slash between them. Then, in the URL’s query string (i.e., after the ’?’), values can be set for different column names to filter down the set of values. In this case, Special:GetData will return all the rows of the page ’Employee CSV data’ that have a value of ’Alice Adams’ for the column named ’Employee name’.
    That URL can then be passed in to a call to #get_web_data, just like any other API URL. Note that if you’re using #get_web_data to query a ’GetData’ page, you can apply filtering in either place: either within the API, or as a #get_web_data filter. Barring any reason to use one versus the other, it’s recommended to do the filtering within the URL itself, since that’s slightly faster.
Caching data
    You can configure External Data to cache the data contained in the URLs that it accesses, both to speed up retrieval of values and to reduce the load on the system whose data is being accessed. To do this, run the SQL contained in the extension file “ExternalData.sql” in your database, which will create the table “ed_url_cache”, then add the following to your LocalSettings.php file, after the inclusion of External Data:
$edgCacheTable = 'ed_url_cache';
    You should also add a line like the following, to set the expiration time of the cache, in seconds; this example line will cache the data for a week:
$edgCacheExpireTime = 7 * 24 * 60 * 60;

Widgets
    A wiki doesn’t usually consist of text alone, and often it’s helpful to embed outside media into the pages. MediaWiki itself doesn’t allow for embedding HTML and JavaScript within pages, though, which means that audio and video players, and other
Vom Netzwerk:

Weitere Kostenlose Bücher