forked from wikimedia/mediawiki-extensions-SemanticGenealogy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gedcom5ResultPrinter.php
73 lines (65 loc) · 2.2 KB
/
Gedcom5ResultPrinter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Printer class for creating GEDCOM exports
*
* @file GedcomResultPrinter.php
* @ingroup SemanticGenealogy
*
* @licence GNU GPL v2+
* @author Thomas Pellissier Tanon < thomaspt@hotmail.fr >
*/
class Gedcom5ResultPrinter extends SMWResultPrinter {
public $ids = array();
public function getMimeType( $res ) {
return 'application/x-gedcom';
}
public function getFileName( $res ) {
if( $this->getSearchLabel( SMW_OUTPUT_WIKI ) != '' ) {
return str_replace( ' ', '_', $this->getSearchLabel( SMW_OUTPUT_WIKI ) ) . '.ged';
} else {
return 'GEDCOM.ged';
}
}
public function getQueryMode( $context ) {
return ( $context == SMWQueryProcessor::SPECIAL_PAGE ) ? SMWQuery::MODE_INSTANCES : SMWQuery::MODE_NONE;
}
public function getName() {
return wfMsg( 'semanticgenealogy-gedcomexport-desc' );
}
protected function getResultText( SMWQueryResult $res, $outputmode ) {
$result = '';
if( $outputmode == SMW_OUTPUT_FILE ) {
$people = array();
$row = $res->getNext();
while( $row !== false ) {
$people[] = new PersonPageValues( $row[0]->getResultSubject() );
$row = $res->getNext();
}
$printer = new Gedcom5FilePrinter();
$printer->addPeople( $people );
$result = $printer->getFile();
} else { // just make link
if( $this->getSearchLabel( $outputmode ) ) {
$label = $this->getSearchLabel( $outputmode );
} else {
$label = wfMsgForContent( 'semanticgenealogy-gedcomexport-link' );
}
$link = $res->getQueryLink( $label );
$link->setParameter( 'gedcom5', 'format' );
if( $this->getSearchLabel( SMW_OUTPUT_WIKI ) != '' ) {
$link->setParameter( $this->getSearchLabel( SMW_OUTPUT_WIKI ), 'searchlabel' );
}
if( array_key_exists( 'limit', $this->m_params ) ) {
$link->setParameter( $this->m_params['limit'], 'limit' );
} else { // use a reasonable default limit
$link->setParameter( 20, 'limit' );
}
$result .= $link->getText( $outputmode, $this->mLinker );
$this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); // yes, our code can be viewed as HTML if requested, no more parsing needed
}
return $result;
}
public function getParameters() {
return array_merge( parent::getParameters(), $this->exportFormatParameters() );
}
}