Extension talk:QrCode
Add topicPlease use the Add Topic link above to add a new issue.
Also, please enable debugging in your LocalSetting.php file like so:
$wgDebugLogFile = '/tmp/wiki.log';
and then grep what is being added to that log and has QrCode in hit: i.e.
~ # tail -f /tmp/wiki.log | grep QrCode
Supply that information when you report problems. Thanks!
Class Job not found
[edit]I am getting the following error on using this extension on my MediaWiki 1.12 version:
Fatal error: Class 'Job' not found in /var/lib/mediawiki/extensions/QrCode/QrCode.php on line 162
The requirement does say 1.12 or above so it should have worked...Any ideas?
--Modest 16081982 22:44, 27 October 2010 (UTC)
- I'm not sure when exactly the Job class was introduced, but from what I can judge, it has been in mw 1.6. Thus it should work with 1.12.
Can you check whether you have the /includes/JobQueue.php file? --Kwisatz
Never mind. I just upgraded to 1.15 and now will test it with it.--Modest 16081982 06:19, 13 December 2010 (UTC)
MW1.16 : Call to a member function addWikiText()
[edit]Hi,
when saving page, I get following message in the apache logfile :
PHP Fatal error: Call to a member function addWikiText() on a non-object in /server/www/trunk/mediawiki/extensions/QrCode/QrCode.php on line 191
and following in the browser :
Detected bug in an extension! Hook fnAddToWatch failed to return a value; should return true to continue hook processing or false to abort. Backtrace: #0 /server/www/trunk/mediawiki/includes/Article.php(2099): wfRunHooks('ArticleSaveComp...', Array) #1 /server/www/trunk/mediawiki/includes/Article.php(1791): Article->doEdit(''''MediaWiki wu...', '', 98) #2 /server/www/trunk/mediawiki/includes/EditPage.php(1047): Article->updateArticle(''''MediaWiki wu...', '', false, false, false, '') #3 /server/www/trunk/mediawiki/includes/EditPage.php(2552): EditPage->internalAttemptSave(false, false) #4 /server/www/trunk/mediawiki/includes/EditPage.php(389): EditPage->attemptSave() #5 /server/www/trunk/mediawiki/includes/EditPage.php(271): EditPage->edit() #6 /server/www/trunk/mediawiki/includes/Wiki.php(553): EditPage->submit() #7 /server/www/trunk/mediawiki/includes/Wiki.php(70): MediaWiki->performAction(Object(OutputPage), Object(Article), Object(Title), Object(User), Object(WebRequest)) #8 /server/www/trunk/mediawiki/index.php(117): MediaWiki->performRequestForTitle(Object(Title), Object(Article), Object(OutputPage), Object(User), Object(WebRequest)) #9 {main}
Any idea what's going on ? Adding a
global $wgOut
didn't help
Thanks
- I'm not sure that is related to the QrCode extension. It doesn't use the mentioned fnAddToWatch hook. Maybe you have another extension that does not return a value? --Clausekwis 11:41, 23 February 2011 (UTC)
Use another URL
[edit]unfortunately label parameter gets sanitized. To specify an URL, code needs to be changed like this :
public function showCode( $label = false ){ // Check for a provided label and use the page URL as default. // Also strip all non-alphanumeric characters if ( $label ) { if(eregi('^(http|https)://',$label)) { $this->_label = $label; } else { $this->_label = preg_replace("/[^0-9a-zA-Z_]+/", "", $label); } $this->_uploadComment = $label; // should we sanitize this?
- I have removed all sanitizing from the label as I don't exactly remember where I saw a problem with this. It is probably a remainder from before the md5()ing of the filename. --Clausekwis 12:27, 23 February 2011 (UTC)
Not working with MW1.15.5 also
[edit]I added the following wikitext in one of my pages on my Mediawiki version 1.15 on my Debian Lenny system:
{#qrcode:}} This is Test Page 2
and I get the following warning messages at the top of the page with NO QR Code image generated:
Warning: file_put_contents(/usr/share/mediawiki-extensions/QrCode/phpqrcode/qrcode7AaP9U-errors.txt) function.file-put-contents: failed to open stream: Permission denied in /usr/share/mediawiki-extensions/QrCode/phpqrcode/qrtools.php on line 106
Also there is specific version of QRCode that I should be using with MW1.15? --Modest 16081982 06:23, 13 December 2010 (UTC)
- Have you checked that your webserver has write permissions on the folder mentioned in your above error message? i.e. /usr/share/mediawiki-extensions/QrCode/phpqrcode/ --Clausekwis 11:33, 23 February 2011 (UTC)
- Also please try the latest revision of the extension as the location for logfiles has changed. --Clausekwis 12:51, 23 February 2011 (UTC)
QrCodes not placed on page?
[edit]It seems that the QrCodes on my pages are created, as i can see in my FTP program. The issue is that they don't appear on the page itself. I wrote a template for it, that worked a while for me. There are some pages that have the codes on the pages itself. The new created pages have the same template and the QrCode isn't showing up while it is created. Any idea?
What are the required folders on the server for this extension to have it worked and what CHMODS are required to those folders?
- Can you please enable debugging in your LocalSettings.php file and grep for anything containing 'QrCode'?
- Successful creation of a qrcode looks like this:
QrCode::_generate: Generated qrcode file /tmp/qrcodeqfiBWc with ecc M, 4 and boundary 0. DatabaseBase::query: Writes done: INSERT INTO `job` (job_id,job_cmd,job_namespace,job_title,job_params) VALUES (NULL,'uploadQrCode','2','Kwisatz/Sandbox','a:3:{s:7:\"tmpName\";s:17:\"/tmp/qrcodeqfiBWc\";s:7:\"dstName\";s:39:\"QR-dc4e51355bfcfe33e689f1c30e0b1f17.png\";s:7:\"comment\";s:25:\"http://www.hackerspace.lu\";}') QrCodeJob::run: Uploading qrcode, c: http://www.hackerspace.lu t: QrCode QR-dc4e51355bfcfe33e689f1c30e0b1f17.png, generated on Wed, 23 Feb 2011 13:41:50 +0100 by the QrCode Extension for page [[User:Kwisatz/Sandbox]]. \performUpload: sum:http://www.hackerspace.lu c: QrCode QR-dc4e51355bfcfe33e689f1c30e0b1f17.png, generated on Wed, 23 Feb 2011 13:41:50 +0100 by the QrCode Extension for page [[User:Kwisatz/Sandbox]]. w:FSRepo::publishBatch: wrote tempfile /tmp/qrcodeqfiBWc to /var/www/hackerspace.lu/www/w/images/6/68/QR-dc4e51355bfcfe33e689f1c30e0b1f17.png uploadQrCode User:Kwisatz/Sandbox tmpName=/tmp/qrcodeqfiBWc dstName=QR-dc4e51355bfcfe33e689f1c30e0b1f17.png comment=http://www.hackerspace.lu
- Hereby i can add some of the code, it's placed here for as long as needed: http://dpaste.org/kOFv/
1.17
[edit]Is anyone working on making this work for 1.17? rotsee 20:33, 11 July 2011 (UTC)
- Yes, we're currently working on it and will commit to subversion as soon as we have completed all of our tests. --Clausekwis 08:01, 12 July 2011 (UTC)
- That's beautiful, thanks! rotsee 11:23, 26 July 2011 (UTC)
A solution for 1.17.0
[edit]This is a quick solution for those who has downloaded a version of this extension and want to make work on MediaWiki 1.17.0
On file QrCode.php fun method UploadQrCodeJob::run() you may replace this piece of code:
public function run() {
global $wgOut;
$mUpload = new UploadFromFile();
By something like this:
public function run() {
global $wgOut;
global $wgRequest;
global $_FILES;
$_FILES['AUXILIAR_QRCODE_FILE'] = array(
'name' => $this->_tmpName,
'type' => 'image/png',
'tmp_name' => $this->_tmpName,
'error' => UPLOAD_ERR_OK,
'size' => 1);
$webRequestUpload = new WebRequestUpload($wgRequest, 'AUXILIAR_QRCODE_FILE');
$mUpload = new UploadFromFile();
$mUpload->initialize( $this->_dstFileName, $webRequestUpload); // we don't know the filesize, how could we?
--Daemonraco 16:54, 15 August 2011 (UTC)
- Did someone get this to work on 1.17? For me, instead of an image, the digit "1" shows up...
- Never mind, I was using version 0.08, downloaded 0.09 from trunk now, an it works like a charm! rotsee 19:15, 26 September 2011 (UTC)
Two Tweaks (for URL and Image)
[edit]Tweaks
[edit]First tweak I present is base on something posted avobe. I just added the keyword url to make a difference between a simple label and an URL.
The second tweak I present is the addition of keyword isize to resize a thumbnail. Even though there's a keyword called size, this affects directly the image generation and not the size of a thumbnail. In my case, I rather create an image of 500px and then I show it with different sizes use the MediaWiki auto-thumb functionality (visit Help:Images for more information).
The problem I had was to create a big enough QrCode image and not been able to show it in 200x200 pixels.
Search and Replace (Implementation)
[edit]Search:
foreach( $params as $pair ) {
$rpms = explode( '=', $pair );
if( $rpms[0] == 'ecc' ) $ecc = $rpms[1];
if( $rpms[0] == 'size' ) $size = $rpms[1];
if( $rpms[0] == 'boundary' ) $margin = $rpms[1];
if( $rpms[0] == 'label' ) $label = $rpms[1];
}
$newQrCode = new MWQrCode( $parser, $ecc, $size, $margin );
return $newQrCode->showCode( $label );
}
Replace:
foreach( $params as $pair ) {
$rpms = explode( '=', $pair );
if( $rpms[0] == 'ecc' ) $ecc = $rpms[1];
if( $rpms[0] == 'size' ) $size = $rpms[1];
if( $rpms[0] == 'boundary' ) $margin = $rpms[1];
if( $rpms[0] == 'label' ) $label = $rpms[1];
if( $rpms[0] == 'url' ) $url = $rpms[1];
if( $rpms[0] == 'isize' ) $isize = $rpms[1];
}
$newQrCode = new MWQrCode( $parser, $ecc, $size, $margin, $isize);
return $newQrCode->showCode($label, $url);
Search:
private $_margin; // qrcode margin
Replace:
private $_margin; // qrcode margin
private $_isize; // image size
Search:
public function __construct( $parser, $ecc = false, $size = false, $margin = false ) {
global $wgQrCodeECC, $wgQrCodeSize, $wgQrCodeBoundary, $wgQrCodeBot;
$this->_parser = $parser;
$this->_title = $parser->getTitle();
$this->_ecc = ( $ecc ) ? $ecc : $wgQrCodeECC;
$this->_size = ( $size ) ? $size : $wgQrCodeSize;
$this->_margin = ( $margin ) ? $margin : $wgQrCodeBoundary;
}
Replace:
public function __construct( $parser, $ecc = false, $size = false, $margin = false, $isize=false) {
global $wgQrCodeECC, $wgQrCodeSize, $wgQrCodeBoundary, $wgQrCodeBot;
$this->_parser = $parser;
$this->_title = $parser->getTitle();
$this->_ecc = ( $ecc ) ? $ecc : $wgQrCodeECC;
$this->_size = ( $size ) ? $size : $wgQrCodeSize;
$this->_margin = ( $margin ) ? $margin : $wgQrCodeBoundary;
$this->_isize = $isize;
}
Search:
public function showCode( $label = false ){
Replace:
public function showCode($label=false , $url=false) {
Search:
} else {
$this->_label = $this->_title->getFullURL();
$this->_uploadComment = 'Encoded URL for '.$this->_title->getFullText();
}
Replace:
} else {
if($url) {
$this->_label = urldecode($url);
} else {
$this->_label = $this->_title->getFullURL();
$this->_uploadComment = 'Encoded URL for '.$this->_title->getFullText();
}
}
Search:
private function _displayImage( $file ){
$ft = $file->getTitle();
return '[['.$ft->getFullText().']]';
}
Replace:
private function _displayImage( $file ){
$ft = $file->getTitle();
return '[['.$ft->getFullText().($this->_isize?"|{$this->_isize}":'').']]';
}
Usage
[edit]For the image tweak, you may write something like this
{{#qrcode:|isize=200px}}
For the URL tweak, you may write something like this
{{#qrcode:|url=http://www.example.com/}}
--Daemonraco 02:52, 17 August 2011 (UTC)
QrCode in Sidebar
[edit]If you wish to have a QrCode for each page of you wiki you may do this (if you need an example you may visit my personal wiki and see this tweak working).
--Daemonraco 01:18, 19 August 2011 (UTC)
First: Font Code
[edit]The first thing is to add a little code creating a file called $IP/extensions/QrCode/QrCodeSidebar.php and filling it with:
<?php
$wgQrCodeInSidebar = false;
$wgQrCodeInSidebarConf = array(
'ecc' => 'L',
'size' => '6',
'margin' => '0',
'isize' => '128px'
);
// Hook to modify the sidebar
$wgHooks['SkinBuildSidebar'][] = 'QrCodeInSidebar';
function QrCodeInSidebar($skin, &$bar) {
global $wgQrCodeInSidebar;
global $wgQrCodeInSidebarConf;
global $wgParser;
global $wgScriptPath;
global $wgRequest;
global $wgTitle;
if(!$wgQrCodeInSidebar) {
return $bar;
} else {
$ok = true;
$action = "".$wgRequest->getText('action');
$ok = (!$action || in_array($action, array('view','purge')));
$ok = ($ok && !$wgTitle->getNamespace());
if($ok) {
$newQrCode = new MWQrCode($wgParser,
$wgQrCodeInSidebarConf['ecc'],
$wgQrCodeInSidebarConf['size'],
$wgQrCodeInSidebarConf['margin'],
$wgQrCodeInSidebarConf['isize']);
$bar['qrcode'] = "<center>".$wgParser->recursiveTagParse($newQrCode->showCode())."</center>";
return true;
} else {
return $bar;
}
}
}
?>
Second: Activating It
[edit]Now you need to modify you LocalSettings.php and add these lines at the end (or wherever you see fit):
require_once "$IP/extensions/QrCode/QrCodeSidebar.php";
$wgQrCodeInSidebar = true;
Note
[edit]This will add a QrCode to each page except those under a namespace. This is made in this way to avoid cyclic image creations.
Make QR image non clickable?
[edit]Hi.
Great extension, but I have one issue. The actual QR image is clickable which then takes you to the image page. What would be nice is if the MW image mark-up equivalent to link= could be implemented so the image just shows without a clickable link. It is after all a camera oriented image rather than one you click!
--Mitchelln 10:21, 27 September 2011 (UTC)
Maintenance?
[edit]Is this extension being maintained? I think it would be an excellent feature for authors to use when citing Wikipedia or other MediaWiki contents. Badon (talk) 23:21, 11 March 2012 (UTC)