Euvl has uploaded a new change for review. https://gerrit.wikimedia.org/r/70802
Change subject: Support for multiple definitions per term ...................................................................... Support for multiple definitions per term Change-Id: I4e1d0651b3d66bada92db9c3a1c76cdd6de1529c --- M LingoBasicBackend.php M LingoElement.php 2 files changed, 27 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Lingo refs/changes/02/70802/1 diff --git a/LingoBasicBackend.php b/LingoBasicBackend.php index 09072dc..cab7084 100644 --- a/LingoBasicBackend.php +++ b/LingoBasicBackend.php @@ -53,6 +53,7 @@ } $content = $rev->getText(); + } $this->mArticleLines = array_reverse(explode( "\n", $content )); @@ -71,8 +72,8 @@ wfProfileIn( __METHOD__ ); $ret = null; - $term = null; - static $definition = null; + static $term = null; + static $definitions = null; // find next valid line (yes, the assignation is intended) while ( ( $ret == null ) && ( $entry = each( $this->mArticleLines ) ) ) { @@ -83,25 +84,31 @@ $chunks = explode( ':', $entry[1], 2 ); - // found a new term? - if ( count( $chunks ) >= 1 && strlen( $chunks[0] ) >= 1 ) { - $term = trim( substr( $chunks[0], 1 ) ); - } + // found a new definition? + if ( count ( $chunks ) == 2 ) { + // if definitions and term are already set, and now goes definition again, + // it means that we work with a totally new term and have to remove previous data + // from static variables + if ($definitions && $term) { + $definitions = []; + $term = null; + } + $definitions[] = trim( $chunks[1] ); + } - // found a new definition? - if ( count ( $chunks ) == 2 ) { - $definition = trim( $chunks[1] ); + // found a new term? + if (count( $chunks ) >= 1 && strlen( $chunks[0] ) >= 1 ) { + $term = trim( substr( $chunks[0], 1 ) ); } if ( $term !== null ) { $ret = array( LingoElement::ELEMENT_TERM => $term, - LingoElement::ELEMENT_DEFINITION => $definition, + LingoElement::ELEMENT_DEFINITIONS => $definitions, LingoElement::ELEMENT_LINK => null, LingoElement::ELEMENT_SOURCE => null ); } - } wfProfileOut( __METHOD__ ); diff --git a/LingoElement.php b/LingoElement.php index 0a2733f..e1d1b36 100644 --- a/LingoElement.php +++ b/LingoElement.php @@ -20,7 +20,7 @@ */ class LingoElement { const ELEMENT_TERM = 0; - const ELEMENT_DEFINITION = 1; + const ELEMENT_DEFINITIONS = 1; const ELEMENT_SOURCE = 2; const ELEMENT_LINK = 3; @@ -60,7 +60,7 @@ // if there is only one link available, just insert the link if ( count( $this->mDefinitions ) === 1 - && !is_string( $this->mDefinitions[0][self::ELEMENT_DEFINITION] ) + && !is_string( $this->mDefinitions[0][self::ELEMENT_DEFINITIONS] ) && is_string( $this->mDefinitions[0][self::ELEMENT_LINK] ) ) { // create Title object for target page @@ -112,6 +112,7 @@ // Wrap term in <span> tag, hidden wfSuppressWarnings(); $spanTerm = $doc->createElement( 'span', htmlentities( $this->mTerm, ENT_COMPAT, 'UTF-8' ) ); + wfRestoreWarnings(); $spanTerm->setAttribute( 'class', 'tooltip_abbr' ); @@ -124,7 +125,11 @@ foreach ( $this->mDefinitions as $definition ) { wfSuppressWarnings(); - $element = $doc->createElement( 'span', htmlentities( $definition[self::ELEMENT_DEFINITION], ENT_COMPAT, 'UTF-8' ) ); + $definitions = null; + foreach ($definition[self::ELEMENT_DEFINITIONS] as $def) { + $definitions .= $def . ', '; + } + $element = $doc->createElement( 'span', htmlentities(trim($definitions, ', '), ENT_COMPAT, 'UTF-8' ) ); wfRestoreWarnings(); if ( $definition[self::ELEMENT_LINK] ) { $linkedTitle = Title::newFromText( $definition[self::ELEMENT_LINK] ); @@ -166,7 +171,7 @@ } public function getDefinition( &$key ) { - return $this->mDefinitions[$key][self::ELEMENT_DEFINITION]; + return $this->mDefinitions[$key][self::ELEMENT_DEFINITIONS]; } public function getLink( &$key ) { -- To view, visit https://gerrit.wikimedia.org/r/70802 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4e1d0651b3d66bada92db9c3a1c76cdd6de1529c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Lingo Gerrit-Branch: master Gerrit-Owner: Euvl <eu.vlase...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits