Extension:RDFa Breadcrumbs

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
RDFa Breadcrumbs

Release status: unknown

Implementation User interface
Description Allows users to include breadcrumbs on pages with will get RDFa markup
Author(s) Hendrik Brummermann
Last version 1.0 (2010-09-18)
License CC-BY
Download No link
Check usage and version matrix

RDFa Breadcrumbs allows users to include breadcrumbs on pages which will get RDFa markup. It does not depend on categories but allows the definition on the individual pages.

Usage:

{{#breadcrumbs:
   [[Main Page]]
   | [[Manual:Extensions|Extensions]]
   | [[Extension:RDFa Breadcrumbs|RDFa Breadcrumbs]]
   | ... }}

This will look like this:

Main Page > Extensions > RDFa Breadcrumbs

In addition it will include RDFa markup so that Google will recognize it as Breadcrumb.

Installation [edit]

  1. Create a new file rdfa-breadcrumbs.php in your extensions folder and copy the following script into it.
  2. Add
    require_once("$IP/extensions/rdfa-breadcrumbs.php");
    
    into your LocalSettings.php
  3. Edit [[MediaWiki:common.css]] and add the following section at the end:


.breadcrumbs {
   clear: both;
   border:1px solid #AAAAAA;
   background-color:#F9F9F9;
   padding:5px;
}

Download [edit]

<?php
 
// License: CC-BY 2010 Hendrik Brummermann <nhb_web@nexgo.de>
 
 
$wgHooks['ParserFirstCallInit'][] = 'efRDFaBreadcrumbs_Setup';
$wgHooks['LanguageGetMagic'][]       = 'efRDFaBreadcrumbs_Magic';
 
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'RDFa_Breadcrumbs',
        'version' => '1.0',
        'url' => 'http://www.mediawiki.org/wiki/Extension:RDFa_Breadcrumbs',
        'author' => 'Hendrik Brummermann',
        'description' => 'Breadcrumbs with RDFa markup',
);
 
 
function efRDFaBreadcrumbs_Setup( &$parser ) {
        $parser->setFunctionHook('breadcrumbs', 'RDFaBreadcrumbs_Render' );
        return true;
}
 
function efRDFaBreadcrumbs_Magic( &$magicWords, $langCode ) {
        $magicWords['breadcrumbs'] = array( 0, 'breadcrumbs' );
        return true;
}
 
function RDFaBreadcrumbs_Render($parser) {
        $output = '<div class="breadcrumbs" xmlns:v="http://rdf.data-vocabulary.org/#">';
        for ($i = 1; $i < func_num_args(); $i++) {
                if ($i > 1) {
                        $output .= ' &gt; ';
                }
                $output .= '<span typeof="v:Breadcrumb">';
                $item = trim(func_get_arg($i));
                $output .= '<a href="'.htmlspecialchars(getURLFromLink($item))
                        .'" rel="v:url" property="v:title">';
                $output .= htmlspecialchars(getTextFromLink($item));
                $output .= '</a></span>';
        }
        $output = $output . '</div>';
        return array($output, 'noparse' => true, 'isHTML' => true);
}
 
function getURLFromLink($link) {
        global $wgArticlePath;
        if (strpos($link, '[[') === 0) {
                // internal link
                $delimiter = '|';
                $start = 2;
                $pos2 = strpos($link, $delimiter);
                if ($pos2 === FALSE) {
                        $pos2 = strlen($link) - 2;
                }
                $url = substr($link, $start, $pos2 - $start);
                return trim(preg_replace('/\$1/', urlencode(preg_replace('/[ +]/', '_', trim($url))), $wgArticlePath));
        } else if (strpos($link, '[') === 0) {
                // external link
                $delimiter = ' ';
                $start = 1;
                $pos2 = strpos($link, $delimiter);
                if ($pos2 === FALSE) {
                        $pos2 = strlen($link) - 1;
                }
                $url = substr($link, $start, $pos2 - $start);
                return trim($url);
        } else {
                return trim(preg_replace('/\$1/', urlencode(preg_replace('/[ +]/', '_', trim($link))), $wgArticlePath));
        }
}
 
function getTextFromLink($link) {
        if (strpos($link, '[[') === 0) {
                // internal link
                $delimiter = '|';
                $start = 1;
        } else if (strpos($link, '[') === 0) {
                // external link
                $delimiter = ' ';
                $start = 0;
        } else {
                return trim($link);
        }
        $pos1 = strpos($link, $delimiter);
        if ($pos1 === FALSE) {
                $pos1 = $start;
        }
        $pos2 = strpos($link, ']');
        return trim(substr($link, $pos1 + 1, $pos2 - $pos1 - 1));
}


See also [edit]