Structured Data Plugin

data plugin by Andreas Gohr
Add and query structured data in your wiki

Last updated on 2010-01-25. Provides Syntax, Helper, Action.
Compatible with DokuWiki 2009-12-25+.

Conflicts with datapdo!
Similar to fields, pagemod.

Tagged with data, database, listing, sqlite, tables, tags.

This plugin allows you to add structured data to any DokuWiki page. Think about this data as additional named attributes. Those attributes can then be queried and aggregated. The plugin is similar to what was done here for the repository plugin but its internals are very different to the repository plugin.

This plugin requires the SQLite extension for PHP! (Should be included with PHP5).

Download and Installation

This plugin can be downloaded manually or through the Plugin Manager from the download link given above.

Changes

Plugin Syntax

This plugin depends on multiple parts, each having a similar syntax. The syntax defines a block with various key/value pairs configuring the behaviour of the plugin part.

Data Entry (Input)

This part is used to add structured data to a page. All data entered here is tied to the page. Let's start with an example:

---- dataentry ----
type            : web development
volume          : 1 Mrd    # how much do they pay?
employees       : Joe, Jane, Jim
customer_page   : customers:microsoft
deadline_dt     : 2009-08-17
server_pages    : servers:devel01, extern:microsoft
website_url     : http://www.microsoft.com
task_tags       : programming, coding, design, html
----

As you can see the block is defined by hyphens and the word dataentry. You may add additional words after the dataentry keyword. Those will be added as additional CSS classes in the final HTML output. You can use this for styling how different entry types should be displayed later.

You may use the # character to add comments to the block. Those will be ignored and will neither be displayed nor saved.

Inside the block you see column names and their values. There are a few rules for the column names:

  • Use any name you like
  • If the name ends with the s character, you may add multiple values separated by commas (like in the employees row)
  • Special types can be added to the name to have the output formatted accordingly. Use an underscore to separate identifier and type. The following types are available currently:
    • dt – a date in the form YYYY-MM-DD, formatted as simple text but the input is checked for correct format
    • page – the entry is treated as Wiki pagename and will be linked in output
    • title – like page, but an additional display title can be given separated by a pipe
    • nspage – like page, but the column name is treated as namespace for the link.
    • url – the value will be treated as external link
    • tag – the values are linked to a page named after the column name, using the value as control filter for a data table
    • mail – the value is checked to contain a valid email address, additional text is used as name that will be linked with the given email address
    • img<num> – the input is assumed to be a image URL or local media id. The optional <num> is the wanted width in pixels to resize the image to (defaults to 40)
    • when no type is given, it's just treated as simple string
  • When using a type, add the s for multi-values at the very end (like in the server_pages row)

Data Table (Output)

To aggregate the structured data attached to various pages in your wiki this syntax is used. It will display a configurable table with the data you want. The table can be sorted and filtered. Paging is supported as well. And just as with the dataentry, you may add additional words after the datatable keyword. Those will be added as additional CSS classes in the final HTML output.. Let's start with an example again:

---- datatable ----
cols    : %pageid%, employees, deadline_dt, volume
headers : Details, Assigned Employees, Deadline, $$$
max     : 10
filter  : type=web development
sort    : ^volume
----

The above config will display a table with all web development projects, the employees assigned to the project, the deadline and the volume. The table will be sorted by the volume and will display a maximum of 10 projects.

So the keyword before the colon is a configuration option and the value behind is the actual setting. To make it more fault tolerant often multiple option names are possible. Here is a list of all available options:

Option(s) Required? Description
cols
select
yes These are the attributes you want to display. These are the same names you used in the Data Entry part
title
titles
head
header
headers
no If specified, these names will be used in the table headers instead of the column names
max
limit
no How many rows should be displayed. If more rows are available the table will be made browsable. If not given all matching rows are shown
sort
order
no By what column should the table be sorted initially? Prepend a ^ to reverse the sorting
filter
where
filterand
and
no Filter by a column value. You may specify this more than once, multiple filters will be ANDed.
filteror
or
no Like filter, but multiple instances will be ORed

For filtering, multiple comparators are possible:

Comparator Meaning
= Exact match
!= or <> Does not exactly match
< Less than
<= Less or equal than
> Greater than
>= Greater or equal than
~ Wildcard match. Use a * as wildcard. Like Apple* to match Apple Pie and Apple Computer
!~ Negative Wildcard match. Select everything that does not match the expression.

You may use the special word %user% in a filter to make it match against the currently logged in user.

This syntax will disable all caching for the current page!

There are a few variables available to be used as field names:

Variable Meaning
%pageid% The whole pagename of a page
%title% The “title” of a page. This is the first headline of a page.

Data List (Output)

The datalist works like the datatable above and accepts the same parameters. But instead of displaying a table, an unordered list is shown. Each result row is one list item, all selected columns are joined with a space. The header parameter is completely ignored.

---- datalist ----
cols    : %pageid%, volume
max     : 10
filter  : type=web development
sort    : ^volume
----

Related Pages (Output)

