Foxtrott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/275220

Change subject: Cleanup
......................................................................

Cleanup

Change-Id: I1c50f179eafc7f45133ca5f9d77c1586a26418fa
---
M src/Lingo.i18n.magic.php
M src/LingoBackend.php
M src/LingoBasicBackend.php
M src/LingoElement.php
M src/LingoHooks.php
M src/LingoMessageLog.php
M src/LingoParser.php
M src/LingoTree.php
8 files changed, 202 insertions(+), 153 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Lingo 
refs/changes/20/275220/1

diff --git a/src/Lingo.i18n.magic.php b/src/Lingo.i18n.magic.php
index 3a3218d..af1f283 100644
--- a/src/Lingo.i18n.magic.php
+++ b/src/Lingo.i18n.magic.php
@@ -9,81 +9,81 @@
 $magicWords = array();
 
 /** English (English) */
-$magicWords['en'] = array(
+$magicWords[ 'en' ] = array(
        'noglossary' => array( 0, '__NOGLOSSARY__' ),
 );
 
 /** Arabic (العربية) */
-$magicWords['ar'] = array(
+$magicWords[ 'ar' ] = array(
        'noglossary' => array( 0, '__لا_قاموس__' ),
 );
 
 /** Egyptian Arabic (مصرى) */
-$magicWords['arz'] = array(
+$magicWords[ 'arz' ] = array(
        'noglossary' => array( 0, '__من_غير_قاموس__' ),
 );
 
 /** German (Deutsch) */
-$magicWords['de'] = array(
+$magicWords[ 'de' ] = array(
        'noglossary' => array( 0, '__KEINGLOSSAR__', '__KEIN_GLOSSAR__' ),
 );
 
 /** Zazaki (Zazaki) */
-$magicWords['diq'] = array(
+$magicWords[ 'diq' ] = array(
        'noglossary' => array( 0, 'QISEBENDÇINİYO' ),
 );
 
 /** Esperanto (Esperanto) */
-$magicWords['eo'] = array(
+$magicWords[ 'eo' ] = array(
        'noglossary' => array( 0, '__NEDIFINO__' ),
 );
 
 /** French (français) */
-$magicWords['fr'] = array(
+$magicWords[ 'fr' ] = array(
        'noglossary' => array( 0, '__SANSGLOSSAIRE__' ),
 );
 
 /** Italian (italiano) */
-$magicWords['it'] = array(
+$magicWords[ 'it' ] = array(
        'noglossary' => array( 0, '__NOGLOSSARIO__' ),
 );
 
 /** Korean (한국어) */
-$magicWords['ko'] = array(
+$magicWords[ 'ko' ] = array(
        'noglossary' => array( 0, '__용어집없음__' ),
 );
 
 /** Macedonian (македонски) */
-$magicWords['mk'] = array(
+$magicWords[ 'mk' ] = array(
        'noglossary' => array( 0, '__БЕЗПОИМНИК__' ),
 );
 
 /** Malayalam (മലയാളം) */
-$magicWords['ml'] = array(
+$magicWords[ 'ml' ] = array(
        'noglossary' => array( 0, '__ചുരുക്കംവേണ്ട__' ),
 );
 
 /** Low Saxon (Netherlands) (Nedersaksies) */
-$magicWords['nds-nl'] = array(
+$magicWords[ 'nds-nl' ] = array(
        'noglossary' => array( 0, '__GIEN_GLOSSARIUM__' ),
 );
 
 /** Dutch (Nederlands) */
-$magicWords['nl'] = array(
+$magicWords[ 'nl' ] = array(
        'noglossary' => array( 0, '___GEENWOORDENLIJST__' ),
 );
 
 /** Serbian (Latin script) (srpski (latinica)‎) */
-$magicWords['sr-el'] = array(
+$magicWords[ 'sr-el' ] = array(
        'noglossary' => array( 0, '__BEZREČNIKA__', '__BEZ_REČNIKA__' ),
 );
 
 /** Turkish (Türkçe) */
-$magicWords['tr'] = array(
+$magicWords[ 'tr' ] = array(
        'noglossary' => array( 0, '__SÖZLÜKYOK__' ),
 );
 
 /** Simplified Chinese (中文(简体)‎) */
-$magicWords['zh-hans'] = array(
+$magicWords[ 'zh-hans' ] = array(
        'noglossary' => array( 0, '__无词汇表__' ),
-);
\ No newline at end of file
+);
diff --git a/src/LingoBackend.php b/src/LingoBackend.php
index e64741a..383ee69 100644
--- a/src/LingoBackend.php
+++ b/src/LingoBackend.php
@@ -35,6 +35,10 @@
 
        protected $mMessageLog;
 
+       /**
+        * LingoBackend constructor.
+        * @param LingoMessageLog|null $messages
+        */
        public function __construct( LingoMessageLog &$messages = null ) {
 
                if ( !$messages ) {
@@ -44,6 +48,9 @@
                }
        }
 
+       /**
+        * @return LingoMessageLog
+        */
        public function getMessageLog() {
                return $this->mMessageLog;
        }
@@ -65,7 +72,7 @@
         * strings: Term, Definition, Link, Source. If there is no next element 
the
         * function returns null.
         *
-        * @return the next element or null
+        * @return LingoElement | null
         */
        abstract public function next();
 }
diff --git a/src/LingoBasicBackend.php b/src/LingoBasicBackend.php
index 84d80c2..d872cd0 100644
--- a/src/LingoBasicBackend.php
+++ b/src/LingoBasicBackend.php
@@ -35,6 +35,10 @@
 
        protected $mArticleLines = array();
 
+       /**
+        * LingoBasicBackend constructor.
+        * @param LingoMessageLog|null $messages
+        */
        public function __construct( LingoMessageLog &$messages = null ) {
 
                global $wgexLingoPage, $wgRequest;
@@ -46,7 +50,7 @@
                // Get Terminology page
                $title = Title::newFromText( $page );
                if ( $title->getInterwiki() ) {
-                       $this->getMessageLog()->addError( wfMessage( 
'lingo-terminologypagenotlocal' , $page )->inContentLanguage()->text() );
+                       $this->getMessageLog()->addError( wfMessage( 
'lingo-terminologypagenotlocal', $page )->inContentLanguage()->text() );
                        return false;
                }
 
@@ -55,7 +59,8 @@
                // here, i.e. $rev->getText() would return outdated Test.
                // This hack takes the text directly out of the data from the 
web request.
                if ( $wgRequest->getVal( 'action', 'view' ) === 'submit'
-                               && Title::newFromText( $wgRequest->getVal( 
'title' ) )->getArticleID() === $title->getArticleID() ) {
+                       && Title::newFromText( $wgRequest->getVal( 'title' ) 
)->getArticleID() === $title->getArticleID()
+               ) {
 
                        $content = $wgRequest->getVal( 'wpTextbox1' );
 
@@ -70,12 +75,12 @@
 
                }
 
-               $parser  = new Parser;
+               $parser = new Parser;
                // expand templates and variables in the text, producing valid, 
static wikitext
                // have to use a new anonymous user to avoid any leakage as 
Lingo is caching only one user-independant glossary
                $content = $parser->preprocess( $content, $title, new 
ParserOptions( new User() ) );
 
-               $this->mArticleLines = array_reverse(explode( "\n", $content ));
+               $this->mArticleLines = array_reverse( explode( "\n", $content ) 
);
        }
 
        /**
@@ -84,7 +89,7 @@
         * and Source are set to null. If there is no next element the function
         * returns null.
         *
-        * @return Array the next element or null
+        * @return Array | null
         */
        public function next() {
 
@@ -97,36 +102,36 @@
                // find next valid line (yes, the assignation is intended)
                while ( ( count( $ret ) == 0 ) && ( $entry = each( 
$this->mArticleLines ) ) ) {
 
-                       if ( empty( $entry[1] ) || ($entry[1][0] !== ';' && 
$entry[1][0] !== ':')) {
+                       if ( empty( $entry[ 1 ] ) || ( $entry[ 1 ][ 0 ] !== ';' 
&& $entry[ 1 ][ 0 ] !== ':' ) ) {
                                continue;
                        }
 
-                       $chunks = explode( ':', $entry[1], 2 );
+                       $chunks = explode( ':', $entry[ 1 ], 2 );
 
                        // found a new definition?
-                       if ( count ( $chunks ) == 2 ) {
+                       if ( count( $chunks ) == 2 ) {
 
                                // wipe the data if its a totaly new term 
definition
-                               if ( !empty( $term ) && count( $definitions ) > 
0) {
+                               if ( !empty( $term ) && count( $definitions ) > 
0 ) {
                                        $definitions = array();
                                        $term = null;
                                }
 
-                               $definitions[] = trim( $chunks[1] );
+                               $definitions[] = trim( $chunks[ 1 ] );
                        }
 
                        // found a new term?
-                       if (count( $chunks ) >= 1 && strlen( $chunks[0] ) >= 1 
) {
-                               $term = trim( substr( $chunks[0], 1 ) );
+                       if ( count( $chunks ) >= 1 && strlen( $chunks[ 0 ] ) >= 
1 ) {
+                               $term = trim( substr( $chunks[ 0 ], 1 ) );
                        }
 
                        if ( $term !== null ) {
                                foreach ( $definitions as $definition ) {
                                        $ret[] = array(
-                                               LingoElement::ELEMENT_TERM => 
$term,
+                                               LingoElement::ELEMENT_TERM      
 => $term,
                                                
LingoElement::ELEMENT_DEFINITION => $definition,
-                                               LingoElement::ELEMENT_LINK => 
null,
-                                               LingoElement::ELEMENT_SOURCE => 
null
+                                               LingoElement::ELEMENT_LINK      
 => null,
+                                               LingoElement::ELEMENT_SOURCE    
 => null
                                        );
                                }
                        }
@@ -134,7 +139,7 @@
 
                wfProfileOut( __METHOD__ );
 
-               return array_pop($ret);
+               return array_pop( $ret );
        }
 
        /**
@@ -143,8 +148,7 @@
         * @param Title $title
         * @return Revision
         */
-       public function getRevision( $title )
-       {
+       public function getRevision( $title ) {
                global $wgexLingoEnableApprovedRevs;
 
                if ( $wgexLingoEnableApprovedRevs ) {
diff --git a/src/LingoElement.php b/src/LingoElement.php
index 9614ce8..5d57c2c 100644
--- a/src/LingoElement.php
+++ b/src/LingoElement.php
@@ -49,6 +49,11 @@
 
        static private $mLinkTemplate = null;
 
+       /**
+        * LingoElement constructor.
+        * @param $term
+        * @param $definition
+        */
        public function __construct( &$term, &$definition = null ) {
 
                $this->mTerm = $term;
@@ -58,19 +63,24 @@
                }
        }
 
+       /**
+        * @param $definition
+        */
        public function addDefinition( &$definition ) {
                $this->mDefinitions[] = array_pad( $definition, 
self::ELEMENT_FIELDCOUNT, null );
        }
 
+       /**
+        * @param DOMDocument $doc
+        * @return DOMNode|DOMText
+        */
        public function getFullDefinition( DOMDocument &$doc ) {
 
                global $wgexLingoDisplayOnce;
 
-               wfProfileIn( __METHOD__ );
-
                // return textnode if
                if ( $wgexLingoDisplayOnce && $this->mHasBeenDisplayed ) {
-                       return $doc->createTextNode($this->mTerm);
+                       return $doc->createTextNode( $this->mTerm );
                }
 
                // only create if not yet created
@@ -78,8 +88,9 @@
 
                        // 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_LINK] ) ) {
+                               && !is_string( $this->mDefinitions[ 0 ][ 
self::ELEMENT_DEFINITION ] )
+                               && is_string( $this->mDefinitions[ 0 ][ 
self::ELEMENT_LINK ] )
+                       ) {
 
                                $this->mFullDefinition = 
$this->getFullDefinitionAsLink( $doc );
 
@@ -91,39 +102,64 @@
                        $this->mHasBeenDisplayed = true;
                }
 
-               wfProfileOut( __METHOD__ );
-
                return $this->mFullDefinition->cloneNode( true );
        }
 
+       /**
+        * @return mixed
+        */
        public function getCurrentKey() {
                return key( $this->mDefinitions );
        }
 
+       /**
+        * @param $key
+        * @return mixed
+        */
        public function getTerm( $key ) {
-               return $this->mDefinitions[$key][self::ELEMENT_TERM];
+               return $this->mDefinitions[ $key ][ self::ELEMENT_TERM ];
        }
 
+       /**
+        * @param $key
+        * @return mixed
+        */
        public function getSource( &$key ) {
-               return $this->mDefinitions[$key][self::ELEMENT_SOURCE];
+               return $this->mDefinitions[ $key ][ self::ELEMENT_SOURCE ];
        }
 
+       /**
+        * @param $key
+        * @return mixed
+        */
        public function getDefinition( &$key ) {
-               return $this->mDefinitions[$key][self::ELEMENT_DEFINITION];
+               return $this->mDefinitions[ $key ][ self::ELEMENT_DEFINITION ];
        }
 
+       /**
+        * @param $key
+        * @return mixed
+        */
        public function getLink( &$key ) {
-               return $this->mDefinitions[$key][self::ELEMENT_LINK];
+               return $this->mDefinitions[ $key ][ self::ELEMENT_LINK ];
        }
 
+       /**
+        * @param $key
+        * @return mixed
+        */
        public function getStyle( &$key ) {
-               return $this->mDefinitions[$key][self::ELEMENT_STYLE];
+               return $this->mDefinitions[ $key ][ self::ELEMENT_STYLE ];
        }
 
        public function next() {
                next( $this->mDefinitions );
        }
 
+       /**
+        * @param DOMDocument $doc
+        * @return DOMNode
+        */
        private function getLinkTemplate( DOMDocument &$doc ) {
                // create template if it does not yet exist
                if ( !self::$mLinkTemplate || ( 
self::$mLinkTemplate->ownerDocument !== $doc ) ) {
diff --git a/src/LingoHooks.php b/src/LingoHooks.php
index c260ac6..032876e 100644
--- a/src/LingoHooks.php
+++ b/src/LingoHooks.php
@@ -42,18 +42,18 @@
         * @param String $text
         * @return Boolean
         */
-       static function parse( &$parser, &$text ) {
+       public static function parse( &$parser, &$text ) {
 
                global $wgexLingoUseNamespaces;
 
                $title = $parser->getTitle();
 
                // parse if
-               if ( !isset( $parser->mDoubleUnderscores['noglossary'] ) && // 
__NOGLOSSARY__ not present and
+               if ( !isset( $parser->mDoubleUnderscores[ 'noglossary' ] ) && 
// __NOGLOSSARY__ not present and
                        (
-                       !$title || // title not set or
-                       !isset( $wgexLingoUseNamespaces[ $title->getNamespace() 
] ) || // namespace not explicitly forbidden (i.e. not in list of namespaces 
and set to false) or
-                       $wgexLingoUseNamespaces[$title->getNamespace()] // 
namespace explicitly allowed
+                               !$title || // title not set or
+                               !isset( $wgexLingoUseNamespaces[ 
$title->getNamespace() ] ) || // namespace not explicitly forbidden (i.e. not 
in list of namespaces and set to false) or
+                               $wgexLingoUseNamespaces[ $title->getNamespace() 
] // namespace explicitly allowed
                        )
                ) {
 
@@ -70,8 +70,8 @@
        /**
         * Creates tag hook(s)
         */
-       public static function registerTags(Parser $parser) {
-               $parser->setHook( 'noglossary',  
'LingoHooks::noglossaryTagRenderer');
+       public static function registerTags( Parser $parser ) {
+               $parser->setHook( 'noglossary', 
'LingoHooks::noglossaryTagRenderer' );
                return true;
        }
 
@@ -86,22 +86,21 @@
         */
        public static function noglossaryTagRenderer( $input, array $args, 
Parser $parser, PPFrame $frame ) {
                $output = $parser->recursiveTagParse( $input, $frame );
-               return '<span class="noglossary">'.$output.'</span>';
+               return '<span class="noglossary">' . $output . '</span>';
        }
 
        /**
         * Deferred settings
         * - registration of _NOGLOSSARY_ magic word
         * - extension description shown on Special:Version
-        *
         */
        public static function initExtension() {
-               MagicWord::$mDoubleUnderscoreIDs[ ] = 'noglossary';
+               MagicWord::$mDoubleUnderscoreIDs[] = 'noglossary';
 
-               foreach ( $GLOBALS['wgExtensionCredits']['parserhook'] as 
$index => $description ) {
-                       if 
($GLOBALS['wgExtensionCredits']['parserhook'][$index]['name'] === 'Lingo') {
-                               
$GLOBALS['wgExtensionCredits']['parserhook'][$index]['description'] =
-                                       wfMessage( 'lingo-desc', 
$GLOBALS['wgexLingoPage'] ? $GLOBALS['wgexLingoPage'] : wfMessage( 
'lingo-terminologypagename' )->inContentLanguage()->text() )->text();
+               foreach ( $GLOBALS[ 'wgExtensionCredits' ][ 'parserhook' ] as 
$index => $description ) {
+                       if ( $GLOBALS[ 'wgExtensionCredits' ][ 'parserhook' ][ 
$index ][ 'name' ] === 'Lingo' ) {
+                               $GLOBALS[ 'wgExtensionCredits' ][ 'parserhook' 
][ $index ][ 'description' ] =
+                                       wfMessage( 'lingo-desc', $GLOBALS[ 
'wgexLingoPage' ] ? $GLOBALS[ 'wgexLingoPage' ] : wfMessage( 
'lingo-terminologypagename' )->inContentLanguage()->text() )->text();
                        }
                }
        }
diff --git a/src/LingoMessageLog.php b/src/LingoMessageLog.php
index d5b8993..089169a 100644
--- a/src/LingoMessageLog.php
+++ b/src/LingoMessageLog.php
@@ -43,38 +43,57 @@
        const MESSAGE_WARNING = 2;
        const MESSAGE_NOTICE = 3;
 
-       function addMessage( $message, $severity = self::MESSAGE_NOTICE ) {
-               $this->mMessages[] = array($message, $severity);
+       /**
+        * @param $message
+        * @param int $severity
+        */
+       public function addMessage( $message, $severity = self::MESSAGE_NOTICE 
) {
+               $this->mMessages[] = array( $message, $severity );
 
                // log errors and warnings in debug log
                if ( $severity == self::MESSAGE_WARNING ||
-                       $severity == self::MESSAGE_ERROR ) {
+                       $severity == self::MESSAGE_ERROR
+               ) {
                        wfDebug( $message );
                }
        }
 
-       function addError( $message ) {
-               $this->mMessages[] = array($message, self::MESSAGE_ERROR);
+       /**
+        * @param $message
+        */
+       public function addError( $message ) {
+               $this->mMessages[] = array( $message, self::MESSAGE_ERROR );
                wfDebug( "Error: $message\n" );
        }
 
-       function addWarning( $message ) {
-               $this->mMessages[] = array($message, self::MESSAGE_WARNING);
+       /**
+        * @param $message
+        */
+       public function addWarning( $message ) {
+               $this->mMessages[] = array( $message, self::MESSAGE_WARNING );
                wfDebug( "Warning: $message\n" );
        }
 
-       function addNotice( $message ) {
-               $this->mMessages[] = array($message, self::MESSAGE_NOTICE);
+       /**
+        * @param $message
+        */
+       public function addNotice( $message ) {
+               $this->mMessages[] = array( $message, self::MESSAGE_NOTICE );
        }
 
-       function getMessagesFormatted( $severity = self::MESSAGE_WARNING, 
$header = null ) {
+       /**
+        * @param int $severity
+        * @param null $header
+        * @return null|string
+        */
+       public function getMessagesFormatted( $severity = 
self::MESSAGE_WARNING, $header = null ) {
                global $wgTitle, $wgUser;
 
                $ret = '';
 
                foreach ( $this->mMessages as $message ) {
-                       if ( $message[1] <= $severity ) {
-                               $ret .= '* ' . $message[0] . "\n";
+                       if ( $message[ 1 ] <= $severity ) {
+                               $ret .= '* ' . $message[ 0 ] . "\n";
                        }
                }
 
@@ -86,16 +105,19 @@
                        if ( $header == null ) {
                                $header = '';
                        } elseif ( $header != '' ) {
-                               $header = Html::rawElement( 'div', 
array('class' => 'heading'), $header );
+                               $header = Html::rawElement( 'div', array( 
'class' => 'heading' ), $header );
                        }
 
-                       $ret = Html::rawElement( 'div', array('class' => 
'messages'),
-                                       $header . "\n" .
-                                       $ret
+                       $ret = Html::rawElement( 'div', array( 'class' => 
'messages' ),
+                               $header . "\n" .
+                               $ret
                        );
 
+                       // FIXME: Variable 'parser' might have not been defined
+                       // FIXME: $parser->parse returns ParserOutput, not 
String
                        $ret = $parser->parse( $ret, $wgTitle, 
ParserOptions::newFromUser( $wgUser ) );
                } else {
+                       // FIXME: Should probably return '' (and throw an error 
if necessary)
                        $ret = null;
                }
 
diff --git a/src/LingoParser.php b/src/LingoParser.php
index 115127c..6ebc003 100644
--- a/src/LingoParser.php
+++ b/src/LingoParser.php
@@ -48,14 +48,22 @@
        // The RegEx to split a chunk of text into words
        public static $regex = null;
 
+       /**
+        * LingoParser constructor.
+        * @param LingoMessageLog|null $messages
+        */
        public function __construct( LingoMessageLog &$messages = null ) {
                global $wgexLingoBackend;
 
                $this->mLingoBackend = new $wgexLingoBackend( $messages );
        }
 
-       private static function uniqPrefix( Parser &$parser) {
-               if ( defined("Parser::MARKER_PREFIX" )) {
+       /**
+        * @param Parser $parser
+        * @return string
+        */
+       private static function uniqPrefix( Parser &$parser ) {
+               if ( defined( "Parser::MARKER_PREFIX" ) ) {
                        return Parser::MARKER_PREFIX;
                } else {
                        return $parser->uniqPrefix();
@@ -68,19 +76,17 @@
         * @param string $text
         * @return Boolean
         */
-       static function parse( Parser &$parser, &$text ) {
-               wfProfileIn( __METHOD__ );
+       public static function parse( Parser &$parser, &$text ) {
+
                if ( !self::$parserSingleton ) {
                        self::$parserSingleton = new LingoParser();
 
                        // The RegEx to split a chunk of text into words
                        // Words are: placeholders for stripped items, 
sequences of letters and numbers, single characters that are neither letter nor 
number
-                       self::$regex = '/' . preg_quote( 
self::uniqPrefix($parser), '/' ) . '.*?' . preg_quote( Parser::MARKER_SUFFIX, 
'/' ) . '|[\p{L}\p{N}]+|[^\p{L}\p{N}]/u';
+                       self::$regex = '/' . preg_quote( self::uniqPrefix( 
$parser ), '/' ) . '.*?' . preg_quote( Parser::MARKER_SUFFIX, '/' ) . 
'|[\p{L}\p{N}]+|[^\p{L}\p{N}]/u';
                }
 
                self::$parserSingleton->realParse( $parser, $text );
-
-               wfProfileOut( __METHOD__ );
 
                return true;
        }
@@ -98,15 +104,12 @@
         *
         * @return Array an array mapping terms (keys) to descriptions (values)
         */
-       function getLingoArray() {
-               wfProfileIn( __METHOD__ );
+       public function getLingoArray() {
 
                // build glossary array only once per request
                if ( !$this->mLingoTree ) {
                        $this->buildLingo();
                }
-
-               wfProfileOut( __METHOD__ );
 
                return $this->mLingoTree->getTermList();
        }
@@ -116,8 +119,7 @@
         *
         * @return LingoTree a LingoTree mapping terms (keys) to descriptions 
(values)
         */
-       function getLingoTree() {
-               wfProfileIn( __METHOD__ );
+       public function getLingoTree() {
 
                // build glossary array only once per request
                if ( !$this->mLingoTree ) {
@@ -127,7 +129,7 @@
 
                                // Try cache first
                                global $wgexLingoCacheType;
-                               $cache = ($wgexLingoCacheType !== null)?  
wfGetCache( $wgexLingoCacheType ):wfGetMainCache();
+                               $cache = ( $wgexLingoCacheType !== null ) ? 
wfGetCache( $wgexLingoCacheType ) : wfGetMainCache();
                                $cachekey = wfMemcKey( 'ext', 'lingo', 
'lingotree' );
                                $cachedLingoTree = $cache->get( $cachekey );
 
@@ -151,23 +153,19 @@
 
                }
 
-               wfProfileOut( __METHOD__ );
-
                return $this->mLingoTree;
        }
 
        protected function &buildLingo() {
-               wfProfileIn( __METHOD__ );
 
                $lingoTree = new LingoTree();
                $backend = &$this->mLingoBackend;
 
                // assemble the result array
                while ( $elementData = $backend->next() ) {
-                       $lingoTree->addTerm( 
$elementData[LingoElement::ELEMENT_TERM], $elementData );
+                       $lingoTree->addTerm( $elementData[ 
LingoElement::ELEMENT_TERM ], $elementData );
                }
 
-               wfProfileOut( __METHOD__ );
                return $lingoTree;
        }
 
@@ -183,18 +181,15 @@
        protected function realParse( &$parser, &$text ) {
                global $wgRequest;
 
-               wfProfileIn( __METHOD__ );
-
                $action = $wgRequest->getVal( 'action', 'view' );
 
                if ( $text === null ||
                        $text === '' ||
                        $action === 'edit' ||
                        $action === 'ajax' ||
-                       isset( $_POST['wpPreview'] )
+                       isset( $_POST[ 'wpPreview' ] )
                ) {
 
-                       wfProfileOut( __METHOD__ );
                        return true;
                }
 
@@ -202,27 +197,22 @@
                $glossary = $this->getLingoTree();
 
                if ( $glossary == null ) {
-                       wfProfileOut( __METHOD__ );
                        return true;
                }
 
                // Parse HTML from page
-               wfProfileIn( __METHOD__ . ' 1 loadHTML' );
                wfSuppressWarnings();
 
-               $doc = new DOMDocument('1.0','utf-8');
+               $doc = new DOMDocument( '1.0', 'utf-8' );
                $doc->loadHTML( '<html><head><meta http-equiv="content-type" 
content="charset=utf-8"/></head><body>' . $text . '</body></html>' );
 
                wfRestoreWarnings();
-               wfProfileOut( __METHOD__ . ' 1 loadHTML' );
 
-               wfProfileIn( __METHOD__ . ' 2 xpath' );
                // Find all text in HTML.
                $xpath = new DOMXpath( $doc );
                $elements = $xpath->query(
-                               
"//*[not(ancestor-or-self::*[@class='noglossary'] or 
ancestor-or-self::a)][text()!=' ']/text()"
+                       "//*[not(ancestor-or-self::*[@class='noglossary'] or 
ancestor-or-self::a)][text()!=' ']/text()"
                );
-               wfProfileOut( __METHOD__ . ' 2 xpath' );
 
                // Iterate all HTML text matches
                $nb = $elements->length;
@@ -235,7 +225,6 @@
                                continue;
                        }
 
-                       wfProfileIn( __METHOD__ . ' 3 lexer' );
                        $matches = array();
                        preg_match_all(
                                self::$regex,
@@ -243,32 +232,28 @@
                                $matches,
                                PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER
                        );
-                       wfProfileOut( __METHOD__ . ' 3 lexer' );
 
-                       if ( count( $matches ) == 0 || count( $matches[0] ) == 
0 ) {
+                       if ( count( $matches ) == 0 || count( $matches[ 0 ] ) 
== 0 ) {
                                continue;
                        }
 
-                       $lexemes = &$matches[0];
+                       $lexemes = &$matches[ 0 ];
                        $countLexemes = count( $lexemes );
                        $parent = &$el->parentNode;
                        $index = 0;
                        $changedElem = false;
 
                        while ( $index < $countLexemes ) {
-                               wfProfileIn( __METHOD__ . ' 4 findNextTerm' );
                                list( $skipped, $used, $definition ) =
                                        $glossary->findNextTerm( $lexemes, 
$index, $countLexemes );
-                               wfProfileOut( __METHOD__ . ' 4 findNextTerm' );
 
-                               wfProfileIn( __METHOD__ . ' 5 insert' );
                                if ( $used > 0 ) { // found a term
                                        if ( $skipped > 0 ) { // skipped some 
text, insert it as is
                                                $parent->insertBefore(
                                                        $doc->createTextNode(
                                                                substr( 
$el->nodeValue,
-                                                                       
$currLexIndex = $lexemes[$index][1],
-                                                                       
$lexemes[$index + $skipped][1] - $currLexIndex )
+                                                                       
$currLexIndex = $lexemes[ $index ][ 1 ],
+                                                                       
$lexemes[ $index + $skipped ][ 1 ] - $currLexIndex )
                                                        ),
                                                        $el
                                                );
@@ -285,18 +270,16 @@
                                        if ( $changedElem ) {
                                                $parent->insertBefore(
                                                        $doc->createTextNode(
-                                                               substr( 
$el->nodeValue, $lexemes[$index][1] )
+                                                               substr( 
$el->nodeValue, $lexemes[ $index ][ 1 ] )
                                                        ),
                                                        $el
                                                );
                                        } else {
-                                               wfProfileOut( __METHOD__ . ' 5 
insert' );
                                                // In principle superfluous, 
the loop would run out
                                                // anyway. Might save a bit of 
time.
                                                break;
                                        }
                                }
-                               wfProfileOut( __METHOD__ . ' 5 insert' );
 
                                $index += $used + $skipped;
                        }
@@ -314,11 +297,12 @@
                        $text = preg_replace( '%(^.*<body>)|(</body>.*$)%UDs', 
'', $doc->saveHTML() );
                }
 
-               wfProfileOut( __METHOD__ );
-
                return true;
        }
 
+       /**
+        * @param $parser
+        */
        protected function loadModules( &$parser ) {
                global $wgOut, $wgScriptPath;
 
@@ -343,7 +327,7 @@
                }
 
                // load styles
-               if ( method_exists( $parserOutput, 'addModuleStyles') ) {
+               if ( method_exists( $parserOutput, 'addModuleStyles' ) ) {
                        $parserOutput->addModuleStyles( 'ext.Lingo.Styles' );
                        if ( !$wgOut->isArticle() ) {
                                $wgOut->addModuleStyles( 'ext.Lingo.Styles' );
@@ -359,10 +343,10 @@
        /**
         * Purges the lingo tree from the cache.
         */
-       public static function purgeCache () {
+       public static function purgeCache() {
 
                global $wgexLingoCacheType;
-               $cache = ($wgexLingoCacheType !== null)?  wfGetCache( 
$wgexLingoCacheType ):wfGetMainCache();
+               $cache = ( $wgexLingoCacheType !== null ) ? wfGetCache( 
$wgexLingoCacheType ) : wfGetMainCache();
                $cache->delete( wfMemcKey( 'ext', 'lingo', 'lingotree' ) );
 
        }
diff --git a/src/LingoTree.php b/src/LingoTree.php
index cae4c2f..604bb48 100644
--- a/src/LingoTree.php
+++ b/src/LingoTree.php
@@ -57,22 +57,22 @@
         * Adds a string to the Lingo Tree
         * @param String $term
         */
-       function addTerm( &$term, $definition ) {
+       public function addTerm( &$term, $definition ) {
                if ( !$term ) {
                        return;
                }
 
-               if ( isset( $this->mList[$term] ) ) { // term exists, store 2nd 
definition
-                       $this->mList[$term]->addDefinition( $definition );
+               if ( isset( $this->mList[ $term ] ) ) { // term exists, store 
2nd definition
+                       $this->mList[ $term ]->addDefinition( $definition );
                } else {
 
                        $matches = array();
                        preg_match_all( LingoParser::$regex, $term, $matches );
 
-                       $elt = $this->addElement( $matches[0], $term, 
$definition );
-                       $this->mList[$term] = &$elt[-1];
+                       $elt = $this->addElement( $matches[ 0 ], $term, 
$definition );
+                       $this->mList[ $term ] = &$elt[ -1 ];
 
-                       $this->mMinLength = min( array($this->mMinLength, 
strlen( $term )) );
+                       $this->mMinLength = min( array( $this->mMinLength, 
strlen( $term ) ) );
                }
        }
 
@@ -89,45 +89,44 @@
                $tree = &$this->mTree;
 
                // end of path, store description; end of recursion
-               while ( ($step = array_shift( $path )) !== null ) {
+               while ( ( $step = array_shift( $path ) ) !== null ) {
 
-                       if ( !isset( $tree[$step] ) ) {
-                               $tree[$step] = array();
+                       if ( !isset( $tree[ $step ] ) ) {
+                               $tree[ $step ] = array();
                        }
 
-                       $tree = &$tree[$step];
+                       $tree = &$tree[ $step ];
                }
 
-               if ( isset( $tree[-1] ) ) {
-                       $tree[-1]->addDefinition( $definition );
+               if ( isset( $tree[ -1 ] ) ) {
+                       $tree[ -1 ]->addDefinition( $definition );
                } else {
-                       $tree[-1] = new LingoElement( $term, $definition );
+                       $tree[ -1 ] = new LingoElement( $term, $definition );
                }
 
                return $tree;
        }
 
-       function getMinTermLength() {
+       public function getMinTermLength() {
                return $this->mMinLength;
        }
 
-       function getTermList() {
+       public function getTermList() {
                return $this->mList;
        }
 
-       function findNextTerm( &$lexemes, $index, $countLexemes ) {
-               wfProfileIn( __METHOD__ );
+       public function findNextTerm( &$lexemes, $index, $countLexemes ) {
 
                $start = $lastindex = $index;
                $definition = null;
 
                // skip until the start of a term is found
                while ( $index < $countLexemes && !$definition ) {
-                       $currLex = &$lexemes[$index][0];
+                       $currLex = &$lexemes[ $index ][ 0 ];
 
                        // Did we find the start of a term?
                        if ( array_key_exists( $currLex, $this->mTree ) ) {
-                               list( $lastindex, $definition ) = 
$this->findNextTermNoSkip( $this->mTree[$currLex], $lexemes, $index, 
$countLexemes );
+                               list( $lastindex, $definition ) = 
$this->findNextTermNoSkip( $this->mTree[ $currLex ], $lexemes, $index, 
$countLexemes );
                        }
 
                        // this will increase the index even if we found 
something;
@@ -135,23 +134,21 @@
                        $index++;
                }
 
-               wfProfileOut( __METHOD__ );
                if ( $definition ) {
-                       return array($index - $start - 1, $lastindex - $index + 
2, $definition);
+                       return array( $index - $start - 1, $lastindex - $index 
+ 2, $definition );
                } else {
-                       return array($index - $start, 0, null);
+                       return array( $index - $start, 0, null );
                }
        }
 
-       function findNextTermNoSkip( Array &$tree, &$lexemes, $index, 
$countLexemes ) {
-               wfProfileIn( __METHOD__ );
+       public function findNextTermNoSkip( Array &$tree, &$lexemes, $index, 
$countLexemes ) {
 
-               if ( $index + 1 < $countLexemes && array_key_exists( $currLex = 
$lexemes[$index + 1][0], $tree ) ) {
-                       $ret = $this->findNextTermNoSkip( $tree[$currLex], 
$lexemes, $index + 1, $countLexemes );
+               if ( $index + 1 < $countLexemes && array_key_exists( $currLex = 
$lexemes[ $index + 1 ][ 0 ], $tree ) ) {
+                       $ret = $this->findNextTermNoSkip( $tree[ $currLex ], 
$lexemes, $index + 1, $countLexemes );
                } else {
-                       $ret = array($index, &$tree[-1]);
+                       $ret = array( $index, &$tree[ -1 ] );
                }
-               wfProfileOut( __METHOD__ );
+
                return $ret;
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/275220
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c50f179eafc7f45133ca5f9d77c1586a26418fa
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Lingo
Gerrit-Branch: master
Gerrit-Owner: Foxtrott <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to