r100367 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100366‎ | r100367 | r100368 >
Date:19:37, 20 October 2011
Author:foxtrott
Status:deferred
Tags:
Comment:
Allow use of one definition for more than one term, e.g. to allow for grammatical variants
Modified paths:
  • /trunk/extensions/Lingo/LingoBasicBackend.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Lingo/LingoBasicBackend.php
@@ -43,8 +43,7 @@
4444
4545 $content = $rev->getText();
4646
47 - $term = array();
48 - $this->mArticleLines = explode( "\n", $content );
 47+ $this->mArticleLines = array_reverse(explode( "\n", $content ));
4948 }
5049
5150 /**
@@ -58,26 +57,37 @@
5958 public function next() {
6059
6160 $ret = null;
 61+ static $term = null;
 62+ static $definition = null;
6263
6364 // find next valid line (yes, the assignation is intended)
6465 while ( ( $ret == null ) && ( $entry = each( $this->mArticleLines ) ) ) {
6566
66 - if ( empty( $entry[1] ) || $entry[1][0] !== ';' ) {
 67+ if ( empty( $entry[1] ) || ($entry[1][0] !== ';' && $entry[1][0] !== ':')) {
6768 continue;
6869 }
6970
70 - $terms = explode( ':', $entry[1], 2 );
 71+ $chunks = explode( ':', $entry[1], 2 );
7172
72 - if ( count( $terms ) < 2 ) {
73 - continue; // Invalid syntax
 73+ // found a new term?
 74+ if ( $chunks[0] ) {
 75+ $term = trim( substr( $chunks[0], 1 ) );
7476 }
 77+
 78+ // found a new definition?
 79+ if ( count ( $chunks ) == 2 ) {
 80+ $definition = trim( $chunks[1] );
 81+ }
7582
76 - $ret = array(
77 - LingoElement::ELEMENT_TERM => trim( substr( $terms[0], 1 ) ),
78 - LingoElement::ELEMENT_DEFINITION => trim( $terms[1] ),
79 - LingoElement::ELEMENT_LINK => null,
80 - LingoElement::ELEMENT_SOURCE => null
81 - );
 83+ if ( $term !== null ) {
 84+ $ret = array(
 85+ LingoElement::ELEMENT_TERM => $term,
 86+ LingoElement::ELEMENT_DEFINITION => $definition,
 87+ LingoElement::ELEMENT_LINK => null,
 88+ LingoElement::ELEMENT_SOURCE => null
 89+ );
 90+ }
 91+
8292 }
8393
8494 return $ret;

Status & tagging log