r104585 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104584‎ | r104585 | r104586 >
Date:20:11, 29 November 2011
Author:kwisatz
Status:deferred
Tags:
Comment:
qrcode: allow to force a scheme
Modified paths:
  • /trunk/extensions/QrCode/QrCode.php (modified) (history)

Diff [purge]

Index: trunk/extensions/QrCode/QrCode.php
@@ -22,7 +22,7 @@
2323 $wgExtensionCredits['parserhook'][] = array(
2424 'path' => __FILE__,
2525 'name' => 'QrCode',
26 - 'version' => '0.10',
 26+ 'version' => '0.11',
2727 'author' => array( 'David Raison' ),
2828 'url' => 'http://www.mediawiki.org/wiki/Extension:QrCode',
2929 'descriptionmsg' => 'qrcode-desc'
@@ -49,6 +49,7 @@
5050 $wgQrCodeECC = 'L'; // L,M,Q,H
5151 $wgQrCodeSize = 4; // pixel size of black squares
5252 $wgQrCodeBoundary = 2; // margin around qrcode
 53+$wgQrCodeForceScheme = false; // use protocol the author uses
5354
5455 // not changeable
5556 define('QRCODEBOT','QrCode generator'); // if a user changes this, the name won't be protected anymore
@@ -65,7 +66,7 @@
6667 $parser = array_shift($params); // we'll need the parser later
6768
6869 // Handling "Undefined variable" notices
69 - $margin = $ecc = $size = $label = false;
 70+ $margin = $ecc = $size = $label = $scheme = false;
7071
7172 foreach( $params as $pair ) {
7273 $firstEqual = strpos( $pair, '=' );
@@ -75,7 +76,7 @@
7677 }
7778 }
7879
79 - $newQrCode = new MWQrCode( $parser, $ecc, $size, $margin );
 80+ $newQrCode = new MWQrCode( $parser, $ecc, $size, $margin, $scheme );
8081 return $newQrCode->showCode( $label );
8182 }
8283
@@ -100,19 +101,21 @@
101102 private $_ecc; // error correction
102103 private $_size; // qrcode size
103104 private $_margin; // qrcode margin
 105+ private $_scheme; // force the protocol to be http or https?
104106
105107 /**
106108 * Set qrcode properties
107109 *
108110 * @param $parser Parser
109111 */
110 - public function __construct( $parser, $ecc = false, $size = false, $margin = false ) {
111 - global $wgQrCodeECC, $wgQrCodeSize, $wgQrCodeBoundary;
 112+ public function __construct( $parser, $ecc = false, $size = false, $margin = false, $scheme = false ) {
 113+ global $wgQrCodeECC, $wgQrCodeSize, $wgQrCodeBoundary, $wgQrCodeForceScheme;
112114 $this->_parser = $parser;
113115 $this->_title = $parser->getTitle();
114116 $this->_ecc = ( $ecc ) ? $ecc : $wgQrCodeECC;
115117 $this->_size = ( $size ) ? $size : $wgQrCodeSize;
116118 $this->_margin = ( $margin ) ? $margin : $wgQrCodeBoundary;
 119+ $this->_scheme = ( $scheme ) ? $scheme : $wgQrCodeForceScheme;
117120 }
118121
119122 /**
@@ -121,13 +124,20 @@
122125 */
123126 public function showCode( $label = false ){
124127
125 - // Check for a provided label and use the page URL as default.
 128+ // Check for a provided label and use the page URL as default (but force protocol if requested)
126129 if ( $label ) {
127 - $this->_label = $label; // cannot remember why sanitizing this would make sense
128 - //$this->_label = preg_replace("/[^0-9a-zA-Z_]+/", "", $label);
129 - $this->_uploadComment = $label; // should we sanitize this?
 130+ $this->_label = $label; // should we sanitize this?
 131+ $this->_uploadComment = $label;
130132 } else {
131 - $this->_label = $this->_title->getFullURL();
 133+ $url = parse_url($this->_title->getFullURL());
 134+ $url['scheme'] = ( $this->_scheme ) ? $this->_scheme : $url['scheme'];
 135+ //$this->_label = http_build_url($url); // http_build_url is part of pecl_http >= 0.21.0 :(
 136+ $this->_label = $url['scheme'] . '://'
 137+ . $url['host']
 138+ . ( ( isset($url['port']) ) ? $url['port'] : '' )
 139+ . ( ( isset($url['path']) ) ? $url['path'] : '' )
 140+ . ( ( isset($url['query']) ) ? '?' . $url['query'] : '' )
 141+ . ( ( isset($url['fragment']) ) ? '#' . $url['fragment'] : '' );
132142 $this->_uploadComment = 'Encoded URL for '.$this->_title->getFullText();
133143 }
134144

Status & tagging log