I'm trying to execute the following function on every page that exists for an uploaded file: {{filepath:{{PAGENAME}}.pdf}}
So, if I uploaded a file called "File.pdf", on the wiki page for File.pdf, I'd expect {{PAGENAME}} to return "File". I'd expect the entire function to return something like: http://mywiki.com/mediawiki/images/4/4d/File.pdf
Instead, nothing at all is returned when PAGENAME is embedded within filepath. If I type the expression without {{PAGENAME}}, i.e. {{filepath:File.pdf}}, it works fine and returns: http://mywiki.com/mediawiki/images/4/4d/File.pdf
Is it just not possible to embed magic words in string functions, or am I missing some escape character or something?
Thanks in advance, -Dana
{{filepath}} isn't a string function: it's built in like {{PAGENAME}}.
Anyway, {{PAGENAME}} includes a file page's extension, so you just want {{filepath:{{PAGENAME}}}}.
Hi Benjamin,
Thanks so much for the quick reply.
Indeed, you are right that there is no trouble embedding magic words as you said. I hadn't realized, but the problem is actually that I have the magic word within a template. So when I use it, it references the PAGENAME of that template, rather than the page that the template is being transcluded on. Is there a way so that the PAGENAME can refer to the final page it's being transcluded on rather than just the template?
Thanks again and apologies for misspecifying my problem.
-Dana
On Sat, Jan 21, 2012 at 11:44 PM, Benjamin Lees emufarmers@gmail.com wrote:
{{filepath}} isn't a string function: it's built in like {{PAGENAME}}.
Anyway, {{PAGENAME}} includes a file page's extension, so you just want {{filepath:{{PAGENAME}}}}.
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
On Sun, Jan 22, 2012 at 12:42 AM, Dana Chandler dchandler@gmail.com wrote:
So when I use it, it references the PAGENAME of that template, rather than the page that the template is being transcluded on. Is there a way so that the PAGENAME can refer to the final page it's being transcluded on rather than just the template?
I might still be fuzzy on precisely what you're doing. To be clear, you're creating Template:Foo with {{filepath:{{PAGENAME}}}} in it and then embedding it on File:Bar.pdf? That produces a working image link on my wiki, with PAGENAME expanded to Bar.pdf, not Foo.
What version of MediaWiki are you running?
Hi Benjamin,
You're right that that works as well, but still doesn't solve my problem. Let me try to give a bit more detail on the problem, since describing subparts hasn't been useful.
I'm trying to use the EmbedPDF extension so that each File:Foo.pdf page has an embedded image of the pdf. I was using the extension (which creates <pdf> </pdf> tags) and I thought the template was causing the problem, but it's really the modification to the extension so that it accepts magic words.
Ordinarily, the extension accepts input like <pdf>http://location.com/File.pdf</pdf> or <pdf>FileonWiki.pdf</pdf>.
However, I'm trying to modify the extension to accept magic words so that I can invoke either <pdf>http://mywiki.com/mediawiki/images/4/4d/File.pdf</pdf> or <pdf>FileonWiki.pdf</pdf> by using <pdf>{{filepath:{{PAGENAME}}}}</pdf> or <pdf>{{PAGENAME}}</pdf>. There was a proposed solution to a similar problem that was posted here (http://www.mediawiki.org/wiki/Extension_talk:EmbedPDF#URI_error_.28semantic_...), but it doesn't seem to work since the $input variable ends up as {{filepath:{{PAGENAME}}}} rather than the filepath.
Thanks again incredibly for all of your help. I've been unable to solve this problem after trying many different things.
Below is the code for the EmbedPDF extension with commented out code note for where I made the modification to accept magic words:
<?php /** * MediaWiki EmbedPDF extension * * @version 0.1 * @author Dmitry Shurupov * @link http://www.mediawiki.org/wiki/Extension:EmbedPDF */
$wgExtensionCredits['parserhook'][] = array( 'name' => 'EmbedPDF', 'author' => 'Dmitry Shurupov', 'version' => '0.1', 'url' => 'http://www.mediawiki.org/wiki/Extension:EmbedPDF', 'description' => 'Allows to embed .pdf documents on a wiki page.', );
$wgExtensionFunctions[] = 'registerEmbedPDFHandler';
function registerEmbedPDFHandler () { global $wgParser; $wgParser->setHook( 'pdf', 'embedPDFHandler' ); }
function makeHTMLforPDF ( $path, $argv ) { if (empty($argv['width'])) { $width = '1000'; } else { $width = $argv['width']; }
if (empty($argv['height'])) { $height = '700'; } else { $height = $argv['height']; } return '<object data="'.$path.'" width="'.$width.'" height="'.$height.'" type="application/pdf"></object>'; }
function embedPDFHandler ( $input, $argv ) { if (!$input) return '<font color="red">Error: empty param in <pdf>!</font>';
/* ---> Portion added in so that it accepts magic words
if (preg_match('/^{{filepath:{{[^}]+}}}}$/i', $input)) return makeHTMLforPDF( $input, $argv ); */
/* ---> Note: If instead of the above "return makeHTMLforPDF" line you write,
return '<font color="red">Match: '.$input.'</font>';
it returns: {{filepath:{{PAGENAME}}}} rather than http://mywiki.com/mediawiki/images/4/4d/File.pdf */
if (preg_match('/^[^/]+.pdf$/i', $input)) { $img = Image::newFromName( $input ); if ($img != NULL) return makeHTMLforPDF( $img->getURL(), $argv ); }
if (preg_match('/^http://[\w-_]+(.[\w-_]+)+([\w-.,@?^=%&:/~+#]*[\w-@?^=%&/~+#])?.pdf$/i', $input)) return makeHTMLforPDF( $input, $argv ); else return '<font color="red">Error: bad URI in <pdf>!</font>'; } ?>
On Sun, Jan 22, 2012 at 8:45 AM, Benjamin Lees emufarmers@gmail.com wrote:
On Sun, Jan 22, 2012 at 12:42 AM, Dana Chandler dchandler@gmail.com wrote:
So when I use it, it references the PAGENAME of that template, rather than the page that the template is being transcluded on. Is there a way so that the PAGENAME can refer to the final page it's being transcluded on rather than just the template?
I might still be fuzzy on precisely what you're doing. To be clear, you're creating Template:Foo with {{filepath:{{PAGENAME}}}} in it and then embedding it on File:Bar.pdf? That produces a working image link on my wiki, with PAGENAME expanded to Bar.pdf, not Foo.
What version of MediaWiki are you running?
MediaWiki-l mailing list MediaWiki-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
mediawiki-l@lists.wikimedia.org