Extension:PIM Support

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual
Crystal Clear action run.png
PIM Support

Release status: experimental

Implementation Special page, Data extraction
Description simple Personal Information Management support, currently for prefilled contact wikipages in seperate namespace
Author(s) Florian Konnertz (groovehuntertalk)
Latest version 0.1 (2008-03-20)
MediaWiki 1.11.
License No license specified
Download No link
Example none public
Parameters

currently none

Added rights

currently none

Hooks used
OutputPageBeforeHTML

Translate the PIM Support extension if it is available at translatewiki.net

Check usage and version matrix; code metrics

What can this extension do?[edit | edit source]

It provides a special page providing links to [[K:John Doe]]. "K" is a custom namespace, meaning Kontakt (german for contact). The data comes from csv export file from linux kontact PIM. PIM, for whom do not know is short for "Personal Information Management", so this extensions aims (in further development) to offer access to this information: dates, calendar, tasks, emails. For now it's a bit helpful for creating articles about your contacts without typing them and populating these pages with basic contact data.


Usage[edit | edit source]

View Special:PIM_Support to see all your contacts as links to wikipages. Create a page and you should see some basic contact data on that page.


Download instructions[edit | edit source]

Please cut and paste the code found below and place it in $IP/extensions/PIM_Support/PIM_Support.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.


Installation[edit | edit source]

To install this extension, add the following to LocalSettings.php:

$wgExtraNamespaces[210] = "K";
define("NS_K", 210);
$wgContentNamespaces[] = 210;
 
require_once("$IP/extensions/PIM_Support/PIM_Support.php");

export your contacts from kontact and move or copy the file to

$IP/extensions/PIM_Support/

copy the file again to kontact_header.csv and remove all but the first line (the header line), leave it in that dir.

I guess you have to experiment a bit with the dir and filename variables in the code to get it running.


Configuration parameters[edit | edit source]

none yet

User rights[edit | edit source]

none yet


Code[edit | edit source]

<?php
if (!defined('MEDIAWIKI')) die();
 
$dir = dirname(__FILE__) . '/';
$csv_fn = $dir.'kontact_export_20080307.csv';
 
$wgExtensionFunctions[] = "wfSetupPIM_Support";
 
$wgExtensionCredits['PIM Support'][] = array(
    'name'      =>  'PIM Support',
    'author'    =>  'Florian Konnertz',
    'url'       =>  'http://www.mediawiki.org/wiki/User:Groovehunter',
    'description' =>'Basic PIM (Personal Information Management) Support'
    );
 
 
// XXX namen normalisieren , capitals?, zweite+ vornamen entfernen?
$wgHooks['OutputPageBeforeHTML'][] = 'PIM_OutputPageBeforeHTML';
 
 
function PIM_OutputPageBeforeHTML(&$out, &$text) {
    global $wgTitle;
    global $df;
    $out = '';
    $ns = $wgTitle->getNamespace();
    //var_dump($ns);
    if ($ns == NS_K) {
        $title_text = $wgTitle->getText();
        $name = explode(' ', $title_text);
        $cfn = $name[0];
        $cln = $name[1];
        $lines = loadData();
        $names = indexAsData($lines);
        $ind = $cln."_".$cfn;
        $data = $names[$ind];
        if ($data) {
            $details = showDetails($data);
            $out .= $details;
        }
    }
    $text .= $out;
    return true;
}
 
 
function showDetails($line) {
    global $dir;
    $hfn = $dir.'kontact_header.csv';
    $hline = file_get_contents($hfn);
    $header = split('","', $hline);
    $dout = '';
    $dout .= '<b>Details des Kontakts</b><br>';
    $dout .= '<table border="1">';
    //$show_fields = array(1,2,7,8,9,11,15,17,20,21,22,28,36);
    $show_fields = array(7,8,9,11,15,17,20,21,22,28,36);
    foreach ($show_fields as $i=>$k) {
        $dout .= '<tr>';
        $dout .= '<td>';
        $dout .= "<b>{$header[$k]}</b></td>";
        $dout .= "<td>{$line[$k]}</td></tr>";
    }
    $dout .= '</table>';
    return $dout;
}
 
function wfSetupPIM_Support() {
    // FIXME title of specialpage is not rendered correctly
    require_once( 'SpecialPage.php' );
    SpecialPage::addPage( new SpecialPage( 'PIM_Support', 'edit',
      /*listed*/ true, /*function*/ false, /*file*/ false )  );
 
      // XXX name indizieren, als file speichern f�r abruf bei artikel-kontakt-seite um
      // detail daten nachzuladen in artikel-text
}
 
function loadData() {
    global $csv_fn;
    if (file_exists( $csv_fn )) {
        $lines = file( $csv_fn );
        return $lines;
    }
}
 
function indexAsData($lines) {
    $data = array();
    foreach ($lines as $k=>$line) {
        //dump($line);
        $fields = split('","', $line);
        $ln = $fields[1];
        $fn = $fields[2];
        $ind = $ln."_".$fn;
        $data[$ind] = $fields;
    }
    ksort($data);
    return $data;
}
 
function indexAsNames($lines) {
    foreach ($lines as $k=>$line) {
        //dump($line);
        $fields = split('","', $line);
        $ln = $fields[1];
        $fn = $fields[2];
        $name = $fn." ".$ln;
        $ind = $ln."_".$fn;
        $names[$ind] = $name;
        ksort($names);
    }
    return $names;
}
 
function wfSpecialPIM_Support() {
    global $wgOut;
    $lines = loadData();
    if ($lines) {
        $names = indexAsNames($lines);
    //sort($lines);
        $num = count($names);
 
        $out = '';
        $out .= "[[PIM Support Extension]] - {$num} names \n\n";
        //for ($i=65; $i<=90; $i++) $abc[] = chr($i);
        //foreach ($abc as $v) {
        // XXX first letters!!
 
        foreach ($names as $k=>$name) {
            $ptitle_l = str_replace(' ', '_', $name);
            $out .= "* [[K:{$name}]]\t";
            //$out .= "[[xing:{$name}]]\n";   // XXX test for xing in notizen, substitute umlauts
        }
    } else {
        $out .= 'Data file not found';
    }
    $wgOut->addWikiText($out);
}

See also[edit | edit source]

not sure if there are related extensions. I will check soon, my next wish is email access, so to write wikified emails make sense