[PATCH 3/8] convert wikimedia img src to thumbnail url

Signed-off-by: klObs <jw@klobs.de>
This commit is contained in:
dodo 2013-03-31 15:42:02 +02:00 committed by klObs
parent 952ce2f9ca
commit feb4741da2
1 changed files with 33 additions and 3 deletions

View File

@ -56,9 +56,39 @@
<xsl:template match="image">
<xsl:variable name="path">
<xsl:call-template name="normalize-path">
<xsl:with-param name="path">
<xsl:value-of select="string(.)"/>
</xsl:with-param>
<xsl:with-param name="path">
<xsl:choose>
<xsl:when test="contains(string(.), '://')">
<xsl:choose>
<xsl:when test="contains(string(.), 'wikimedia.org')">
<xsl:variable name="filename">
<xsl:value-of select="string(str:tokenize(string(.),'/')[last()])"/>
</xsl:variable>
<xsl:variable name="hash">
<xsl:value-of select="concat(str:tokenize(string(.),'/')[position()=last()-2],'/',str:tokenize(string(.),'/')[position()=last()-1],'/')"/>
</xsl:variable>
<xsl:variable name="validfilename">
<xsl:choose>
<xsl:when test="contains($filename, '.svg') and string-length(substring-after($filename, '.svg'))=0">
<xsl:value-of select="concat($filename, '.png')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$filename"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="concat(substring-before(string(.),'commons/'),'commons/thumb/',$hash,$filename,'/600px-',$validfilename)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="string(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="string(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>