Difference between revisions of "Extension talk:LinkifySVG"
(→Intercepting uploaded SVG's) |
(→Intercepting uploaded SVG's) |
||
Line 18: | Line 18: | ||
== Intercepting uploaded SVG's == | == Intercepting uploaded SVG's == | ||
− | + | I've used the [[MW:Manual:Manual:Hooks/UploadForm:BeforeProcessing|UploadForm:BeforeProcessing hook]] which passes the ''UploadForm'' object containing the temp file, file size and original name. The temp file can be modified if less than a certain size and having an ''svg'' extension. I used this rather than later hooks because otherwise the content hash and size properties will not match the final file. |
Revision as of 07:31, 27 February 2009
Purpose
This extension is planned to intercept uploading of SVG files and convert any text in them into links if they contain a valid URL or are surrounded by double square brackets to indicate a wiki article.
Linkifying an SVG
First the xlink namespace must be added to the SVG opening element:
Next the XML must be parsed and any text elements with matching content converted by surrounding it with an a element. Here's an example of a text element from an SVG created with Inkscape which has been simplified a bit for clarity and linkified.
Intercepting uploaded SVG's
I've used the UploadForm:BeforeProcessing hook which passes the UploadForm object containing the temp file, file size and original name. The temp file can be modified if less than a certain size and having an svg extension. I used this rather than later hooks because otherwise the content hash and size properties will not match the final file.