r73517 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73516‎ | r73517 | r73518 >
Date:12:20, 22 September 2010
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
Made some small improvements
Modified paths:
  • /trunk/extensions/QrCode/QrCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/QrCode/QrCode.php
@@ -12,33 +12,33 @@
1313 * which is, in turn, based on C libqrencode library
1414 * Copyright (C) 2006-2010 by Kentaro Fukuchi
1515 * http://megaui.net/fukuchi/works/qrencode/index.en.html
16 - *
17 - *
1816 */
1917
20 -if ( !defined( 'MEDIAWIKI' ) )
 18+if ( !defined( 'MEDIAWIKI' ) ) {
2119 die( 'This is a MediaWiki extension, and must be run from within MediaWiki.' );
 20+}
2221
2322 $wgExtensionCredits['parserhook'][] = array(
2423 'path' => __FILE__,
2524 'name' => 'QrCode',
2625 'version' => '0.02',
27 - 'author' =>'David Raison',
 26+ 'author' => array( 'David Raison' ),
2827 'url' => 'http://www.mediawiki.org/wiki/Extension:QrCode',
2928 'descriptionmsg' => 'qrcode-desc'
3029 );
3130
3231 $wgAutoloadClasses['QRcode'] = dirname(__FILE__) . '/phpqrcode/qrlib.php';
33 -$wgExtensionFunctions[] = "efQrcodeSetup";
3432 $wgExtensionMessagesFiles['QrCode'] = dirname(__FILE__) .'/QrCode.i18n.php';
 33+
3534 $wgHooks['LanguageGetMagic'][] = 'wfQrCodeLanguageGetMagic';
 35+$wgHooks['ParserFirstCallInit'][] = 'efQrcodeRegisterFunction';
3636
37 -function efQrcodeSetup(){
38 - global $wgParser;
39 - $wgParser->setFunctionHook( 'qrcode', array(new MwQrCode, 'showCode' ));
 37+function efQrcodeRegisterFunction( Parser &$parser ) {
 38+ $parser->setFunctionHook( 'qrcode', array( new MWQrCode(), 'showCode' ) );
 39+ return true;
4040 }
4141
42 -function wfQrCodeLanguageGetMagic( &$magicWords, $langCode='en' ) {
 42+function wfQrCodeLanguageGetMagic( &$magicWords, $langCode = 'en' ) {
4343 $magicWords['qrcode'] = array( 0, 'qrcode' );
4444 return true;
4545 }
@@ -49,7 +49,7 @@
5050 $wgQrCodeBoundary = 2; // boundary around square
5151 $wgQrCodeBot = 'QrCodeBot';
5252
53 -class MwQrCode {
 53+class MWQrCode {
5454
5555 private $_dstFileName; // what the file will be named?
5656 private $_label; // What will the qrcode contain?
@@ -112,7 +112,7 @@
113113 * @return output of the _publish method
114114 */
115115 private function _generate(){
116 - global $wgTmpDirectory;
 116+ global $wgTmpDirectory, $wgQrCodeECC, $wgQrCodeSize, $wgQrCodeBoundary;
117117 $tmpName = tempnam( $wgTmpDirectory, 'qrcode' );
118118
119119 QRcode::png( $this->_label, $tmpName, $this->_ecc, $this->_size, $this->_boundary );
@@ -164,4 +164,5 @@
165165 return true;
166166 }
167167 }
168 -}
 168+
 169+}
\ No newline at end of file

Comments

#Comment by Nikerabbit (talk | contribs)   13:16, 22 September 2010
+'author' => array( 'David Raison' ), 

Why use array if there is only one author?

+}
\ No newline at end of file

Please have the files end in a newline.

#Comment by Jeroen De Dauw (talk | contribs)   13:34, 22 September 2010
Why use array if there is only one author?

Bike-shedding!!!

Please have the files end in a newline.

Why?

#Comment by Nikerabbit (talk | contribs)   13:38, 22 September 2010

Because that is the custom. Some tools like cat expect it to be there.

#Comment by Jeroen De Dauw (talk | contribs)   13:48, 22 September 2010

Really? They fail when there is no newline at the end?! I've been committing files without new lines at the end for over a year, and never got any complaint.

#Comment by 😂 (talk | contribs)   14:02, 22 September 2010

They don't fail, they just don't append a newline themselves so you end up with something like

me@host $ cat file.txt
Foo
Bar 
Baz
Some contentme@host $

Which is ugly :(

Somebody should've complained ;-)

Status & tagging log