Page MenuHomePhabricator

"Add leading zeros" magic word
Closed, ResolvedPublic


Author: emddudley

I'd like to request a "magic word" similar to {{formatnum:}} that pads a number
with leading zeros.

Many images on Commons are uploaded as a series with leading zeros on the
image's index. For example, all of the images at have leading zeros.
Many cameras default to using leading zeros in their filenames. Automatically
generating these filenames in a template is difficult.

I don't want to encourage leading zeros in filenames, but if someone wants to
upload a large number of images, it's a huge pain to rename them all.


  • {{padzeros:2|4}} would render as 0002
  • {{padzeros:02|4}} as 0002
  • {{padzeros:0002|2}} as 02
  • {{padzeros:1024|-1}} as 1024
  • {{padzeros:1024|2}} as 1024

Version: unspecified
Severity: enhancement



Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:24 PM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz7044.
bzimport added a subscriber: Unknown Object (MLST).

robchur wrote:

Added two new colon functions in SVN trunk, r16126; "padleft" and "padright":


where STRING is the start string, LENGTH is the desired end length, and
CHARACTER is an (optional) character used for padding. The format for "padright"
is identical save for the function name.