This mode allows you to display a list of pages which are similar to the current page because they share some of the structured data. Which columns are used for similarity comparison has to be given in the cols option. Additional filters and sorting options can be set. Here is an example:

---- datarelated ----
cols  : task_tags, type
title : Similar projects
max   : 5
sort  : ^volume
----

The shown config will look for pages which share values in the columns task and type. A maximum of 5 pages is shown, sorted by volume.

So the keyword before the colon is a configuration option and the value behind is the actual setting. To make it more fault tolerant often multiple option names are possible. Here is a list of all available options:

Option(s) Required? Description
cols
select
yes These are the attributes used to compare similarity. These are the same names you used in the Data Entry part
title no This is description information above the list. Defaults to “Related pages”
max
limit
no How many matches should be shown at maximum
sort
order
no By what column should the list be sorted? Prepend a ^ to reverse the sorting. This is a secondary sort. The list is always sorted by relevancy first.
filter
where
filterand
and
no Filter by a column value. You may specify this more than once, multiple filters will be ANDed.
filteror
or
no Like filter, but multiple instances will be ORed

For filtering, multiple comparators are possible:

Comparator Meaning
= Exact match
!= or <> Does not exactly match
< Less than
<= Less or equal than
> Greater than
>= Greater or equal than
~ Wildcard match. Use a * as wildcard. Like Apple* to match Apple Pie and Apple Computer

This mode will not disable caching for the page, so the list might not always be up to date.

Tag Cloud (Control)

This syntax will display the values of a given data name as a tag cloud. Each value will link back to the current page (unless configured otherwise). The page should also contain a Data Table - this table will then be filtered for all entries matching the selected tag.

Example:

---- datacloud ----
field: employees
min: 2
limit: 20
----

The above code would display a cloud of employees assigned to at least two different projects. A maximum of the 20 most busiest employees are shown.

These are the possible options for the cloud:

Option(s) Required? Description
field
select
col
yes What attribute is used to build the cloud?
limit
max
no Maximum number of tags to display. If not given all will be displayed
min no Minimum count a tag must have. If not given all will be shown
page
target
no Give a page which contains the Data Table to control. If not given the current page is used

Customizing the Styling

Position and styling of input and output boxes can be done with simple CSS. Everything given after the syntax keyword will be assigned as additional class name to the surrounding div. Additionally are the field keys used as classes for the entry box items.

Let's assume the following “dataentry” box, as specified at the beginning of the page.

---- dataentry character24 ----
name            : Jack Bauer
agency_nspage   : CTU
status_tags     : alive, active, disowned, furtive
.... more info
----

You now can style this box with CSS in your conf/userstyle.css. Here is an example:

div.character24 {
  /* code for the container block, such as position, layout and borders, goes here */
  float: right;
  width: 33%;
}
 
div.character24 dl > dt { 
  /* this will allow you to style the definition terms */
  font-variant: small-caps;
}
 
div.character24 dl > dt + dd {
  /* this will allow you to style to the definition values */
  font-family: sans-serif;
}
 
div.character24 dl dd.name{
  /* this makes the name larger than the rest */
  font-size: 120%;
}

Missing Features

  • more control options:
    • labels instead of attribute names, when we want (in order to can have a beautiful display)
    • attribute list (similar to tag cloud but as a simple list)
    • search field
  • better documentation, examples
  • more data types?
    • an “addr” type to hold addresses or GPS coordinates to be displayed or linked with a Google map
  • links in aggregations and data entries don't generate backlinks

Examples

This plugin may be seen in action in the templates table on this wiki. See the source for that page and for some individual template page.

Question and Answers

How to refresh data?

The data that is copied to the SQLite database should be refreshed automatically whenever the page containing the dataentry box is changed.

However there might be some bugs making this not always 100% reliable. Refer to the open bugs section and changes to see what might be broken or what was recently fixed.

When you delete the whole database, all entry pages have to be re-rendered to repopulate the database. There is no automatic way to do so.

You can of course open the database file directly in the SQLite command line client and manipulate it through SQL queries.

Multiple Data Entry Boxes on one Page?

You can not have multiple data entry boxes on the same page, at least not with the same structure.

The page id is used as the primary key to identify a set of data. There would be no difference between the data in multiple boxes (from a database point of view). The later data will just overwrite the earlier mentioned data.

Which SQLite for my PHP?

Your Linux distribution might distribute the SQLite PHP extension in a package separate from the PHP package. E.g. a Debian System lists the following available packages: php-sqlite, php-sqlite3, php5-sqlite, php5-sqlite3 – if you are running the php5 package for PHP then you should install the php5-sqlite package.

Other Questions

If you still have questions, search the forum and if it hasn't been asked before ask your question there.

Bugs, Feature Requests and Patches

Please submit bugs and feature requests in the issue tracker linked at the top. Patches should be sent unified diff format or as git patches against the devel branch. Or even better: fork the repository at github and send a merge request.

 
plugin/data.txt · Last modified: 2010/03/09 10:57 by 91.64.125.163
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate