コード例 #1
0
ファイル: Hooks.php プロジェクト: samwilson/genealogy
 /**
  * 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;
 }
コード例 #2
0
ファイル: Person.php プロジェクト: samwilson/genealogy
 /**
  * Get a multi-valued relationship property of this Person.
  * @param string $type The property name ('genealogy ' will be prepended).
  * @return Person[] The related people.
  */
 protected function getPropMulti($type)
 {
     $out = [];
     $dbr = wfGetDB(DB_SLAVE);
     $articleIds = [];
     foreach ($this->getTitles() as $t) {
         $articleIds[] = $t->getArticleID();
     }
     $results = $dbr->select('page_props', 'pp_value', ['pp_page' => $articleIds, "pp_propname LIKE 'genealogy {$type} %'"], __METHOD__, ['ORDER BY' => 'pp_value']);
     foreach ($results as $result) {
         $title = Title::newFromText($result->pp_value);
         if (is_null($title)) {
             // Do nothing, if this isn't a valid title.
             continue;
         }
         $person = new Person($title);
         $out[$person->getTitle()->getPrefixedDBkey()] = $person;
     }
     return $out;
 }
コード例 #3
0
ファイル: Tree.php プロジェクト: samwilson/genealogy
 protected function outputPersonLine(Person $person)
 {
     $birthYear = $person->getBirthDate();
     $deathYear = $person->getDeathDate();
     if (!empty($birthYear) && !empty($deathYear)) {
         $date = '\\n' . $birthYear . ' &ndash; ' . $deathYear;
     } elseif (!empty($birthYear)) {
         $date = '\\nb.&nbsp;' . $birthYear;
     } elseif (!empty($deathYear)) {
         $date = '\\nd.&nbsp;' . $deathYear;
     } else {
         $date = '';
     }
     if ($person->getTitle()->exists()) {
         $url = '[[' . $person->getTitle()->getText() . ']]';
         $colour = 'black';
     } else {
         $queryString = ['preload' => wfMessage('genealogy-person-preload'), 'action' => 'edit'];
         $url = '[' . $person->getTitle()->getFullURL($queryString) . ' ' . $person->getTitle()->getText() . ']';
         $colour = 'red';
     }
     $title = $person->getTitle()->getText();
     $personId = $this->esc($title);
     $line = $personId . " [" . " label=\"{$title}{$date}\", " . " URL=\"{$url}\", " . " tooltip=\"{$title}\", " . " fontcolor=\"{$colour}\" " . "]";
     $this->out('person', $personId, $line);
 }
コード例 #4
0
ファイル: PersonTest.php プロジェクト: samwilson/genealogy
 public function testRedirectPartner()
 {
     // Create Charles.
     $charlesTitle = Title::newFromText('Charles');
     $charlesPage = new WikiPage($charlesTitle);
     $charlesPage->doEditContent(new WikitextContent('{{#genealogy:partner|Diana}}'), '');
     $charles = new Person($charlesTitle);
     // Create Diana and made sure she's Charles' partner.
     $diannaTitle = Title::newFromText('Diana');
     $diannaPage = new WikiPage($diannaTitle);
     $diannaPage->doEditContent(new WikitextContent("Dianna"), '');
     $this->assertEquals('Diana', $charles->getPartners()['Diana']->getTitle());
     // Redirect Diana to Dianna.
     $diannaPage->doEditContent(new WikitextContent("#REDIRECT [[Dianna]]"), 'Redirecting');
     $diana = new Person(Title::newFromText('Diana'));
     $this->assertEquals('Dianna', $diana->getTitle()->getText());
     $this->assertEquals(['Diana', 'Dianna'], array_keys($diana->getTitles()));
     // Check that Charles and Dianna have the expected partners.
     $this->assertCount(1, $charles->getPartners());
     $this->assertEquals('Dianna', $charles->getPartners()['Dianna']->getTitle());
     $this->assertCount(1, $diana->getPartners());
     $this->assertEquals('Charles', $diana->getPartners()['Charles']->getTitle());
     // Then redirect Charles and check everything again.
     $charlesPage->doEditContent(new WikitextContent("#REDIRECT [[King Charles]]"), '');
     $kingChPage = new WikiPage(Title::newFromText('King Charles'));
     $kingChPage->doEditContent(new WikitextContent('{{#genealogy:partner|Diana}}'), '');
     $this->assertEquals(['Charles', 'King_Charles'], array_keys($charles->getTitles()));
     $this->assertCount(1, $charles->getPartners());
     $this->assertEquals('Dianna', $charles->getPartners()['Dianna']->getTitle());
     $this->assertCount(1, $diana->getPartners());
     $this->assertEquals('King Charles', $diana->getPartners()['King_Charles']->getTitle()->getText());
 }