Exemple #1
0
 public function testChildren()
 {
     $wikiText = '{{#genealogy:parent|Alice}}';
     $this->setPageContent('Bob', $wikiText);
     $this->setPageContent('Carly', $wikiText);
     $alice = new Person(Title::newFromText('Alice'));
     $this->assertEquals(['Bob', 'Carly'], array_keys($alice->getChildren()));
 }
Exemple #2
0
 /**
  * Render the output of the parser function.
  * The input parameters are wikitext with templates expanded.
  * The output should be wikitext too.
  *
  * @param Parser $parser
  * @param string $type
  * @param string $param2
  * @param string $param3
  * @return string The wikitext with which to replace the parser function call.
  */
 public static function renderParserFunction(Parser $parser)
 {
     $params = [];
     $args = func_get_args();
     array_shift($args);
     // Remove $parser
     $type = array_shift($args);
     // Get param 1, the function type
     foreach ($args as $arg) {
         // Everything that's left must be named
         $pair = explode('=', $arg, 2);
         if (count($pair) == 2) {
             $name = trim($pair[0]);
             $value = trim($pair[1]);
             $params[$name] = $value;
         } else {
             $params[] = $arg;
         }
     }
     $out = '';
     $isHtml = false;
     switch ($type) {
         case 'person':
             if (isset($params['birth date'])) {
                 $out .= $params['birth date'];
                 self::saveProp($parser, 'birth date', $params['birth date'], false);
             }
             if (isset($params['death date'])) {
                 $out .= $params['death date'];
                 self::saveProp($parser, 'death date', $params['death date'], false);
             }
             break;
         case 'parent':
             $parentTitle = Title::newFromText($params[0]);
             $parent = new Person($parentTitle);
             $out .= $parent->getWikiLink();
             //				if ( $parentTitle && $parentTitle->exists() ) {
             //					$out .= $parent->getWikiLink();
             //				} else {
             //					$query = [ 'preload' => wfMessage( 'genealogy-person-preload' ) ];
             //					$out .= Linker::link( $parentTitle, null, [], $query );
             //					$isHtml = true;
             //				}
             self::saveProp($parser, 'parent', $params[0]);
             break;
         case 'siblings':
             $person = new Person($parser->getTitle());
             $out .= self::peopleList($parser, $person->getSiblings());
             break;
         case 'partner':
             self::saveProp($parser, 'partner', $params[0]);
             break;
         case 'partners':
             $person = new Person($parser->getTitle());
             $out .= self::peopleList($parser, $person->getPartners());
             break;
         case 'children':
             $person = new Person($parser->getTitle());
             $out .= self::peopleList($parser, $person->getChildren());
             break;
         case 'tree':
             $tree = new Tree();
             if (isset($params['ancestors'])) {
                 $tree->addAncestors(explode("\n", $params['ancestors']));
             }
             if (isset($params['ancestor depth'])) {
                 $tree->setAncestorDepth($params['ancestor depth']);
             }
             if (isset($params['descendants'])) {
                 $tree->addDescendants(explode("\n", $params['descendants']));
             }
             if (isset($params['descendant depth'])) {
                 $tree->setDescendantDepth($params['descendant depth']);
             }
             $graphviz = $tree->getGraphviz();
             $out .= $parser->recursiveTagParse("<graphviz>\n{$graphviz}\n</graphviz>");
             // $out .= $parser->recursiveTagParse( "<pre>$graphviz</pre>" );
             break;
         default:
             $msg = wfMessage('genealogy-parser-function-not-found', [$type]);
             $out .= "<span class='error'>{$msg}</span>";
             break;
     }
     // Return format is documented in Parser::setFunctionHook().
     return $isHtml ? [0 => $out, 'isHTML' => true] : $out;
 }