r113575 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113574‎ | r113575 | r113576 >
Date:17:06, 11 March 2012
Author:reedy
Status:ok (Comments)
Tags:
Comment:
Add $wgExtensionCredits

Add all consonants

Documentation
Modified paths:
  • /trunk/extensions/LuaFoo/LuaFoo.i18n.php (modified) (history)
  • /trunk/extensions/LuaFoo/LuaFoo.php (modified) (history)
  • /trunk/extensions/LuaFoo/includes/Converter.php (modified) (history)
  • /trunk/extensions/LuaFoo/includes/SpecialLuaTranslation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LuaFoo/includes/SpecialLuaTranslation.php
@@ -10,8 +10,6 @@
1111 }
1212
1313 function execute( $par ) {
14 - global $wgRequest;
15 -
1614 $this->setHeaders();
1715
1816 $form = new HTMLForm( array(
Index: trunk/extensions/LuaFoo/includes/Converter.php
@@ -24,6 +24,11 @@
2525 'pfunc_if' => 'pfunc_if'
2626 );
2727
 28+ /**
 29+ * @param $title Title
 30+ * @param $language
 31+ * @return string
 32+ */
2833 static function convert( $title, $language ) {
2934 $converter = new self( $language );
3035 $code = $converter->convertTemplate( $title );
@@ -42,6 +47,10 @@
4348 }
4449 }
4550
 51+ /**
 52+ * @param $title Title
 53+ * @return LuaFoo_Converter_Block
 54+ */
4655 function convertTemplate( $title ) {
4756 $funcName = $this->titleToIdentifier( $title );
4857 $deps = $this->newDeps();
@@ -63,10 +72,18 @@
6473 return $block;
6574 }
6675
 76+ /**
 77+ * @return LuaFoo_Converter_Deps
 78+ */
6779 function newDeps() {
6880 return new LuaFoo_Converter_Deps;
6981 }
7082
 83+ /**
 84+ * @param $value
 85+ * @return LuaFoo_Converter_Expression
 86+ * @throws MWException
 87+ */
7188 function newLiteral( $value ) {
7289 if ( !is_string( $value ) && !is_numeric( $value ) && !is_array( $value ) ) {
7390 throw new MWException( __METHOD__.': invalid literal type' );
@@ -74,12 +91,20 @@
7592 return new LuaFoo_Converter_Expression( 'literal', array( $value ) );
7693 }
7794
 95+ /**
 96+ * @param $hash
 97+ * @return LuaFoo_Converter_Expression
 98+ */
7899 function newHash( $hash ) {
79100 return new LuaFoo_Converter_Expression( 'hash', array_merge(
80101 array_map( array( $this, 'newLiteral' ), array_keys( $hash ) ),
81102 array_values( $hash ) ) );
82103 }
83104
 105+ /**
 106+ * @param $items
 107+ * @return LuaFoo_Converter_Expression|mixed
 108+ */
84109 function newConcat( $items ) {
85110 $filteredItems = array();
86111 foreach ( $items as $item ) {
@@ -142,6 +167,11 @@
143168 }
144169 }
145170
 171+ /**
 172+ * @param $expr
 173+ * @param $deps
 174+ * @return LuaFoo_Converter_Expression
 175+ */
146176 function newTrim( $expr, $deps ) {
147177 if ( $expr->op === 'literal' ) {
148178 // Trim a literal
@@ -166,6 +196,12 @@
167197 }
168198 }
169199
 200+ /**
 201+ * @param $name
 202+ * @param $args
 203+ * @param $deps
 204+ * @return LuaFoo_Converter_Expression
 205+ */
170206 function newParserFunctionCall( $name, $args, $deps ) {
171207 if ( isset( $this->inlineFunctions[$name] ) ) {
172208 $inlineFunc = $this->inlineFunctions[$name];
@@ -177,10 +213,19 @@
178214 return $this->newExpression( 'call', $args );
179215 }
180216
 217+ /**
 218+ * @param $op
 219+ * @param $args
 220+ * @return LuaFoo_Converter_Expression
 221+ */
181222 function newExpression( $op, $args ) {
182223 return new LuaFoo_Converter_Expression( $op, $args );
183224 }
184225
 226+ /**
 227+ * @param $title Title
 228+ * @return mixed|string
 229+ */
185230 function titleToIdentifier( $title ) {
186231 $id = '';
187232 if ( $title->getNamespace() == NS_TEMPLATE ) {
@@ -195,11 +240,20 @@
196241 return $id;
197242 }
198243
 244+ /**
 245+ * @param $name string
 246+ * @return string
 247+ */
199248 function parserFunctionToIdentifier( $name ) {
200249 $name = preg_replace( '/[^\w\177-\377]/', '_', $name );
201250 return "pfunc_$name";
202251 }
203252
 253+ /**
 254+ * @param $title Title
 255+ * @param $deps
 256+ * @return LuaFoo_Converter_Expression|mixed
 257+ */
204258 function getTemplateExpression( $title, $deps ) {
205259 $rev = Revision::newFromTitle( $title );
206260 if ( !$rev ) {
@@ -217,6 +271,12 @@
218272 return $expression;
219273 }
220274
 275+ /**
 276+ * @param $contextNode PPNode_Hash_Array|PPNode_Hash_Attr|PPNode_Hash_Text|PPNode_Hash_Tree
 277+ * @param $deps
 278+ * @return LuaFoo_Converter_Expression|mixed
 279+ * @throws MWException
 280+ */
221281 function expand( $contextNode, $deps ) {
222282 if ( is_string( $contextNode ) ) {
223283 return $this->newLiteral( $contextNode );
@@ -256,6 +316,11 @@
257317 }
258318 }
259319
 320+ /**
 321+ * @param $bits
 322+ * @param $deps
 323+ * @return LuaFoo_Converter_Expression|mixed
 324+ */
260325 function expandTemplate( $bits, $deps ) {
261326 global $wgContLang;
262327
@@ -365,6 +430,11 @@
366431 }
367432 }
368433
 434+ /**
 435+ * @param $piece
 436+ * @param $deps
 437+ * @return LuaFoo_Converter_Expression
 438+ */
369439 function expandTemplateArg( $piece, $deps ) {
370440 $parts = $piece['parts'];
371441 $nameExpr = $this->newTrim( $this->expand( $piece['title'], $deps ), $deps );
@@ -394,6 +464,11 @@
395465 ) );
396466 }
397467
 468+ /**
 469+ * @param $args
 470+ * @param $deps
 471+ * @return LuaFoo_Converter_Expression
 472+ */
398473 function pfunc_if( $args, $deps ) {
399474 if ( isset( $args[0] ) ) {
400475 $condition = $this->newExpression( 'equals', array(
@@ -428,14 +503,24 @@
429504 $this->converter = $converter;
430505 }
431506
 507+ /**
 508+ * @return LuaFoo_Converter_Block
 509+ */
432510 function newBlock() {
433511 return new LuaFoo_Converter_Block( $this );
434512 }
435513
 514+ /**
 515+ * @param $seed
 516+ * @return LuaFoo_Converter_Frame
 517+ */
436518 function newFrame( $seed ) {
437519 return new LuaFoo_Converter_Frame( $this, $seed );
438520 }
439521
 522+ /**
 523+ * @param $name
 524+ */
440525 function getRuntimeBlock( $name ) {
441526 if ( $this->runtimeBlocks === null ) {
442527 $this->setupRuntime();
@@ -485,6 +570,12 @@
486571 'while'
487572 );
488573
 574+ /**
 575+ * @param $name
 576+ * @param $argNames
 577+ * @param $expression
 578+ * @return LuaFoo_Converter_Block
 579+ */
489580 public function makeFunction( $name, $argNames, $expression ) {
490581 $frame = $this->newFrame( $name );
491582 $block = $this->expressionToBlock( $expression, $frame );
@@ -504,10 +595,19 @@
505596 return $func;
506597 }
507598
 599+ /**
 600+ * @return array
 601+ */
508602 public function getKeywords() {
509603 return $this->keywords;
510604 }
511605
 606+ /**
 607+ * @param $expression
 608+ * @param $frame LuaFoo_Converter_Frame
 609+ * @return LuaFoo_Converter_Block
 610+ * @throws MWException
 611+ */
512612 protected function expressionToBlock( $expression, $frame ) {
513613 if ( !($expression instanceof LuaFoo_Converter_Expression ) ) {
514614 throw new MWException( 'Non-expression passed to ' . __METHOD__ );
@@ -616,11 +716,20 @@
617717 return $block;
618718 }
619719
 720+ /**
 721+ * @param $name string
 722+ * @return bool
 723+ */
620724 public function isName( $name ) {
621725 return !in_array( $name, $this->keywords )
622726 && preg_match( '/^[a-zA-Z_][a-zA-Z0-9_]*$/', $name );
623727 }
624728
 729+ /**
 730+ * @param $input
 731+ * @return float|string
 732+ * @throws MWException
 733+ */
625734 protected function encodeLiteral( $input ) {
626735 if ( is_string( $input ) ) {
627736 $result = strtr( $input, array(
@@ -654,6 +763,11 @@
655764 }
656765 }
657766
 767+ /**
 768+ * @param $context
 769+ * @param $arg
 770+ * @return bool
 771+ */
658772 protected function needsBrackets( $context, $arg ) {
659773 if ( isset( $this->binaryPrecedence[ $context->op ] )
660774 && isset( $this->binaryPrecedence[ $arg->op ] ) )
@@ -720,6 +834,10 @@
721835 }
722836 }
723837
 838+ /**
 839+ * @param $name
 840+ * @return LuaFoo_Converter_Block
 841+ */
724842 protected function getRuntimeUnimplementedBlock( $name ) {
725843 $block = $this->newBlock();
726844 $block->addItems( array(
@@ -732,6 +850,10 @@
733851 return $block;
734852 }
735853
 854+ /**
 855+ * @param $block LuaFoo_Converter_Block
 856+ * @param $frame
 857+ */
736858 protected function addLocalDeclarations( $block, $frame ) {
737859 foreach ( $frame->variables as $var => $dummy ) {
738860 $block->prependItem( "local $var" );
@@ -784,10 +906,16 @@
785907 return $out;
786908 }
787909
 910+ /**
 911+ * @return LuaFoo_Converter_Indent
 912+ */
788913 function indent() {
789914 return new LuaFoo_Converter_Indent;
790915 }
791916
 917+ /**
 918+ * @return LuaFoo_Converter_Unindent
 919+ */
792920 function unindent() {
793921 return new LuaFoo_Converter_Unindent;
794922 }
@@ -822,7 +950,7 @@
823951 }
824952
825953 class LuaFoo_Converter_Frame {
826 - static $consonants = 'bdfghjklmnprstvwz';
 954+ static $consonants = 'bcdfghjklmnpqrstvwxyz';
827955 static $vowels = 'aeiou';
828956
829957 var $variables = array();
@@ -834,6 +962,9 @@
835963 srand( crc32( $seed ) );
836964 }
837965
 966+ /**
 967+ * @return string
 968+ */
838969 public function newVariable() {
839970 do {
840971 $length = rand( 5, 8 );
@@ -852,6 +983,10 @@
853984 return $s;
854985 }
855986
 987+ /**
 988+ * @param $expr
 989+ * @return bool
 990+ */
856991 public function getVariable( $expr ) {
857992 $hash = $expr->getHash();
858993 if ( isset( $this->variablesByHash[$hash] ) ) {
Index: trunk/extensions/LuaFoo/LuaFoo.i18n.php
@@ -2,6 +2,7 @@
33
44 $messages = array();
55 $messages['en'] = array(
 6+ 'luafoo-desc' => 'Translates templates to Lua',
67 'luafoo-luatranslation' => 'Translate template to Lua',
78 'luafoo-convert-title' => 'Template to convert to Lua:',
89 'luafoo-convert-submit' => 'Convert',
Index: trunk/extensions/LuaFoo/LuaFoo.php
@@ -4,7 +4,16 @@
55 exit( 1 );
66 }
77
 8+$wgExtensionCredits['specialpage'][] = array(
 9+ 'path' => __FILE__,
 10+ 'name' => 'LuaFoo',
 11+ 'url' => 'https://www.mediawiki.org/wiki/Extension:LuaFoo',
 12+ 'author' => 'Tim Starling',
 13+ 'descriptionmsg' => 'luafoo-desc',
 14+);
 15+
816 $lfip = dirname( __FILE__ );
 17+
918 $wgAutoloadClasses['LuaFoo_SpecialLuaTranslation'] = "$lfip/includes/SpecialLuaTranslation.php";
1019 $wgAutoloadClasses['LuaFoo_Converter'] = "$lfip/includes/Converter.php";
1120

Comments

#Comment by Platonides (talk | contribs)   23:42, 11 March 2012

It was fun reading the consonants comment :)

Status & tagging log