Midgard's new tagging library

I’m spending some time this week on a specification workshop in the countryside. Mostly we’re looking at integration points between Midgard, Gforge and Doxygen to provide a complete open source project collaboration environment.

However, as a side result Midgard also has now a new tagging library: net.nemein.tag. This library is aimed at centralizing how tags are handled in various MidCOM components.

Adding tagging interface is as simple as including the following into a Datamanager 2 schema:

'tags' => Array
(
    'title' => 'tags',
    'type' => 'tags',
    'widget' => 'text',
),

Tags may be entered into this field, separated by spaces. In addition to regular simple tags, like midgard, the tagging library also supports multi-word tags surrounded by quotes, like "This is a long tag".

Another feature with tags in the concept of contexts. Context is something that describes the tag you apply. For example, if you are tagging a wiki page that describes a new feature in Midgard 1.8, you might tag it as "new-feature:Midgard 1.8". This way the site builder knows more about the relation and can display it differently.

Displaying tags is reasonably easy. For example, Midgard Wiki displays tags on a page in the following way:

// List tags used in this wiki page    
$tags_by_context = net_nemein_tag_handler::get_object_tags_by_contexts($request_data['wikipage']);
if (count($tags_by_context) > 0)
{
    echo "<dl class=\"tags\">\n";
    foreach ($tags_by_context as $context => $tags)
    {
        if (!$context)
        {
            $context = $_MIDCOM->i18n->get_string('tagged', 'net.nemein.tag');
        }
        echo "    <dt>{$context}</dt>\n";
        foreach ($tags as $tag => $url)
        {
            echo "        <dd class=\"tag\">{$tag}</dd>\n";
        }
    }
    echo "</dl>\n";
}

Read more Midgard posts.