Wilkins has uploaded a new change for review. https://gerrit.wikimedia.org/r/245913
Change subject: Dynamic loading for all types of FamilyTrees - Adding TODO file ...................................................................... Dynamic loading for all types of FamilyTrees - Adding TODO file Change-Id: Ie0cecf5a65bdfc851dd8cb308849b69f8a625c13 --- M AncestorsFamilyTree.php M DescendantFamilyTree.php M FamilyTree.php M FamilyTreeFactory.php M FamilyTreeTag.php M PersonPageValues.php M RelationFamilyTree.php M SpecialFamilyTree.php A TODO M specialFamilyTree.js 10 files changed, 86 insertions(+), 28 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticGenealogy refs/changes/13/245913/1 diff --git a/AncestorsFamilyTree.php b/AncestorsFamilyTree.php index 3ebc623..89cf5ee 100644 --- a/AncestorsFamilyTree.php +++ b/AncestorsFamilyTree.php @@ -15,6 +15,8 @@ class AncestorsFamilyTree extends FamilyTree { + const NAME = 'ancestors'; + /** * List the ancestors of the person for all needed generations * diff --git a/DescendantFamilyTree.php b/DescendantFamilyTree.php index 5656612..c62983f 100644 --- a/DescendantFamilyTree.php +++ b/DescendantFamilyTree.php @@ -14,6 +14,7 @@ */ class DescendantFamilyTree extends FamilyTree { + const NAME = 'descendant'; /** * List the descendants for all needed generations diff --git a/FamilyTree.php b/FamilyTree.php index 92b9582..592c5a9 100644 --- a/FamilyTree.php +++ b/FamilyTree.php @@ -15,6 +15,8 @@ abstract class FamilyTree { + const NAME = 'root'; + protected $output; protected $person; protected $personName; diff --git a/FamilyTreeFactory.php b/FamilyTreeFactory.php index 2c819fc..05a73f9 100644 --- a/FamilyTreeFactory.php +++ b/FamilyTreeFactory.php @@ -24,18 +24,45 @@ public static function create($type) { global $wgOut; - switch($type) { - case 'ancestors': - return new AncestorsFamilyTree(); - break; - case 'descendant': - return new DescendantFamilyTree(); - break; - case 'link': - return new RelationFamilyTree(); - break; - default: - $wgOut->addWikiText('<span class="error">' . wfMsg('semanticgenealogy-specialfamilytree-error-unknowntype', $type) . '</span>'); + $trees = self::listTrees(); + foreach ($trees as $tree) { + if ($type == $tree::NAME) { + return new $tree(); + } } + $wgOut->addWikiText('<span class="error">' . wfMsg('semanticgenealogy-specialfamilytree-error-unknowntype', $type) . '</span>'); + } + + /** + * List the existing tree types + * + * @return array the list of FamilyTree classes availables + */ + public static function listTrees() + { + $trees = array(); + foreach (new DirectoryIterator(__DIR__) as $file) { + if ($file->isDot()) { + continue; + } + if (!$file->isFile()) { + continue; + } + if (!preg_match("#.php$#", $file->getFilename())) { + continue; + } + require_once $file->getPathname(); + $className = $file->getBasename('.php'); + try { + $classRef = new ReflectionClass($className); + } catch (ReflectionException $e) { + continue; + } + + if (!$classRef->isAbstract() && $classRef->isSubclassOf('FamilyTree')) { + $trees[] = new $className; + } + } + return $trees; } } diff --git a/FamilyTreeTag.php b/FamilyTreeTag.php index 264b6ef..297cea3 100644 --- a/FamilyTreeTag.php +++ b/FamilyTreeTag.php @@ -50,18 +50,20 @@ // A new OutputPage writer $output = new OutputPage; $familytree = FamilyTreeFactory::create($args[self::ATTR_TYPE]); - $familytree->setOutput($output); - $familytree->setPerson($args[self::ATTR_PERSON]); - $familytree->setNumberOfGenerations($args[self::ATTR_DEPTH]); + if ($familytree) { + $familytree->setOutput($output); + $familytree->setPerson($args[self::ATTR_PERSON]); + $familytree->setNumberOfGenerations($args[self::ATTR_DEPTH]); - if (isset($args[self::ATTR_PERSON2])) { - $personName2 = $args[self::ATTR_PERSON2]; - if ($personName2) { - $familytree->setPerson2($personName2); + if (isset($args[self::ATTR_PERSON2])) { + $personName2 = $args[self::ATTR_PERSON2]; + if ($personName2) { + $familytree->setPerson2($personName2); + } } - } - $familytree->render(); + $familytree->render(); + } $output->setArticleBodyOnly(true); ob_start(); diff --git a/PersonPageValues.php b/PersonPageValues.php index 3dee77f..19d3a76 100644 --- a/PersonPageValues.php +++ b/PersonPageValues.php @@ -114,6 +114,7 @@ public function getDescriptionWikiText($withBr = false) { + $yearRegexp = "/.*\b(\d\d\d\d)\b.*/"; $text = '[[' . $this->title->getFullText() . '|' . $this->fullname->getString() . ']]'; if ($this->birthdate || $this->deathdate) { if ($withBr) { @@ -122,10 +123,14 @@ $text .= ' ('; if ($this->birthdate instanceof SMWDITime) { $text .= self::getWikiTextDateFromSMWDITime($this->birthdate) . ' '; + } else if (preg_match($yearRegexp, $this->birthdate)) { + $text .= preg_replace($yearRegexp, "$1", $this->birthdate); } $text .= '-'; if ($this->deathdate instanceof SMWDITime) { $text .= ' ' . self::getWikiTextDateFromSMWDITime($this->deathdate); + } else if (preg_match($yearRegexp, $this->deathdate)) { + $text .= preg_replace($yearRegexp, "$1", $this->deathdate); } $text .= ')'; } diff --git a/RelationFamilyTree.php b/RelationFamilyTree.php index b740460..3eb58e9 100644 --- a/RelationFamilyTree.php +++ b/RelationFamilyTree.php @@ -16,6 +16,8 @@ class RelationFamilyTree extends FamilyTree { + const NAME = 'relation'; + protected $person2; protected $personName2; diff --git a/SpecialFamilyTree.php b/SpecialFamilyTree.php index cee36c8..95f4181 100644 --- a/SpecialFamilyTree.php +++ b/SpecialFamilyTree.php @@ -46,12 +46,12 @@ $type = isset( $parts[0] ) ? $parts[0] : $wgRequest->getText('type'); if ($type == '') { - $type = 'ancestors'; + $type = AncestorsFamilyTree::NAME; } $pageName = isset( $parts[1] ) ? $parts[1] : $wgRequest->getText('page'); - if ($type == 'link') { + if ($type == RelationFamilyTree::NAME) { $pageName2 = isset( $parts[2] ) ? $parts[2] : $wgRequest->getText('page2'); $numOfGenerations = 0; } else { @@ -63,6 +63,7 @@ } $this->showForm(array('type' => $type, 'pageName' => $pageName, 'numOfGenerations' => $numOfGenerations, 'pageName2' => $pageName2)); + if ($pageName == '') { return; @@ -84,7 +85,7 @@ /** * Display the search form for a genealogy tree - * + * * @param array $params the array of search parameters * * @return void @@ -96,10 +97,11 @@ $output = $this->getOutput(); if (!$this->mIncluding) { $output->addModules('ext.smg.specialfamilytree'); + $trees = FamilyTreeFactory::listTrees(); $typeSelect = new XmlSelect('type', 'type', $params['type']); - $typeSelect->addOption(wfMsg('semanticgenealogy-specialfamilytree-type-ancestors'), 'ancestors'); - $typeSelect->addOption(wfMsg('semanticgenealogy-specialfamilytree-type-descendant'), 'descendant'); - $typeSelect->addOption(wfMsg('semanticgenealogy-specialfamilytree-type-link'), 'link'); + foreach ($trees as $tree) { + $typeSelect->addOption(wfMsg('semanticgenealogy-specialfamilytree-type-'.$tree::NAME), $tree::NAME); + } $output->addHTML( Xml::openElement('form', array( 'action' => $wgScript )) . Html::hidden('title', $this->getPageTitle()->getPrefixedText()) . diff --git a/TODO b/TODO new file mode 100644 index 0000000..16d7abb --- /dev/null +++ b/TODO @@ -0,0 +1,15 @@ + +Ideas +----- +- Flag to display either the "full name" or the "page name" +- Adding a decorator for the tree (styling the tree) +- Couple Descendant tree (real tree + wife) + + +Decorators +---------- +- real brown branches + green for a person +- blue for boys, pink for girls +- simple box +- left/right alignment for RelationFamilyTree +- Pretty └── for Descendant tree diff --git a/specialFamilyTree.js b/specialFamilyTree.js index bdd662c..6e3a4fc 100644 --- a/specialFamilyTree.js +++ b/specialFamilyTree.js @@ -26,7 +26,7 @@ } function showFields() { - if( $( 'select#type' ).val() == 'link' ) { + if( $( 'select#type' ).val() == 'relation' ) { $( 'tr#smg-form-entry-gen' ).hide(); $( 'tr#smg-form-entry-page2' ).show(); } else { -- To view, visit https://gerrit.wikimedia.org/r/245913 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie0cecf5a65bdfc851dd8cb308849b69f8a625c13 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/SemanticGenealogy Gerrit-Branch: master Gerrit-Owner: Wilkins <thiba...@taillandier.name> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits