Index: trunk/extensions/QrCode/QrCode.php |
— | — | @@ -22,7 +22,7 @@ |
23 | 23 | $wgExtensionCredits['parserhook'][] = array( |
24 | 24 | 'path' => __FILE__, |
25 | 25 | 'name' => 'QrCode', |
26 | | - 'version' => '0.10', |
| 26 | + 'version' => '0.11', |
27 | 27 | 'author' => array( 'David Raison' ), |
28 | 28 | 'url' => 'http://www.mediawiki.org/wiki/Extension:QrCode', |
29 | 29 | 'descriptionmsg' => 'qrcode-desc' |
— | — | @@ -49,6 +49,7 @@ |
50 | 50 | $wgQrCodeECC = 'L'; // L,M,Q,H |
51 | 51 | $wgQrCodeSize = 4; // pixel size of black squares |
52 | 52 | $wgQrCodeBoundary = 2; // margin around qrcode |
| 53 | +$wgQrCodeForceScheme = false; // use protocol the author uses |
53 | 54 | |
54 | 55 | // not changeable |
55 | 56 | define('QRCODEBOT','QrCode generator'); // if a user changes this, the name won't be protected anymore |
— | — | @@ -65,7 +66,7 @@ |
66 | 67 | $parser = array_shift($params); // we'll need the parser later |
67 | 68 | |
68 | 69 | // Handling "Undefined variable" notices |
69 | | - $margin = $ecc = $size = $label = false; |
| 70 | + $margin = $ecc = $size = $label = $scheme = false; |
70 | 71 | |
71 | 72 | foreach( $params as $pair ) { |
72 | 73 | $firstEqual = strpos( $pair, '=' ); |
— | — | @@ -75,7 +76,7 @@ |
76 | 77 | } |
77 | 78 | } |
78 | 79 | |
79 | | - $newQrCode = new MWQrCode( $parser, $ecc, $size, $margin ); |
| 80 | + $newQrCode = new MWQrCode( $parser, $ecc, $size, $margin, $scheme ); |
80 | 81 | return $newQrCode->showCode( $label ); |
81 | 82 | } |
82 | 83 | |
— | — | @@ -100,19 +101,21 @@ |
101 | 102 | private $_ecc; // error correction |
102 | 103 | private $_size; // qrcode size |
103 | 104 | private $_margin; // qrcode margin |
| 105 | + private $_scheme; // force the protocol to be http or https? |
104 | 106 | |
105 | 107 | /** |
106 | 108 | * Set qrcode properties |
107 | 109 | * |
108 | 110 | * @param $parser Parser |
109 | 111 | */ |
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; |
112 | 114 | $this->_parser = $parser; |
113 | 115 | $this->_title = $parser->getTitle(); |
114 | 116 | $this->_ecc = ( $ecc ) ? $ecc : $wgQrCodeECC; |
115 | 117 | $this->_size = ( $size ) ? $size : $wgQrCodeSize; |
116 | 118 | $this->_margin = ( $margin ) ? $margin : $wgQrCodeBoundary; |
| 119 | + $this->_scheme = ( $scheme ) ? $scheme : $wgQrCodeForceScheme; |
117 | 120 | } |
118 | 121 | |
119 | 122 | /** |
— | — | @@ -121,13 +124,20 @@ |
122 | 125 | */ |
123 | 126 | public function showCode( $label = false ){ |
124 | 127 | |
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) |
126 | 129 | 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; |
130 | 132 | } 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'] : '' ); |
132 | 142 | $this->_uploadComment = 'Encoded URL for '.$this->_title->getFullText(); |
133 | 143 | } |
134 | 144 | |