http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89602
Revision: 89602
Author: foxtrott
Date: 2011-06-06 20:49:35 +0000 (Mon, 06 Jun 2011)
Log Message:
-----------
small fixes (mostly comments and formatting)
Modified Paths:
--------------
trunk/extensions/Lingo/Lingo.php
trunk/extensions/Lingo/LingoBackend.php
trunk/extensions/Lingo/LingoBasicBackend.php
trunk/extensions/Lingo/LingoParser.php
trunk/extensions/Lingo/LingoTree.php
Modified: trunk/extensions/Lingo/Lingo.php
===================================================================
--- trunk/extensions/Lingo/Lingo.php 2011-06-06 20:43:13 UTC (rev 89601)
+++ trunk/extensions/Lingo/Lingo.php 2011-06-06 20:49:35 UTC (rev 89602)
@@ -1,4 +1,5 @@
<?php
+
/**
* Provides hover-over tool tips on articles from words defined on the
* Terminology page.
@@ -18,10 +19,10 @@
define( 'LINGO_VERSION', '0.2 alpha' );
-$wgExtensionCredits[ 'parserhook' ][ ] = array(
+$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'Lingo',
- 'author' => array( 'Barry Coughlan',
'[http://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]' ),
+ 'author' => array('Barry Coughlan',
'[http://www.mediawiki.org/wiki/User:F.trott Stephan Gambke]'),
'url' => 'http://www.mediawiki.org/wiki/Extension:Lingo',
'description' => 'Provides hover-over tool tips on articles from words
defined on the [[Terminology]] page',
'version' => LINGO_VERSION,
@@ -29,6 +30,8 @@
// server-local path to this file
$wgexLingoDir = dirname( __FILE__ );
+
+// set LingoBasicBackend as the backend to access the glossary
$wgexLingoBackend = 'LingoBasicBackend';
// register message file
Modified: trunk/extensions/Lingo/LingoBackend.php
===================================================================
--- trunk/extensions/Lingo/LingoBackend.php 2011-06-06 20:43:13 UTC (rev
89601)
+++ trunk/extensions/Lingo/LingoBackend.php 2011-06-06 20:49:35 UTC (rev
89602)
@@ -23,14 +23,19 @@
public function __construct( LingoMessageLog &$messages = null ) {
$this->mMessageLog = $messages;
+ }
+ public function getMessageLog() {
+ return $this->mMessageLog;
}
/**
+ * This function returns the next element. The element is an array of
four
+ * strings: Term, Definition, Link, Source. If there is no next element
the
+ * function returns null.
*
* @return the next element or null
*/
abstract public function next();
-
}
Modified: trunk/extensions/Lingo/LingoBasicBackend.php
===================================================================
--- trunk/extensions/Lingo/LingoBasicBackend.php 2011-06-06 20:43:13 UTC
(rev 89601)
+++ trunk/extensions/Lingo/LingoBasicBackend.php 2011-06-06 20:49:35 UTC
(rev 89602)
@@ -39,8 +39,12 @@
}
/**
+ * This function returns the next element. The element is an array of
four
+ * strings: Term, Definition, Link, Source. For the LingoBasicBackend
Link
+ * and Source are set to null. If there is no next element the function
+ * returns null.
*
- * @return Boolean true, if a next element is available
+ * @return Array the next element or null
*/
public function next() {
Modified: trunk/extensions/Lingo/LingoParser.php
===================================================================
--- trunk/extensions/Lingo/LingoParser.php 2011-06-06 20:43:13 UTC (rev
89601)
+++ trunk/extensions/Lingo/LingoParser.php 2011-06-06 20:49:35 UTC (rev
89602)
@@ -22,14 +22,14 @@
*/
class LingoParser {
- private $mLingoArray = null;
private $mLingoTree = null;
private $mLingoBackend = null;
private static $parserSingleton = null;
- public function __construct() {
+ public function __construct( LingoMessageLog &$messages = null ) {
global $wgexLingoBackend;
- $this->mLingoBackend = new $wgexLingoBackend( new
LingoMessageLog() );
+
+ $this->mLingoBackend = new $wgexLingoBackend( $messages );
}
/**
@@ -56,17 +56,17 @@
*
* @return Array an array mapping terms (keys) to descriptions (values)
*/
- function getLingoArray( LingoMessageLog &$messages = null ) {
+ function getLingoArray() {
wfProfileIn( __METHOD__ );
// build glossary array only once per request
- if ( !$this->mLingoArray ) {
- $this->buildLingo( $messages );
+ if ( !$this->mLingoTree ) {
+ $this->buildLingo();
}
wfProfileOut( __METHOD__ );
- return $this->mLingoArray;
+ return $this->mLingoTree->getTermList();
}
/**
@@ -74,12 +74,12 @@
*
* @return LingoTree a LingoTree mapping terms (keys) to descriptions
(values)
*/
- function getLingoTree( LingoMessageLog &$messages = null ) {
+ function getLingoTree() {
wfProfileIn( __METHOD__ );
// build glossary array only once per request
if ( !$this->mLingoTree ) {
- $this->buildLingo( $messages );
+ $this->buildLingo();
}
wfProfileOut( __METHOD__ );
@@ -87,7 +87,7 @@
return $this->mLingoTree;
}
- protected function buildLingo( LingoMessageLog &$messages = null ) {
+ protected function buildLingo() {
wfProfileIn( __METHOD__ );
$this->mLingoTree = new LingoTree();
Modified: trunk/extensions/Lingo/LingoTree.php
===================================================================
--- trunk/extensions/Lingo/LingoTree.php 2011-06-06 20:43:13 UTC (rev
89601)
+++ trunk/extensions/Lingo/LingoTree.php 2011-06-06 20:49:35 UTC (rev
89602)
@@ -39,15 +39,14 @@
}
if ( isset( $this->mList[$term] ) ) { // term exists, store 2nd
definition
-
- $this->mList[$term][-1]->addDefinition( $definition );
-
+ $this->mList[$term]->addDefinition( $definition );
} else {
$matches;
preg_match_all( '/[[:alpha:]]+|[^[:alpha:]]/u', $term,
$matches );
- $this->mList[$term] = $this->addElement( $matches[0],
$term, $definition );
+ $elt = $this->addElement( $matches[0], $term,
$definition );
+ $this->mList[$term] = &$elt[-1];
$this->mMinLength = min( array($this->mMinLength,
strlen( $term )) );
}
@@ -56,8 +55,9 @@
/**
* Adds an element to the Lingo Tree
*
- * @param array $path
- * @param <type> $index
+ * @param array $path An array containing the constituing lexemes of
the term
+ * @param String $term
+ * @param String $definition
* @return Array the tree node the element was stored in
*/
protected function &addElement( Array &$path, &$term, &$definition ) {
@@ -72,7 +72,6 @@
}
$tree = &$tree[$step];
-
}
if ( isset( $tree[-1] ) ) {
@@ -88,6 +87,10 @@
return $this->mMinLength;
}
+ function getTermList() {
+ return $this->mList;
+ }
+
function findNextTerm( &$lexemes, $index, $countLexemes ) {
wfProfileIn( __METHOD__ );
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs