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(a)gmail.com> wrote:
On Sun, Jan 22, 2012 at 12:42 AM, Dana Chandler
<dchandler(a)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(a)lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l