Wilkins has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/370594 )
Change subject: Patch for the previous commit in review - fixing syntax based on codesniffer v0.10 - deleting composer.lock ...................................................................... Patch for the previous commit in review - fixing syntax based on codesniffer v0.10 - deleting composer.lock Change-Id: I726a246e89c8b5b381f7ff1233ca59019ae86d57 --- M Gedcom5FilePrinter.php M Gedcom5ResultPrinter.php M GenealogicalFilePrinter.php M PersonPageValues.php M SemanticGenealogy.alias.php M SemanticGenealogy.body.php M SemanticGenealogy.i18n.php M SemanticGenealogy.php M SemanticGenealogyException.php M SpecialFamilyTree.php M Tools.php M composer.json D composer.lock M src/Decorator/BoxDecorator.php M src/Decorator/SimpleDecorator.php M src/Decorator/TreeDecorator.php M src/Decorator/TreeDecoratorFactory.php M src/Tree/AncestorsFamilyTree.php M src/Tree/DescendantFamilyTree.php M src/Tree/DescendantListFamilyTree.php M src/Tree/FamilyTree.php M src/Tree/FamilyTreeFactory.php M src/Tree/LinkFamilyTree.php 23 files changed, 319 insertions(+), 352 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticGenealogy refs/changes/94/370594/1 diff --git a/Gedcom5FilePrinter.php b/Gedcom5FilePrinter.php index e13811e..47b3787 100644 --- a/Gedcom5FilePrinter.php +++ b/Gedcom5FilePrinter.php @@ -11,11 +11,10 @@ * @licence GNU GPL v2+ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> */ -class Gedcom5FilePrinter extends GenealogicalFilePrinter -{ +class Gedcom5FilePrinter extends GenealogicalFilePrinter { - protected $families = array(); - protected $familiesByPerson = array(); + protected $families = []; + protected $familiesByPerson = []; /** * Set file in $this->file property @@ -23,7 +22,6 @@ * @return void */ protected function setFile() { - $this->setFamiliesList(); $this->addHead(); @@ -42,20 +40,25 @@ * @return void */ protected function setFamiliesList() { - foreach ( $this->people as $child ) { - $id = $this->getFamilyIdForChild( $child ); - if ( $id != '0S0' ) { - $this->addChildToFamily( $id, $child ); - list( $fatherId, $motherId ) = explode( 'S', $id ); - $this->addFamilyToPerson( $id, $fatherId ); - $this->addFamilyToPerson( $id, $motherId ); + $familyId = $this->getFamilyIdForChild( $child ); + if ( $familyId != '0S0' ) { + $this->addChildToFamily( $familyId, $child ); + list( $fatherId, $motherId ) = explode( 'S', $familyId ); + $this->addFamilyToPerson( $familyId, $fatherId ); + $this->addFamilyToPerson( $familyId, $motherId ); } } } + /** + * Get the family Id if the given child + * + * @param object $child the PersonPageValues object of the child + * + * @return string the key + */ protected function getFamilyIdForChild( PersonPageValues $child ) { - $key = ''; if ( $child->father instanceof SMWDIWikiPage && isset( $this->people[$child->father->getTitle()->getArticleID()] ) ) { @@ -78,36 +81,51 @@ return $key; } + /** + * Adds a child to a family + * + * @param string $familyKey the family key + * @param object $child the PersonPageValues object of the child to add + * + * @return void + */ protected function addChildToFamily( $familyKey, PersonPageValues $child ) { - $childId = $child->title->getArticleID(); if ( isset( $this->families[$familyKey] ) ) { if ( !in_array( $childId, $this->families[$familyKey] ) ) { $this->families[$familyKey][] = $childId; } } else { - $this->families[$familyKey] = array( $childId ); + $this->families[$familyKey] = [ $childId ]; } } + /** + * Adds a family to a person + * + * @param integer $familyId the id of the family + * @param integer $personId the id of the person + * + * @return void + */ protected function addFamilyToPerson( $familyId, $personId ) { - if ( $personId != 0 ) { if ( isset( $this->familiesByPerson[$personId] ) ) { if ( !in_array( $familyId, $this->familiesByPerson[$personId] ) ) { $this->familiesByPerson[$personId][] = $familyId; } } else { - $this->familiesByPerson[$personId] = array( $familyId ); + $this->familiesByPerson[$personId] = [ $familyId ]; } } } /** * Add GEDCOM header + * + * @return void */ protected function addHead() { - global $wgSitename, $wgRightsText; $this->addRow( 0, 'HEAD' ); @@ -120,7 +138,8 @@ } // $this->addRow( 1, 'FILE', ); //TODO name of the file $this->addRow( 1, 'DATE', strtoupper( date( 'd M Y' ) ) ); - $this->addRow( 2, 'TIME', date( 'H:i:s' ) ); // TODO hh:mm:ss.fs + // TODO hh:mm:ss.fs + $this->addRow( 2, 'TIME', date( 'H:i:s' ) ); $this->addRow( 1, 'GEDC' ); $this->addRow( 2, 'VERS', 5.5 ); $this->addRow( 2, 'FORM', 'LINEAGE-LINKED' ); @@ -131,13 +150,13 @@ /** * Add the GEDCOM for a person * - * @param $person PersonPageValues + * @param integer $personId the id of the person + * @param object $person PersonPageValues object * * @return void */ - protected function addPerson( $id, PersonPageValues $person ) { - - $this->addRow( 0, '@I'. $id . '@', 'INDI' ); + protected function addPerson( $personId, PersonPageValues $person ) { + $this->addRow( 0, '@I'. $personId . '@', 'INDI' ); $this->addRow( 1, 'NAME', $this->getGedcomName( $person ) ); $this->addStringValueAsRow( 2, 'GIVN', $person->givenname ); $this->addStringValueAsRow( 2, 'SURN', $person->surname ); @@ -149,8 +168,8 @@ if ( $familyId != '0S0' ) { $this->addRow( 1, 'FAMC', '@F'. $familyId . '@' ); } - if ( isset( $this->familiesByPerson[$id] ) ) { - foreach ( $this->familiesByPerson[$id] as $familyId ) { + if ( isset( $this->familiesByPerson[$personId] ) ) { + foreach ( $this->familiesByPerson[$personId] as $familyId ) { $this->addRow( 1, 'FAMS', '@F'. $familyId . '@' ); } } @@ -158,10 +177,17 @@ $this->addEvent( 'DEAT', $person->deathdate, $person->deathplace ); } - protected function addFamily( $id, $children ) { - - list( $fatherId, $motherId ) = explode( 'S', $id ); - $this->addRow( 0, '@F'. $id . '@', 'FAM' ); + /** + * Adds family to the gedcom + * + * @param integer $familyId the id of the family + * @param array $children the children array + * + * @return void + */ + protected function addFamily( $familyId, $children ) { + list( $fatherId, $motherId ) = explode( 'S', $familyId ); + $this->addRow( 0, '@F'. $familyId . '@', 'FAM' ); if ( $fatherId != 0 ) { $this->addRow( 1, 'HUSB', '@I' . $fatherId . '@' ); } @@ -173,8 +199,14 @@ } } + /** + * Get the gedcom name + * + * @param object $person the person object + * + * @return string the name for the gedcom + */ protected function getGedcomName( PersonPageValues $person ) { - $name = ''; if ( $person->givenname instanceof SMWDIBlob && $person->givenname->getString() != '' ) { $name .= $person->givenname->getString(); @@ -188,8 +220,16 @@ return $name; } + /** + * Adds a row + * + * @param string $level the level of the row + * @param string $key the key + * @param object $value the value + * + * @return void + */ protected function addRow( $level, $key, $value = null ) { - $this->file .= $level . ' ' . $key; if ( $value !== null ) { $this->file .= ' ' . str_replace( '\n', ' ', $value ); @@ -198,10 +238,17 @@ } /** - * TODO add places metadata support. - */ + * Add Event + * + * TODO add places metadata support. + * + * @param string $type the type + * @param string $date the date + * @param string $place the place + * + * @return void + */ protected function addEvent( $type, $date, $place ) { - if ( $date === null && $place === null ) { return; } @@ -214,15 +261,31 @@ } } + /** + * Adds a row from string value + * + * @param string $level the level of the row + * @param string $key the key + * @param object $value the string value + * + * @return void + */ protected function addStringValueAsRow( $level, $key, $value ) { - if ( $value instanceof SMWDIBlob ) { $this->addRow( $level, $key, $value->getString() ); } } + /** + * Adds a row from time value + * + * @param string $level the level of the row + * @param string $key the key + * @param object $value the time value + * + * @return void + */ protected function addTimeValueAsRow( $level, $key, $value ) { - if ( $value instanceof SMWDITime ) { $lang = new Language(); $this->addRow( $level, $key, @@ -230,8 +293,16 @@ } } + /** + * Adds a row from the wiki page + * + * @param string $level the level of the row + * @param string $key the key + * @param object $value the wiki page value + * + * @return void + */ protected function addWikiPageValueAsRow( $level, $key, $value ) { - if ( $value instanceof SMWDIWikiPage ) { $this->addRow( $level, $key, $value->getTitle()->getText() ); } diff --git a/Gedcom5ResultPrinter.php b/Gedcom5ResultPrinter.php index a949c2c..d86e993 100644 --- a/Gedcom5ResultPrinter.php +++ b/Gedcom5ResultPrinter.php @@ -9,17 +9,28 @@ * @licence GNU GPL v2+ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> */ -class Gedcom5ResultPrinter extends SMWResultPrinter -{ - public $ids = array(); +class Gedcom5ResultPrinter extends SMWResultPrinter { + public $ids = []; + /** + * Get the mimetype of the result printer + * + * @param string|object $res the result printer + * + * @return string the mimetype + */ public function getMimeType( $res ) { - return 'application/x-gedcom'; } + /** + * Get the filename of the result printer + * + * @param string|object $res the result printer + * + * @return string the filename + */ public function getFileName( $res ) { - if ( $this->getSearchLabel( SMW_OUTPUT_WIKI ) != '' ) { return str_replace( ' ', '_', $this->getSearchLabel( SMW_OUTPUT_WIKI ) ) . '.ged'; } else { @@ -27,22 +38,40 @@ } } + /** + * Get the query mode + * + * @param string $context the context + * + * @return string the query mode + */ public function getQueryMode( $context ) { - return ( $context == SMWQueryProcessor::SPECIAL_PAGE ) ? SMWQuery::MODE_INSTANCES : SMWQuery::MODE_NONE; } + /** + * Get the Result printer name + * + * @return the name of the result printer + */ public function getName() { return wfMessage( 'semanticgenealogy-gedcomexport-desc' )->text(); } + /** + * Get the result test of the result printer + * + * @param SMWQueryResult $res the result + * @param integer $outputmode the output mode chosen + * + * @return string the result text + */ protected function getResultText( SMWQueryResult $res, $outputmode ) { - $result = ''; if ( $outputmode == SMW_OUTPUT_FILE ) { - $people = array(); + $people = []; $row = $res->getNext(); while ( $row !== false ) { $people[] = new PersonPageValues( $row[0]->getResultSubject() ); @@ -51,7 +80,8 @@ $printer = new Gedcom5FilePrinter(); $printer->addPeople( $people ); $result = $printer->getFile(); - } else { // just make link + } else { + // just make link if ( $this->getSearchLabel( $outputmode ) ) { $label = $this->getSearchLabel( $outputmode ); } else { @@ -64,7 +94,8 @@ } if ( array_key_exists( 'limit', $this->m_params ) ) { $link->setParameter( $this->m_params['limit'], 'limit' ); - } else { // use a reasonable default limit + } else { + // use a reasonable default limit $link->setParameter( 20, 'limit' ); } $result .= $link->getText( $outputmode, $this->mLinker ); @@ -74,8 +105,12 @@ return $result; } + /** + * Get all the parameters + * + * @return array the base parameters and the export format parameters + */ public function getParameters() { - return array_merge( parent::getParameters(), $this->exportFormatParameters() ); } } diff --git a/GenealogicalFilePrinter.php b/GenealogicalFilePrinter.php index 534fb9d..1c126b8 100644 --- a/GenealogicalFilePrinter.php +++ b/GenealogicalFilePrinter.php @@ -9,20 +9,18 @@ * @licence GNU GPL v2+ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> */ -abstract class GenealogicalFilePrinter -{ +abstract class GenealogicalFilePrinter { protected $file = ''; - protected $people = array(); + protected $people = []; /** * Add people to the GEDCOM file * - * @param $people array|PersonPageValues + * @param object $people array|PersonPageValues * * @return void */ public function addPeople( $people ) { - foreach ( $people as $person ) { $this->people[$person->title->getArticleID()] = $person; } @@ -37,7 +35,6 @@ * @return string */ public function getFile() { - if ( $this->file === '' ) { $this->setFile(); } diff --git a/PersonPageValues.php b/PersonPageValues.php index 5ee98e0..93c0c10 100644 --- a/PersonPageValues.php +++ b/PersonPageValues.php @@ -9,8 +9,7 @@ * @licence GNU GPL v2+ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> */ -class PersonPageValues -{ +class PersonPageValues { protected $page; public $title; public $fullname; @@ -31,10 +30,11 @@ /** * Constructor for a single indi in the file. + * + * @param SMWDIWikiPage $page the page */ public function __construct( SMWDIWikiPage $page ) { - - $values = array(); + $values = []; $storage = smwfGetStore(); $this->page = $page; $this->title = $page->getTitle(); @@ -59,6 +59,11 @@ } } + /** + * Get the page of the person + * + * @return SMWDIWikiPage the current page + */ public function getPage() { return $this->page; } @@ -69,12 +74,11 @@ * @return array */ public function getChildren() { - if ( $this->children !== null ) { return $this->children; } - $this->children = array(); + $this->children = []; $storage = smwfGetStore(); $properties = SemanticGenealogy::getProperties(); if ( $properties['father'] instanceof SMWDIProperty ) { @@ -90,7 +94,7 @@ } } - usort( $this->children, array( "PersonPageValues", "comparePeopleByBirthDate" ) ); + usort( $this->children, [ "PersonPageValues", "comparePeopleByBirthDate" ] ); return $this->children; } @@ -115,9 +119,13 @@ return $this->partner; } + /** + * Sorter to compare 2 persons based on their date of birth + * + * @return integer a comparaison integer + */ private static function comparePeopleByBirthDate( PersonPageValues $personA, PersonPageValues $personB ) { - if ( $personA->birthdate instanceof SMWDITime ) { $aKey = $personA->birthdate->getSortKey(); } else { @@ -155,8 +163,15 @@ return $this->title->getFullText(); } + /** + * Generate the Person description wiki text based on the special pages options + * + * @param boolean $withBr adding <br> tags or not + * @param string $displayName the display type tag + * + * @return string the text to display + */ public function getDescriptionWikiText( $withBr = false, $displayName = 'fullname' ) { - $yearRegexp = "/.*\b(\d\d\d\d)\b.*/"; $text = '<div class="person-block">'; $text .= '<div class="person-name">'; @@ -185,15 +200,27 @@ return $text; } + /** + * Get a string base on the SMWDITime object + * + * @param SMWDITime $dataItem the time item + * + * @return string the wiki text for a given date + */ protected static function getWikiTextDateFromSMWDITime( SMWDITime $dataItem ) { - $val = new SMWTimeValue( SMWDataItem::TYPE_TIME ); $val->setDataItem( $dataItem ); return $val->getShortWikiText(); } + /** + * Get the page from the pageName + * + * @param string $pageName the page name + * + * @return SMWDIWikiPage the page object + */ public static function getPageFromName( $pageName ) { - $pageTitle = Title::newFromText( $pageName ); return SMWDIWikiPage::newFromTitle( $pageTitle ); } diff --git a/SemanticGenealogy.alias.php b/SemanticGenealogy.alias.php index 4d249bc..a14b2e8 100644 --- a/SemanticGenealogy.alias.php +++ b/SemanticGenealogy.alias.php @@ -9,14 +9,14 @@ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> */ -$specialPageAliases = array(); +$specialPageAliases = []; /* English (English) */ -$specialPageAliases['en'] = array( - 'FamilyTree' => array( 'FamilyTree' ), -); +$specialPageAliases['en'] = [ + 'FamilyTree' => [ 'FamilyTree' ], +]; /* French (Français) */ -$specialPageAliases['fr'] = array( - 'FamilyTree' => array( 'ArbreGénéalogique' ), -); +$specialPageAliases['fr'] = [ + 'FamilyTree' => [ 'ArbreGénéalogique' ], +]; diff --git a/SemanticGenealogy.body.php b/SemanticGenealogy.body.php index 6461d8e..5ff326c 100644 --- a/SemanticGenealogy.body.php +++ b/SemanticGenealogy.body.php @@ -9,15 +9,16 @@ * @licence GNU GPL v2+ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> */ -class SemanticGenealogy -{ +class SemanticGenealogy { /** * Get an array key => value of genealogical properties as SMWDIProperty + * * @throws MWException + * + * @return array the properties array */ public static function getProperties() { - static $properties; if ( $properties !== null ) { @@ -25,7 +26,7 @@ } global $wgGenealogicalProperties; - $properties = array(); + $properties = []; if ( !is_array( $wgGenealogicalProperties ) ) { throw new MWException( 'Configuration variable $wgGenealogicalProperties must be an array !' ); diff --git a/SemanticGenealogy.i18n.php b/SemanticGenealogy.i18n.php index e13eff1..d127f33 100644 --- a/SemanticGenealogy.i18n.php +++ b/SemanticGenealogy.i18n.php @@ -10,13 +10,21 @@ * * This shim maintains compatibility back to MediaWiki 1.17. */ -$messages = array(); +$messages = []; if ( !function_exists( 'wfJsonI18nShimc57238e8287ad032' ) ) { + /** + * I have no idea what this does + * + * @param string $cache the cache + * @param string $code the code + * @param array &$cachedData the cachedData + * + * @return true + */ function wfJsonI18nShimc57238e8287ad032( $cache, $code, &$cachedData ) { - - $codeSequence = array_merge( array( $code ), $cachedData['fallbackSequence'] ); + $codeSequence = array_merge( [ $code ], $cachedData['fallbackSequence'] ); foreach ( $codeSequence as $csCode ) { - $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json"; + $fileName = __DIR__ . "/i18n/$csCode.json"; if ( is_readable( $fileName ) ) { $data = FormatJson::decode( file_get_contents( $fileName ), true ); foreach ( array_keys( $data ) as $key ) { diff --git a/SemanticGenealogy.php b/SemanticGenealogy.php index 4ae1cc4..9ac2559 100644 --- a/SemanticGenealogy.php +++ b/SemanticGenealogy.php @@ -47,18 +47,18 @@ define( 'SGENEA_VERSION', '0.3.0' ); } -$wgExtensionCredits['semantic'][] = array( +$wgExtensionCredits['semantic'][] = [ 'path' => __FILE__, 'name' => 'Semantic Genealogy', 'version' => SGENEA_VERSION, - 'author' => array( + 'author' => [ '[http://www.mediawiki.org/wiki/User:Tpt Tpt]' - ), + ], 'url' => 'https://www.mediawiki.org/wiki/Extension:Semantic_Genealogy', 'descriptionmsg' => 'semanticgenealogy-desc' -); +]; -$wgGenealogicalProperties = array( +$wgGenealogicalProperties = [ 'givenname' => 'Prénom', 'surname' => 'Nom', 'nickname' => '', @@ -69,9 +69,9 @@ 'deathplace' => 'Lieu de décès', 'father' => 'Père', 'mother' => 'Mère' -); +]; -$dir = dirname( __FILE__ ) . '/'; +$dir = __DIR__ . '/'; $dirTree = $dir.'src/Tree/'; $dirDecorator = $dir.'src/Decorator/'; @@ -103,18 +103,17 @@ $wgAutoloadClasses['SpecialFamilyTree'] = $dir . 'SpecialFamilyTree.php'; $wgSpecialPages['FamilyTree'] = 'SpecialFamilyTree'; -$moduleTemplate = array( +$moduleTemplate = [ 'localBasePath' => $dir, 'remoteBasePath' => ( $wgExtensionAssetsPath === false ? $wgScriptPath . '/extensions' : $wgExtensionAssetsPath ) . '/SemanticGenealogy', 'group' => 'ext.smg' -); +]; -$wgResourceModules['ext.smg.specialfamilytree'] = $moduleTemplate + array( +$wgResourceModules['ext.smg.specialfamilytree'] = $moduleTemplate + [ 'scripts' => 'modules/specialFamilyTree.js', 'styles' => 'modules/styles.css', - 'dependencies' => array( 'jquery.ui.autocomplete' ), - 'messages' => array( - ) -); - + 'dependencies' => [ 'jquery.ui.autocomplete' ], + 'messages' => [ + ] +]; diff --git a/SemanticGenealogyException.php b/SemanticGenealogyException.php index 08f3a86..6b578ff 100644 --- a/SemanticGenealogyException.php +++ b/SemanticGenealogyException.php @@ -9,9 +9,6 @@ * @licence GNU GPL v2+ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> */ -class SemanticGenealogyException extends Exception -{ - - +class SemanticGenealogyException extends Exception { } diff --git a/SpecialFamilyTree.php b/SpecialFamilyTree.php index 2c5adfc..b4dd480 100644 --- a/SpecialFamilyTree.php +++ b/SpecialFamilyTree.php @@ -9,8 +9,7 @@ * @licence GNU GPL v2+ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> */ -class SpecialFamilyTree extends SpecialPage -{ +class SpecialFamilyTree extends SpecialPage { private $type; private $gen; @@ -18,7 +17,7 @@ private $page2; private $decorator; - private $params = array( 'type', 'gen', 'page', 'page2', 'decorator', 'displayname' ); + private $params = [ 'type', 'gen', 'page', 'page2', 'decorator', 'displayname' ]; /** * @constructor @@ -43,7 +42,7 @@ if ( $par != '' ) { $parts = explode( '/', urldecode( $par ) ); } else { - $parts = array(); + $parts = []; } $this->type = isset( $parts[0] ) ? $parts[0] : $wgRequest->getText( 'type' ); @@ -125,12 +124,9 @@ /** * Display the search form for a genealogy tree * - * @param array $params the array of search parameters - * * @return void */ protected function showForm() { - global $wgScript; if ( !$this->mIncluding ) { @@ -150,7 +146,7 @@ $this->msg( 'semanticgenealogy-specialfamilytree-decorator-'.$decorator::NAME )->text(), $decorator::NAME - ); + ); } $displaynameSelect = new XmlSelect( 'displayname', 'displayname', $this->displayname ); @@ -160,60 +156,60 @@ $this->msg( 'semanticgenealogy-specialfamilytree-displayname-pagename' )->text(), 'pagename' ); $output->addHTML( - Xml::openElement( 'form', array( 'action' => $wgScript ) ) . + Xml::openElement( 'form', [ 'action' => $wgScript ] ) . Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) . Xml::openElement( 'fieldset' ) . - Xml::openElement( 'table', array( 'id' => 'smg-familyTree-form' ) ) . - Xml::openElement( 'tr', array( 'id' => 'smg-form-entry-page' ) ) . - Xml::openElement( 'th', array( 'class' => 'mw-label' ) ) . + Xml::openElement( 'table', [ 'id' => 'smg-familyTree-form' ] ) . + Xml::openElement( 'tr', [ 'id' => 'smg-form-entry-page' ] ) . + Xml::openElement( 'th', [ 'class' => 'mw-label' ] ) . Xml::label( $this->msg( 'semanticgenealogy-specialfamilytree-label-page' )->text(), 'page' ) . Xml::closeElement( 'th' ) . - Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . - Xml::input( 'page', 30, $this->page, array( 'class' => 'smg-input-page' ) ) . + Xml::openElement( 'td', [ 'class' => 'mw-input' ] ) . + Xml::input( 'page', 30, $this->page, [ 'class' => 'smg-input-page' ] ) . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) . - Xml::openElement( 'tr', array( 'id' => 'smg-form-entry-type' ) ) . - Xml::openElement( 'th', array( 'class' => 'mw-label' ) ) . + Xml::openElement( 'tr', [ 'id' => 'smg-form-entry-type' ] ) . + Xml::openElement( 'th', [ 'class' => 'mw-label' ] ) . Xml::label( $this->msg( 'semanticgenealogy-specialfamilytree-label-type' )->text(), 'type' ) . Xml::closeElement( 'th' ) . - Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . + Xml::openElement( 'td', [ 'class' => 'mw-input' ] ) . $typeSelect->getHtml() . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) . - Xml::openElement( 'tr', array( 'id' => 'smg-form-entry-decorator' ) ) . - Xml::openElement( 'th', array( 'class' => 'mw-label' ) ) . + Xml::openElement( 'tr', [ 'id' => 'smg-form-entry-decorator' ] ) . + Xml::openElement( 'th', [ 'class' => 'mw-label' ] ) . Xml::label( $this->msg( 'semanticgenealogy-specialfamilytree-label-decorator' )->text(), 'decorator' - ) . + ) . Xml::closeElement( 'th' ) . - Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . + Xml::openElement( 'td', [ 'class' => 'mw-input' ] ) . $decoratorSelect->getHtml() . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) . - Xml::openElement( 'tr', array( 'id' => 'smg-form-entry-displayname' ) ) . - Xml::openElement( 'th', array( 'class' => 'mw-label' ) ) . + Xml::openElement( 'tr', [ 'id' => 'smg-form-entry-displayname' ] ) . + Xml::openElement( 'th', [ 'class' => 'mw-label' ] ) . Xml::label( $this->msg( 'semanticgenealogy-specialfamilytree-label-displayname' )->text(), 'displayname' - ) . + ) . Xml::closeElement( 'th' ) . - Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . + Xml::openElement( 'td', [ 'class' => 'mw-input' ] ) . $displaynameSelect->getHtml() . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) . - Xml::openElement( 'tr', array( 'id' => 'smg-form-entry-gen' ) ) . - Xml::openElement( 'th', array( 'class' => 'mw-label' ) ) . + Xml::openElement( 'tr', [ 'id' => 'smg-form-entry-gen' ] ) . + Xml::openElement( 'th', [ 'class' => 'mw-label' ] ) . Xml::label( $this->msg( 'semanticgenealogy-specialfamilytree-label-gen' )->text(), 'gen' ) . Xml::closeElement( 'th' ) . - Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . + Xml::openElement( 'td', [ 'class' => 'mw-input' ] ) . Xml::input( 'gen', 2, $this->gen ) . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) . - Xml::openElement( 'tr', array( 'id' => 'smg-form-entry-page2' ) ) . - Xml::openElement( 'th', array( 'class' => 'mw-label' ) ) . + Xml::openElement( 'tr', [ 'id' => 'smg-form-entry-page2' ] ) . + Xml::openElement( 'th', [ 'class' => 'mw-label' ] ) . Xml::label( $this->msg( 'semanticgenealogy-specialfamilytree-label-page2' )->text(), 'page2' ) . Xml::closeElement( 'th' ) . - Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . - Xml::input( 'page2', 30, $this->page2, array( 'class' => 'smg-input-page' ) ) . + Xml::openElement( 'td', [ 'class' => 'mw-input' ] ) . + Xml::input( 'page2', 30, $this->page2, [ 'class' => 'smg-input-page' ] ) . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) . Xml::closeElement( 'table' ) . diff --git a/Tools.php b/Tools.php index 34decd6..f546378 100644 --- a/Tools.php +++ b/Tools.php @@ -2,12 +2,18 @@ -class Tools -{ +class Tools { + /** + * Find the subclasses of that superclass in one directory + * + * @param string $dir the directory + * @param string $superClass the superclass name + * + * @return array an array of $classes subclass of the superClass + */ public static function getSubclassesOf( $dir, $superClass ) { - - $classes = array(); + $classes = []; foreach ( new DirectoryIterator( $dir ) as $file ) { if ( $file->isDot() ) { continue; @@ -31,6 +37,5 @@ } } return $classes; - } } diff --git a/composer.json b/composer.json index ebbc185..3eac7bb 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "mediawiki/semantic-genealogy", "type": "mediawiki-extension", "description": "The Semantic Genealogy extension provides the ability to view genealogy trees and export GEDCOM files.", + "minimum-stability": "dev", "keywords": [ "Semantic", "Genealogy", @@ -22,7 +23,8 @@ } ], "require-dev": { - "mediawiki/mediawiki-codesniffer": "0.4.0" + "mediawiki/mediawiki-codesniffer": "~0.10", + "squizlabs/php_codesniffer": "3.0.1" }, "scripts": { "check": [ diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 64db2e9..0000000 --- a/composer.lock +++ /dev/null @@ -1,127 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "hash": "a001a27134e4fbdccc75cc02e158ac01", - "content-hash": "dcc8a4334f91f8746bdcb22a0b10677d", - "packages": [], - "packages-dev": [ - { - "name": "mediawiki/mediawiki-codesniffer", - "version": "v0.4.0", - "source": { - "type": "git", - "url": "https://github.com/wikimedia/mediawiki-tools-codesniffer.git", - "reference": "0104c7063441e179ee0a6598e0a028223bf480dd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/wikimedia/mediawiki-tools-codesniffer/zipball/0104c7063441e179ee0a6598e0a028223bf480dd", - "reference": "0104c7063441e179ee0a6598e0a028223bf480dd", - "shasum": "" - }, - "require": { - "squizlabs/php_codesniffer": "2.3.4" - }, - "require-dev": { - "jakub-onderka/php-parallel-lint": "0.9.*", - "phpunit/phpunit": "~4.1.0" - }, - "type": "library", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-2.0+" - ], - "description": "MediaWiki CodeSniffer Standards", - "homepage": "https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP", - "keywords": [ - "codesniffer", - "mediawiki" - ], - "time": "2015-09-26 21:34:16" - }, - { - "name": "squizlabs/php_codesniffer", - "version": "2.3.4", - "source": { - "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "11a2545c44a5915f883e2e5ec12e14ed345e3ab2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/11a2545c44a5915f883e2e5ec12e14ed345e3ab2", - "reference": "11a2545c44a5915f883e2e5ec12e14ed345e3ab2", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "php": ">=5.1.2" - }, - "bin": [ - "scripts/phpcs", - "scripts/phpcbf" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Greg Sherwood", - "role": "lead" - } - ], - "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "http://www.squizlabs.com/php-codesniffer", - "keywords": [ - "phpcs", - "standards" - ], - "time": "2015-09-09 00:18:50" - } - ], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [] -} diff --git a/src/Decorator/BoxDecorator.php b/src/Decorator/BoxDecorator.php index 8552bb3..c77d08a 100644 --- a/src/Decorator/BoxDecorator.php +++ b/src/Decorator/BoxDecorator.php @@ -2,14 +2,9 @@ -class BoxDecorator extends TreeDecorator -{ +class BoxDecorator extends TreeDecorator { const NAME = 'box'; const LABEL = 'Boîtes'; - - - - } diff --git a/src/Decorator/SimpleDecorator.php b/src/Decorator/SimpleDecorator.php index 7b629ad..c627c29 100644 --- a/src/Decorator/SimpleDecorator.php +++ b/src/Decorator/SimpleDecorator.php @@ -4,14 +4,12 @@ -class SimpleDecorator extends TreeDecorator -{ - +class SimpleDecorator extends TreeDecorator { const NAME = 'simple'; const LABEL = 'Simple'; - + /* public function getTreeHeader() { return '<table style="text-align:center;">'; } @@ -43,6 +41,6 @@ public function getPersonFooter() { return '</td>'; } - + */ } diff --git a/src/Decorator/TreeDecorator.php b/src/Decorator/TreeDecorator.php index d4ea6ef..4f356cc 100644 --- a/src/Decorator/TreeDecorator.php +++ b/src/Decorator/TreeDecorator.php @@ -1,11 +1,9 @@ <?php -abstract class TreeDecorator -{ +abstract class TreeDecorator { const NAME = 'root'; const LABEL = 'Root'; - } diff --git a/src/Decorator/TreeDecoratorFactory.php b/src/Decorator/TreeDecoratorFactory.php index 82d6d46..488f086 100644 --- a/src/Decorator/TreeDecoratorFactory.php +++ b/src/Decorator/TreeDecoratorFactory.php @@ -1,8 +1,7 @@ <?php -class TreeDecoratorFactory -{ +class TreeDecoratorFactory { /** * Create a new FamilyTree object @@ -30,6 +29,5 @@ public static function listDecorators() { return Tools::getSubclassesOf( __DIR__, 'TreeDecorator' ); } - } diff --git a/src/Tree/AncestorsFamilyTree.php b/src/Tree/AncestorsFamilyTree.php index fea4360..0c3a7b1 100644 --- a/src/Tree/AncestorsFamilyTree.php +++ b/src/Tree/AncestorsFamilyTree.php @@ -12,8 +12,7 @@ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> * @author Thibault Taillandier <thiba...@taillandier.name> */ -class AncestorsFamilyTree extends FamilyTree -{ +class AncestorsFamilyTree extends FamilyTree { const NAME = 'ancestors'; @@ -23,8 +22,7 @@ * @return array the generations tree */ private function getAncestors() { - - $tree = array(); + $tree = []; $tree[0][1] = new PersonPageValues( $this->person ); for ( $i = 0; $i < $this->numOfGenerations && $tree[$i] !== null; $i++ ) { @@ -33,14 +31,12 @@ return $tree; } - /** * Render the tree of ancestors * * @return void */ public function render() { - $tree = $this->getAncestors(); $output = $this->getOutput(); $output->addHTML( '<table class="decorator-'.$this->decorator. ' smg-tree-root-ancestors">' ); diff --git a/src/Tree/DescendantFamilyTree.php b/src/Tree/DescendantFamilyTree.php index 0cdc98b..5d66d05 100644 --- a/src/Tree/DescendantFamilyTree.php +++ b/src/Tree/DescendantFamilyTree.php @@ -12,36 +12,16 @@ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> * @author Thibault Taillandier <thiba...@taillandier.name> */ -class DescendantFamilyTree extends FamilyTree -{ +class DescendantFamilyTree extends FamilyTree { const NAME = 'descendant'; /** - * List the descendants for all needed generations + * Show the descendants tree * - * @return void + * @param object $person the target person to create the descendant tree + * @param integer $numberOfGenerations number of generation to display */ - private function outputDescendantLine( $person, $pellissier, $end ) { - - $output = $this->getOutput(); - $output->addHTML( '<div class="descendant-line">' ); - $children = $person->getChildren(); - $count = 1; - $depth = substr_count( $pellissier, '.' )+1; - foreach ( $children as $child ) { - $pel = $pellissier . $count . '.'; - $output->addHtml( '<span class="number depth-'.$depth.'">'.$pel.'</span> ' ); - $output->addWikiText( $child->getDescriptionWikiText( false ) ); - if ( $end > 0 ) { - $this->outputDescendantLine( $child, $pel, $end - 1 ); - } - $count++; - } - $output->addHTML( '</div>' ); - } - - private function showDescendants( $person, $numOfGenerations, $top = false ) { - + private function showDescendants( $person, $numOfGenerations ) { $output = $this->getOutput(); if ( $numOfGenerations == 0 ) { return true; @@ -110,7 +90,15 @@ return $person; } - public function getClass( $itemNumber, $nbChildren ) { + /** + * Determine the class to display + * + * @param integer $itemNumber the number of the current item + * @param integer $nbChildren the number of total children + * + * @return string the class name + */ + private function getClass( $itemNumber, $nbChildren ) { if ( $nbChildren == 1 ) { return "child-one"; } @@ -129,9 +117,8 @@ * @return void */ public function render() { - $output = $this->getOutput(); $person = new PersonPageValues( $this->person ); - $this->showDescendants( $person, 4, true ); + $this->showDescendants( $person, 4 ); } } diff --git a/src/Tree/DescendantListFamilyTree.php b/src/Tree/DescendantListFamilyTree.php index a945393..e6e7490 100644 --- a/src/Tree/DescendantListFamilyTree.php +++ b/src/Tree/DescendantListFamilyTree.php @@ -12,17 +12,19 @@ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> * @author Thibault Taillandier <thiba...@taillandier.name> */ -class DescendantListFamilyTree extends FamilyTree -{ +class DescendantListFamilyTree extends FamilyTree { const NAME = 'descendantlist'; /** * List the descendants for all needed generations * + * @param PersonPageValues $person the person object + * @param string $pellissier I don't know + * @param integer $end counter to know wether we should stop + * * @return void */ private function outputDescendantLine( $person, $pellissier, $end ) { - $output = $this->getOutput(); $output->addHTML( '<div class="descendant-line">' ); $children = $person->getChildren(); @@ -46,7 +48,6 @@ * @return void */ public function render() { - $output = $this->getOutput(); $output->addHTML( '<div class="decorator-'.$this->decorator. ' smg-tree-root-descendant">' ); $main = new PersonPageValues( $this->person ); diff --git a/src/Tree/FamilyTree.php b/src/Tree/FamilyTree.php index d710262..18ccc48 100644 --- a/src/Tree/FamilyTree.php +++ b/src/Tree/FamilyTree.php @@ -14,8 +14,7 @@ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> * @author Thibault Taillandier <thiba...@taillandier.name> */ -abstract class FamilyTree -{ +abstract class FamilyTree { const NAME = 'root'; @@ -26,7 +25,11 @@ protected $decorator; protected $displayName; - + /** + * @constructor + * + * @param string $decorator the decorator name + */ public function __construct( $decorator=null ) { $this->decorator = $decorator; } @@ -39,7 +42,6 @@ * @return void */ public function setPerson( $personName ) { - $this->personName = $personName; $this->person = PersonPageValues::getPageFromName( $personName ); } @@ -52,7 +54,6 @@ * @return void */ public function setNumberOfGenerations( $numOfGenerations ) { - $this->numOfGenerations = $numOfGenerations; } @@ -64,7 +65,6 @@ * @return void */ public function setDisplayName( $displayName ) { - $this->displayName = $displayName; } @@ -76,7 +76,6 @@ * @return void */ public function setOutput( $output ) { - $this->output = $output; } @@ -86,7 +85,6 @@ * @return OutputPage the output object */ public function getOutput() { - return $this->output; } @@ -97,7 +95,6 @@ * @return int */ public function getNumOfPeopleInGen( $gen ) { - $result = 1; for ( $i = 0; $i < $gen; $i++ ) { $result *= 2; @@ -105,17 +102,15 @@ return $result; } - /** * Add a generation in a tree * * @param integer $gen the generation number - * @param array $tree the tree to add in + * @param array $tree the tree to add in * * @return array the resulting tree */ protected function addGenInTree( $gen, array $tree ) { - $empty = true; $son = $this->getNumOfPeopleInGen( $gen - 1 ); $end = $son * 4; @@ -150,7 +145,6 @@ return $tree; } - /** * Render the tree * @@ -160,7 +154,6 @@ * @return void */ public function render() { - $this->output->addHtml( "" ); } } diff --git a/src/Tree/FamilyTreeFactory.php b/src/Tree/FamilyTreeFactory.php index 2fc6ad0..a1bbc5d 100644 --- a/src/Tree/FamilyTreeFactory.php +++ b/src/Tree/FamilyTreeFactory.php @@ -11,13 +11,13 @@ * @licence GNU GPL v2+ * @author Thibault Taillandier <thiba...@taillandier.name> */ -class FamilyTreeFactory -{ +class FamilyTreeFactory { /** * Create a new FamilyTree object * * @param string $name the name of the wanted FamilyTree + * @param string $decorator the decorator name * * @return object a new FamilyTree Object */ @@ -38,8 +38,6 @@ * @return array the list of FamilyTree classes availables */ public static function listTrees() { - return Tools::getSubclassesOf( __DIR__, 'FamilyTree' ); - } } diff --git a/src/Tree/LinkFamilyTree.php b/src/Tree/LinkFamilyTree.php index 37b15d7..eb97185 100644 --- a/src/Tree/LinkFamilyTree.php +++ b/src/Tree/LinkFamilyTree.php @@ -13,8 +13,7 @@ * @author Thomas Pellissier Tanon <thoma...@hotmail.fr> * @author Thibault Taillandier <thiba...@taillandier.name> */ -class LinkFamilyTree extends FamilyTree -{ +class LinkFamilyTree extends FamilyTree { const NAME = 'link'; @@ -31,11 +30,9 @@ * @return void */ public function setPerson2( $personName2 ) { - $this->personName2 = $personName2; $this->person2 = PersonPageValues::getPageFromName( $personName2 ); } - /** * Get the relation between the 2 persons (this->person and $this->person2) @@ -43,9 +40,8 @@ * @return array an array of 2 trees */ private function getLink() { - - $tree1 = array(); - $tree2 = array(); + $tree1 = []; + $tree2 = []; $tree1[0][1] = new PersonPageValues( $this->person ); $tree2[0][1] = new PersonPageValues( $this->person2 ); @@ -70,8 +66,8 @@ } if ( $result !== null ) { - return array( $this->getListOfAncestors( $sosa1, $tree1 ), - $this->getListOfAncestors( $sosa2, $tree2 ) ); + return [ $this->getListOfAncestors( $sosa1, $tree1 ), + $this->getListOfAncestors( $sosa2, $tree2 ) ]; } } @@ -85,7 +81,6 @@ * @return array an array of 2 SOSA */ private function compareGenWith( array $gen, array $tree, $max ) { - for ( $i = $max; $i >= 0; $i-- ) { if ( isset( $tree[$i] ) ) { foreach ( $tree[$i] as $sosa2 => $person2 ) { @@ -93,7 +88,7 @@ foreach ( $gen as $sosa1 => $person1 ) { if ( $person1 !== null ) { if ( $person1->title->equals( $person2->title ) ) { - return array( $sosa1, $sosa2 ); + return [ $sosa1, $sosa2 ]; } } } @@ -102,7 +97,6 @@ } } } - /** * Get the list of ancestors for a sosa number @@ -113,7 +107,6 @@ * @return array the list of ancestors */ private function getListOfAncestors( $sosa, array $tree ) { - $num = 1; $temp = 1; for ( $i = 0; $num < $sosa; $i++ ) { @@ -121,7 +114,7 @@ $num += $temp; } - $list = array(); + $list = []; for ( $j = $i; $j >= 0; $j-- ) { $list[] = $tree[$j][$sosa]; $sosa /= 2; @@ -135,7 +128,6 @@ * @return void */ public function render() { - $output = $this->getOutput(); $tree = $this->getLink(); -- To view, visit https://gerrit.wikimedia.org/r/370594 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I726a246e89c8b5b381f7ff1233ca59019ae86d57 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