Hey,
On my local wiki I have a page with the name "File:Blue marker.png". The following code returns false:
$title = Title::makeTitle( NS_FILE, $file ); $title->exists();
That used to return true in the past. Not sure what is broken - my wiki or MediaWiki itself.
What I want to do is go from string page name, such as "File:Blue marker.png", to full URL, such as " http://localhost/phase3/images/6/6f/Blue_marker.png". What is the recommended way of doing this now (that works on MW 1.19 and later)?
Cheers
-- Jeroen De Dauw - http://www.bn2vs.com Software craftsmanship advocate Evil software architect at Wikimedia Germany ~=[,,_,,]:3
Don't know, if that's the correct way, but it is done in SRF for the excel format: https://github.com/SemanticMediaWiki/SemanticResultFormats/blob/master/forma...
On 19 January 2015 at 19:45, Jeroen De Dauw jeroendedauw@gmail.com wrote:
Hey,
On my local wiki I have a page with the name "File:Blue marker.png". The following code returns false:
$title = Title::makeTitle( NS_FILE, $file ); $title->exists();
That used to return true in the past. Not sure what is broken - my wiki or MediaWiki itself.
What I want to do is go from string page name, such as "File:Blue marker.png", to full URL, such as " http://localhost/phase3/images/6/6f/Blue_marker.png". What is the recommended way of doing this now (that works on MW 1.19 and later)?
Cheers
-- Jeroen De Dauw - http://www.bn2vs.com Software craftsmanship advocate Evil software architect at Wikimedia Germany ~=[,,_,,]:3 _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Somebody can correct me, but:
$title = Title::makeTitle( NS_FILE, $filename ); $file = wfLocalFile( $title ); $file->getUrl(); // $file->getFullUrl(); // ...
*-- * *Tyler Romeo* Stevens Institute of Technology, Class of 2016 Major in Computer Science
On Mon, Jan 19, 2015 at 1:45 PM, Jeroen De Dauw jeroendedauw@gmail.com wrote:
Hey,
On my local wiki I have a page with the name "File:Blue marker.png". The following code returns false:
$title = Title::makeTitle( NS_FILE, $file ); $title->exists();
That used to return true in the past. Not sure what is broken - my wiki or MediaWiki itself.
What I want to do is go from string page name, such as "File:Blue marker.png", to full URL, such as " http://localhost/phase3/images/6/6f/Blue_marker.png". What is the recommended way of doing this now (that works on MW 1.19 and later)?
Cheers
-- Jeroen De Dauw - http://www.bn2vs.com Software craftsmanship advocate Evil software architect at Wikimedia Germany ~=[,,_,,]:3 _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On 1/19/15, Jeroen De Dauw jeroendedauw@gmail.com wrote:
Hey,
On my local wiki I have a page with the name "File:Blue marker.png". The following code returns false:
$title = Title::makeTitle( NS_FILE, $file ); $title->exists();
That used to return true in the past. Not sure what is broken - my wiki or MediaWiki itself.
You're sure about that? I think you're just mixing up $title->exists() and $title->isKnown().
$title = Title::makeTitle( NS_FILE, $filename ); $file = wfLocalFile( $title ); $file->getUrl();
That's generally right, but depending on the exact context, the following might be more appropriate:
$title = Title::makeTitle( NS_FILE, $filename ); $file = wfFindFile( $title ); $file->getFullUrl(); // or $file->getCanonicalUrl(); if you need the protocol.
wfLocalFile will always return a file object even if there is no file by that name (And it will take its best guess at the url even for non-existent files). If the name given would normally be a foreign file, wfLocalFile( 'Foo.jpg' )->getUrl() would return what the url would be if there was a local file of that name. On the other hand, wfFindFile will return the appropriate (possibly foreign) file for that name or false if none exists.
In almost all cases you would probably want the wfFindFile behavior and not wfLocalFile().
--bawolff
Hey,
Now trying this code: wfFindFile( $title );
With this title object as input: http://pastebin.com/7B9n1NyN (constructed with Title::makeTitle( NS_FILE, $fileName ))
The output is still false. At the same time, the page definitely exists, and if I put "[[File:Blue marker.png]]" in a wiki page, it shows up just fine. I double checked my file permissions, and they seem fine. What am I missing?
Cheers
-- Jeroen De Dauw - http://www.bn2vs.com Software craftsmanship advocate Evil software architect at Wikimedia Germany ~=[,,_,,]:3
I think you have a double 'File:' prefix in there which may be confusing things. Try Title::newFromText($fileName) if $fileName already includes 'File:' prefix.
-- brion
On Tue, Jan 20, 2015 at 11:42 AM, Jeroen De Dauw jeroendedauw@gmail.com wrote:
Hey,
Now trying this code: wfFindFile( $title );
With this title object as input: http://pastebin.com/7B9n1NyN (constructed with Title::makeTitle( NS_FILE, $fileName ))
The output is still false. At the same time, the page definitely exists, and if I put "[[File:Blue marker.png]]" in a wiki page, it shows up just fine. I double checked my file permissions, and they seem fine. What am I missing?
Cheers
-- Jeroen De Dauw - http://www.bn2vs.com Software craftsmanship advocate Evil software architect at Wikimedia Germany ~=[,,_,,]:3 _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Also try using Title::makeTitleSafe instead of Title:makeTitle.
Your $fileName might not be in the proper dbKey format (use of spaces, etc...) in which case the Title you get would be corrupt since makeTitle doesn't sanitize the text you give.
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://danielfriesen.name/]
On 2015-01-20 11:46 AM, Brion Vibber wrote:
I think you have a double 'File:' prefix in there which may be confusing things. Try Title::newFromText($fileName) if $fileName already includes 'File:' prefix.
-- brion
On Tue, Jan 20, 2015 at 11:42 AM, Jeroen De Dauw jeroendedauw@gmail.com wrote:
Hey,
Now trying this code: wfFindFile( $title );
With this title object as input: http://pastebin.com/7B9n1NyN (constructed with Title::makeTitle( NS_FILE, $fileName ))
The output is still false. At the same time, the page definitely exists, and if I put "[[File:Blue marker.png]]" in a wiki page, it shows up just fine. I double checked my file permissions, and they seem fine. What am I missing?
Cheers
-- Jeroen De Dauw - http://www.bn2vs.com Software craftsmanship advocate Evil software architect at Wikimedia Germany ~=[,,_,,]:3 _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
wikitech-l@lists.wikimedia.org