Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 protected function outputPersonLine(Person $person)
 {
     $birthYear = $person->getBirthDate();
     $deathYear = $person->getDeathDate();
     if (!empty($birthYear) && !empty($deathYear)) {
         $date = '\\n' . $birthYear . ' – ' . $deathYear;
     } elseif (!empty($birthYear)) {
         $date = '\\nb. ' . $birthYear;
     } elseif (!empty($deathYear)) {
         $date = '\\nd. ' . $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);
 }
Exemplo n.º 3
0
 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());
 }