How Wikipedia Works/Chapter 9

Chapter 9: Images, Media, Templates and Special Characters

edit

Articles on Wikipedia can include more than simply text. Images and media files enhance content whereas templates (such as the ubiquitous infoboxes) and tables can help you lay out articles more cleanly. Well-chosen graphics and neat presentations can improve articles significantly. You can also use a number of formatting tricks. For example, you can use some HTML successfully, display special characters, and add mathematical formulas to articles. These tasks all use advanced wikisyntax, which will be covered in this chapter.

Our best advice is to learn the more advanced syntax options when you need them. Much of what is covered in this chapter, particularly information about template syntax, is not usually necessary for basic editing, but you can generally learn how to apply these enhancements quickly if you want to use them to improve an article.

Images and Media Files

edit

Images and media files are a welcome contribution to Wikipedia and complement article text in multiple ways. Images might be illustrations, diagrams, photographs, or maps; they can show the reader what an animal looks like, where a country is, or give a sense of a city's skyline. Media files might include sounds, such as the pronunciation of an unfamiliar word or a short clip of a composer's work, or videos, such as an animation of how a machine works. What all of these files have in common is that they exist to illustrate and clarify article text. Images should not be placed in articles simply for the sake of adding a pretty picture, but a good, clear image of the subject—or an appropriate sound or video file—can greatly enhance any article.

Like all other Wikipedia content, all media and images must be freely licensed. Though today you can find digital images everywhere on the Web, by and large you can't use these images directly in Wikipedia; such use is generally a copyright violation, much like copying someone else's text and uploading it as your own. A better tactic is to take photographs or produce drawings and diagrams yourself, license them freely, and then upload them to Wikipedia for use in articles.

In this section, we'll talk about how to find images on Wikipedia, how to upload your own work for use on the site (and the licensing guidelines to keep in mind when doing so, including whether you can claim a fair use rationale), and then how to embed images in pages, using the special image syntax. We'll then discuss media files such as sound and video clips.

Any discussion of images is incomplete without mentioning one of Wikipedia's sister projects, Wikimedia Commons, which serves as an image and media file repository for all of the Wikimedia projects. These days uploading and working on images on Commons, where images are more easily reusable and searchable, rather than on Wikipedia directly is preferable. A more detailed description of this project can be found in Chapter 16, Wikimedia Commons and Other Sister Projects.

Finding and Adding Images

edit

As of early 2008, Wikipedia and the Wikimedia Commons had well over 3,000,000 images. With this many images, you can most likely find existing images to use in your article. If not, anyone is welcome to upload new images to the site, as long as the images can be used in an article and are freely licensed.

Searching for Images to Use

edit

The Wikimedia Commons is probably the best place to start searching for images or media files. The easiest way to search is to use the Mayflower search engine ( you'll find a link to it on the front page of Commons); Mayflower searches image description pages on Commons for your keywords and returns a page of thumbnail-size pictures as search results. You can also go to Commons to browse media files and images by subject, as most images have been categorized extensively.

On Wikipedia itself, you can also browse images using categories. The topmost category for images is ; this category also contains images that are only used as part of the Wikipedia project (rather than in articles), such as images for WikiProject awards. Under this category you'll find and , which sorts images based on whether they are drawings, animations, and so on. One image collection especially worth visiting is Wikipedia:Featured pictures, which is a selection of some of the very best images on Wikipedia; here you can find the picture of the day and participate in image judging.

Finally, you can also search image descriptions directly on Wikipedia by searching the Image namespace, as described in Chapter 3, Finding Wikipedia's Content. Whether you get any results depends entirely on how well the image has been titled and described.

If you enjoy contributing images and want to help track down needed pictures, there are two places to look for requests for pictures: on Wikipedia and Commons:Picture requests on Commons.

Image Licenses and Fair Use

edit
 
A licencing tutorial used on Wikimedia Commons.

If you can't find an existing image for your article, you can upload a new one. But first make sure the license is acceptable. You shouldn't upload images to Wikipedia without knowing the license restrictions or without permission. All images you upload to Wikipedia must meet one of four criteria:

  • You (the person who puts the picture on Wikipedia) own the rights to the image (that is, you created it), and you agree to release the image under a free license, such as the GFDL.
  • If you didn't originally create the image, you can prove that the copyright holder has licensed the image under an acceptable free license, such as the GFDL.
  • You can prove that the image is in the public domain; this is the case with US government–created work such as photos from NASA, which are automatically placed in the public domain.
  • You produce a convincing fair-use rationale.

Playing fast and loose with the rules is very unhelpful. Do not copy images you find on the Web and call them your own. Although disregarding these points and uploading technically works anyway, many Wikipedians monitor the list of new image uploads, and without a proper license, the image will not remain on the site for long (typically, it will be deleted within a week).

The last of the criteria, fair use, is only accepted on the English-language Wikipedia (not on Commons) and is quite controversial, causing much discussion over the years. Under US copyright law, the term fair use refers generally to a limited use of a copyrighted work for educational or critical purposes. For instance, when a reviewer quotes a small segment from a book he or she is reviewing, the reviewer can do so because of fair use. On Wikipedia, the so-called fair-use policy documents when it is acceptable to use a non-free image on the site. For example, album covers appear in several articles about albums. Cover art is typically copyrighted, but the fair-use policy may mean that a small scanned image of the cover is acceptable so long as the album artwork itself is critically discussed in the article and an image of the artwork is necessary to help clarify this discussion.

Fair use is controversial on Wikipedia because the site aims to include only free content; including any copyrighted material at all is problematic given Wikipedia's license and values, and the legal aspects of what is and isn't fair use can be very difficult to determine. Given this, so-called fair-use images are only used in a very limited range of circumstances. If there is any possibility a free equivalent to a copyrighted image could be obtained instead at some point in the future (for instance, if the copyrighted image is of a living actor and another photographer might donate an equivalent photo), then the copyrighted image should not be used.

The full details of fair use on Wikipedia for images and media are something of a mouthful and are explained on Wikipedia:Non-free content (shortcut WP:NONFREE). Ten points are involved:

  • No free equivalent can exist.
  • Commercial opportunities for the copyright owner must not be affected.
  • Usage on Wikipedia must be minimal. An entire work is not used if a portion or sample would do.
  • The work must have been previously published outside Wikipedia.
  • General Wikipedia content requirements must be met, and the material must be encyclopedic.
  • Other aspects of the media-specific policy (Wikipedia:Image use policy, shortcut WP:IUP) must be met.
  • The content is used in at least one article.
  • The reader must gain significantly from the addition to an article, and the gain could not be achieved by text alone.
  • Non-free content is basically allowed only in articles and not in disambiguation pages.
  • The image description page must be completed properly.

Even so, fair-use images are often culled and deleted from the site.

The best alternative to fair use is to find a free image instead, in line with the site's mission of promoting free culture. For instance, for celebrities or politicians, releasing a single PR photo into the public domain (or under the GFDL) ensures that Wikipedia can use that picture free and clear, and everyone benefits.

Uploading Your Own Images

edit

Images must be uploaded before they can be used on the project. You can't link to images on other websites. Images can be uploaded directly to Wikipedia, or alternatively to the Wikimedia Commons, where they may be used by all Wikimedia projects (not just the English-language Wikipedia). The latter option is preferable. A description of how to upload to the Commons, which is quite similar to the process described next, is in Chapter 16, Wikimedia Commons and Other Sister Projects.

File Types

The following file types can be uploaded to Wikipedia: PNG, GIF, JPG, JPEG, XCF, SVG, DJVU, PDF, MID, and OGG. The first seven are image file formats, whereas the last three are for documents and media. According to Wikipedia:Media, the preferred file formats are JPEG (*.jpg) for images and Scalable Vector Graphics (SVG; *.svg) for drawings.

To upload an image, you must be logged in to the site. Click Upload File on the left-hand sidebar or visit Special:Upload.

The steps are simple:

Save the image or file you wish to upload to your computer.
Click Upload File on the left-hand sidebar and indicate how you got the image. Depending on the option selected, you'll be led through a series of licensing questions to answer before you get to the uploading form.
Figure 9.1. The image uploading form
The image uploading form
Once you reach the uploading form, scroll down past the warnings on the page to the form itself (Figure 9.1, “The image uploading form”).
Fill in the Source filename field; this field is for your original file. Click Browse to access the image on your computer. Once you've found the file, select it and click Open. The filename will then appear in the Source filename field.
Select the destination filename; this is the name the file will have on Wikipedia or Commons (this name will be prefaced by Image: automatically). The filename for the image on your computer is used by default, but you can edit the name to change it (see the advice on naming files below). Remember that image filenames, unlike article titles, cannot be changed once you've named them, so choose carefully.
Describe the image in the Summary field. What is the image of? When was the photo taken or the drawing created? Include as much useful information as you can—this is the only way that people searching for images will be able to find yours. This field may be pre-filled in with a template, depending on which option you chose in step 1; if so, you can fill out the appropriate parameters.
Choose the appropriate license; if you select I don't know, your image will be deleted.
Leave Watch this page checked; this way, you'll notice if the image has been tagged for deletion.
Click Upload File. You're done!

The image now resides in the Image namespace, using the filename you've given it. Once you've successfully uploaded an image, you'll be taken to its image description page; this page is located at http://en.wikipedia.org/wiki/Image:yourimagename.jpg, where yourimagename.jpg is the filename you entered in the Destination filename field. This page is also where your summary description of the image appears. Once an image is embedded in an article, anyone clicking it will be taken to this page (note that if you click an image from Commons, you will automatically see the description page from Commons instead). The information and description on this page can be edited like any other page. To link to an image description page directly (rather than displaying the image), add a colon (:) before the filename in the wikilink:

image:yourimagename.jpg

Files should be named descriptively; do not use a meaningless string of numbers and letters (such as you might get from a digital camera) or filenames such as image.jpg. Image filenames should clearly indicate the subject of the image, and image descriptions should clearly indicate the subject of the image, the photographer or image creator, and the image source. Other information that will also help document the image includes the date the image was taken, location, occasion, and so on. An image is often used in multiple articles, and obviously you have no more say in its use than any other editor does.

Though you cannot change an image filename after uploading it, you can replace an image by uploading a new version of the image with the exact same name; this change will show up in the image history. For an existing image, click the Upload a New Version of This File link, which appears under File history on the image description page.

Using Images

edit

Once you've uploaded an image, you can insert it on a Wikipedia page. Use the following syntax to insert an image on a page:

File:Nameofimage.jpg

This will display the image on the page, at the same size as the original.

Images may be floated to the left or right of the text. Laying out images on the right is more conventional for articles, though right-left alternation may also make sense, depending on the design of the article and the number of images used. For instance, standard infoboxes tend to be placed in the top-right part of an article, which will affect article layout. For an example of an article using multiple images, see Mandelbrot set, where numerous techniques are used to display and arrange images.

You can set image alignment by adding a parameter using the vertical bar or pipe character (|):

File:Nameofimage.jpg

or

File:Nameofimage.jpg

You can also display an image as a thumbnail, which will automatically size the image to 180 pixels with space for a caption at the bottom, using the thumb parameter. You do this by adding two parameters:

File:Nameofimage.jpg
This is an image caption

This is an image caption will, in this case, display below the image. Captions should describe an image completely; they can include internal or external links as necessary. You can also combine this with the alignment parameter:

File:Nameofimage.jpg
This is an image caption

This aligns the image on the right side of the page in a handy thumbnail size with a caption below it.

Rather than using the default thumbnail sizing, images can also be sized to any dimensions:

This is an image
This is an image

This will display the image at 300 pixels, left-aligned, with This is an image displayed as alternative text when a reader hovers the mouse over the image. To add this text as a caption to an image of any size, use the thumb tag with a size parameter:

File:Nameofimage.jpg
This is an image

If you have many small images and you want to display them together, try using the

This will display these six images in a neat table. No double brackets are needed around filenames in an image gallery. Find out more at Wikipedia:Gallery tag.

If you want to include a particularly wide image, such as a panorama of a city skyscape, use the template Template:Wide image. Full details are included on the template page.

As for which images should be included in an article, Wikipedia's image policies mainly deal with copyright concerns. The guideline at Wikipedia:Images does define what encyclopedic images are: An encyclopedic image is relevant to the subject at hand, clear, and good quality. Don't overwhelm your articles with images; using the thumbnail feature also ensures that pages will load more quickly for readers. The Featured Pictures project lays out more criteria for good images at Wikipedia:Featured picture criteria; many of these criteria are related to the technical quality of the image. For help improving images, you can always ask fellow editors interested in images—try the Wikipedia Graphics Lab project at Wikipedia:Graphic Lab.

Using Multimedia Files

edit

Other media files may also be used on Wikipedia. Audio files can be very helpful for some topics; for example, Wikipedia has numerous files designed to help you pronounce Chinese names properly. Chapter 3, Finding Wikipedia's Content covers how to play these files. Sound files must use the free Ogg Vorbis or the MIDI format, and video files must use the Ogg Theora format.

Considering approximately 70,000 articles are devoted to albums and singles, you might expect Wikipedia to have many music files. All music samples from copyright sources, however, have to be specifically tied into the article's description of a song or piece of music. Articles about albums are meant to inform, not to promote.

The fair-use policy also applies. The article on Bob Dylan's "All Along the Watchtower" does include a 14-second sample from the song. This short length conforms to the fair-use policy: The sample has to be minimal and not affect legitimate commercial trade.

Media files, such as sound files, are uploaded in the same way as image files. But when you link to them you replace Image with Media:

Media:Nameoffile.ogg

Though you can upload PDF files, they do not generally play a useful role on Wikipedia or the other Wikimedia projects.

To identify a sound link in an article, you can use Template:Listen, which adds a small sound icon and a handy menu for playing the file, as described at Wikipedia:Creation and usage of media files.

Further Reading

edit

Images

http://en.wikipedia.org/wiki/Wikipedia:Images An overview of using images in pages

http://en.wikipedia.org/wiki/Wikipedia:Picture_tutorial A tutorial on formatting images

http://en.wikipedia.org/wiki/Wikipedia:Extended_image_syntax More advanced image syntax

http://en.wikipedia.org/wiki/Help:Images_and_other_uploaded_files The main help page for images

http://en.wikipedia.org/wiki/Wikipedia:Finding_images_tutorial A tutorial for finding images to illustrate articles

http://commons.wikimedia.org/wiki/Commons:First_steps/Reuse Guidelines for using images from Commons

http://en.wikipedia.org/wiki/Wikipedia:Image_use_policy The image use policy, "including format, content, and copyright issues"

http://en.wikipedia.org/wiki/Wikipedia:10_things_you_did_not_know_about_images_on_Wikipedia A short list of key points about images on Wikipedia

Media

http://en.wikipedia.org/wiki/Wikipedia:Media_help A help page for playing media files

http://en.wikipedia.org/wiki/Template:Listen A template to use with sound files

http://en.wikipedia.org/wiki/Template:Audio Another template to use with sound and pronunciation files

http://en.wikipedia.org/wiki/Wikipedia:WikiProject_Spoken_Wikipedia The project to produce recordings of Wikipedia articles

Templates

edit

Templates are generally used on Wikipedia as navigational and formatting aids and to add recurring or boilerplate messages to pages in a consistent way. They are versatile and, when properly used, help with the presentation of information. A template is a page—which could contain, for instance, a navigation menu—that you can insert into a wiki page and reuse multiple times.

Each template may be included (technically transcluded) in any number of other wiki pages, from just a handful to hundreds of thousands. For programmers, a transcluded template is comparable to an #include statement or a macro that is run at page view time. Templates that you are probably familiar with now are the cleanup messages that appear at the top of articles and the stub messages that are placed at the very bottom of articles. Templates can also help incorporate complicated formatting into articles to standardize them, since templates are created once and then reused. A template can provide a consistent, flexible solution for how information displays. Wikipedians, therefore, create templates whenever similar text appears in different places. Some templates that play a major role in the site are protected, but most are editable pages, residing in their own Template namespace.

Some familiarity with templates will help any editor. Although you don't need to learn how to build your own templates in order to be a knowledgeable Wikipedia contributor, knowing the function of templates and what you can expect from them is helpful. You should understand how to use and edit them.

Using Templates

edit

If you want the same style of footer or boxed graphic to show up across all articles on a given topic, then you'll want to create a template. Similarly, if you consistently leave certain messages on user talk pages—greetings or perhaps advice—using a template provides consistency and also saves time.

To add a template to a page, just edit the page where it should go and embed the name of the template (without the Template namespace prefix) in double curly brackets where you want it to appear, like this: {{template name}}

A template can be used more than once on a single page. After saving the page, the template will display where you've placed it.

For instance, placing

{{cleanup}} at the top of an article will produce the message for readers that was illustrated in Figure 7.1, “The cleanup template message” on Section 1, “Cleanup”. The template message by itself may be viewed by going to the template page at [[Template:Cleanup]]. To see the actual source code of this template, click the Edit This Page tab (which is labeled as View Source for this protected page). The complicated-looking piece of formatting you see is actually what's being included in the rendered article when you use the shortcut {{cleanup}}. Checking Templates Used in an Article

To see all of the templates used on a page, first select the Edit This Page tab to see the wikisource. Then scroll all the way past the edit window and editing shortcuts. At the very bottom of the page, below all the other text and license information, you'll see the note Pages transcluded onto the current version of this page. Under this is a list of all the templates included on that page; click one to go to the Template page itself.

Using Parameters

edit

As a beginning editor, you'll want to edit around templates, not start changing them right away. In time you may have to edit a template, modifying it to add new text. Many templates require you to input parameters, or variables, in a specified form, which then customizes how the template displays on a particular page.

Parameters indicate or allow you to include variables that are going to be different for each template use. For instance, the template Template:WPBooks is used on the talk page of articles about books as an aid to sorting them out. This template is a WikiProject template designed to help editors work on book articles. The template looks like this before it is filled out: {{WPBooks |class = |needs-infobox = }} Each of the choices that are followed by an equal sign is an optional field that can be filled in by the person who inserts the template. For instance, you can fill in the class field with a rating reflecting the quality of the article in question at the time that you viewed it. The possible ratings are listed on the main page of the Template:WPBooks template; they are described as "FA, A, GA, B, Start, Stub, Dab, Template, Cat, NA. If blank, this will default as Unassessed." In other words, if you are reviewing an article about a book and wish to rate it as Start class, type Start after the class parameter.

The infobox parameter, on the other hand, is a simple yes/no choice. If the article needs an infobox, which is another kind of template, type yes here. If it doesn't need an infobox, you could either type no or just leave the parameter blank.

Many templates have optional parameters. For instance, the cleanup template mentioned in the previous section works best with a date parameter like this: {{Cleanup|date=May 2008}} Dating cleanup articles helps ensure that the oldest issues can be addressed first, through the system of cleanup categories by month. 2.3. How Templates Work

When just the double curly brackets are used to include a template on a page, the process is referred to as a transclusion. Some templates may require you to substitute them instead, through a process called substitution. The template directions—generally found in comments on the template page itself—will usually specify when you need to substitute a template rather than transclude it.

Substitution is done by typing {{subst:template name}} Substitution means that the template is expanded and rendered on saving the page, rather than on viewing it. That is, the wikitext that the template produces is saved into the source code of the page where the template is used. This contrasts with transclusion, where you just see the double-bracketed template name when you view the source code.

When a template is substituted, updates to the template page will not automatically propagate to the pages where the template has been placed (when a page is transcluded, they will). Substitution can be useful for pages where you want the wikitext to be closer to the rendered view that the reader sees.

Other Transclusions In fact, any wiki page, not just those in the Template namespace, can be transcluded into any other page. Simply place curly brackets around a colon and the name of the page you want to include: {{:Yourpagename}}. Transcluding subpages onto a main page is sometimes done for long pages that are broken up into many parts in the Wikipedia project space (but it is not done for articles). For instance, if you look at [[Wikipedia:Featured article candidates]], each nomination is actually on a subpage, which is transcluded onto the main FAC page with template syntax in order to give a single view of all the nominations. This feature can be helpful when you're designing your own templates—simply work on the template in a subpage of your userspace, where you can experiment at will. To test your template on another page, type {{:User:yourname/yourtemplatename}}. Of course, you will move it to the regular Template namespace when you're done. Templates can—and often do—automatically categorize the pages they are used on, as well. For instance, in the books template, if you include an infobox parameter, the discussion page of the article will automatically be added to [[Category:Book articles needing infoboxes]]. Similarly, {{cleanup}} places articles into a large category called [[Category:All articles needing cleanup]]. If you use a date parameter of August 2007 in this tag, the article will be categorized into [[Category:Cleanup from August 2007]] as well. Once the template is removed, the article will be removed from the category too.

Varieties of Templates

edit

We don't have space here to discuss all the possible uses for templates and still less space to list all the commonly used ones—Wikipedia has tens of thousands of templates. We'll review a few major types, however. Some should already be familiar to you, such as cleanup templates. Fact-checking notices are useful for interacting with the Wikipedia site, even if you have no intention of getting heavily involved. These templates raise queries about content. Besides the cleanup templates we already described in Chapters Chapter 4, Understanding and Evaluating an Article and Chapter 7, Cleanup, Projects, and Processes, which can be placed at the very top of an article to produce cleanup message boxes, you can also insert small cleanup and fact-checking templates in the text itself. Apply the templates {{fact}} and {{who}} when the source for a statement isn't clear. Another such template is {{lopsided}}, which adds a query to the article about the neutrality of the treatment. Place these templates directly by the questioned text. For example The Moon is made of old blue cheese, with the dusty surface being a space fungus that has grown on it{{fact}}. displays an inline message, such as a superscript citation needed for {{fact}} (see Figure 7.3, “The inline Citation Needed tag” on Section 2.4, “Fact-Checking and Referencing” for how this tag is used). This template also adds the article to a maintenance category, [[Category:All articles with unsourced statements]]. An infobox organizes information to display it cleanly to the reader and at the same time standardizes the presentation of essential facts about an article topic. A variety of infobox, the taxobox, is an infobox used for articles on individual species of animals or plants that present taxonomic information about that species. Infoboxes are typically rectangular, right-justified, and placed at the top of the article. You can go to [[Template:Infobox NBA Player]] to see a basketball player infobox with enough documentation on the page to see how it works (see Figure 9.2, “The NBA player infobox for Dražen Petrović” for how this infobox displays in an article). Each piece of information is a parameter that is filled in by the editor placing the infobox. To set up an infobox, visit [[Help:Infobox]]. Creating and modifying infoboxes is a little more procedural than is standard for Wikipedia. Existing infoboxes may be found on [[Wikipedia:List of infoboxes]] (shortcut WP:IB), though this page may not be consistently maintained, or on [[Category:Infobox templates]] (shortcut WP:INFO), but infoboxes are perhaps most easily found by going to similar articles or the related WikiProject. Navigation templates are also very common, particularly for article footers. For example, the template {{Popes}} is placed near the bottom of pages for any article on a pope, above the listing of categories and interwiki links. This template displays as a box listing links to all the pages about popes of the Catholic Church. As a refinement, because the template contains links to 264 other popes and is thus quite lengthy, the template detail is only displayed when you click the Show link. This kind of hidden template is commonly used for large or unwieldy navigation boxes. Hidden templates can be responsible for odd artifacts if you are using your browser search to locate a phrase on a page, however, since the browser can't "see" the text listing all the popes if the template is hidden.

Figure 9.2. The NBA player infobox for Dražen Petrović The NBA player infobox for Dražen Petrović

Another navigation aid that is versatile and useful for related articles is the succession box, which is also usually displayed at the bottom of the article. Near the bottom of Abraham Lincoln, you'll see a box that could be created by these templates: {{start box}} {{succession box | before = [[James Buchanan]] | title = [[President of the United States]] | after = [[Andrew Johnson]] | years = [[March 4]], [[1861]] - [[April 15]], [[1865]] }} {{end box}}

This displays a message telling you that Lincoln followed James Buchanan as president of the US and so on (Figure 9.3, “The succession boxes at the bottom of the Abraham Lincoln article” shows the many succession boxes used in the Lincoln article). The parameters are filled in with wikilinks. To create a succession box for some other position, edit the box's parameters by replacing, for example, President of the United States with Emperor of Mexico. In fact, go to Maximilian I of Mexico to see a stack of such boxes—a useful graphical representation of relationships for which words alone might be clumsy. is full of similar templates, but probably most editors copy and adapt these boxes from other articles.

Figure 9.3. The succession boxes at the bottom of the Abraham Lincoln article The succession boxes at the bottom of the Abraham Lincoln article

Formatting templates help you with text layout. For example, {{TOCleft}} places the table of contents on the left side of the page. This may be useful if the article also includes a right-justified infobox. Many more complicated templates can also be used for formatting within other templates or for spacing page elements, much as how CSS functions on regular web pages. Wikipedia also has dozens and dozens of templates for projects rather than articles; most of these templates are collected under and . See "Formatting Columns" on Section 3.2, “Formatting Columns” for another example of using templates to format text.

How to Build Templates

edit

You might want to postpone reading this section until you need to build your own template. Existing templates are very numerous and can easily be adapted to meet most needs. Editors are welcome to build new templates, however.

We'll use the example of building a template to place on a user talk page to welcome new users. A template already exists for this purpose at Template:Welcome, but you may want to customize it or build your own personal version from scratch. Templates may include variables, which allow the template to display different messages on individual pages depending on which parameters are input at the time the template is placed. This example illustrates how that works.

March of the Gingerbread Men

Not only are templates convenient and versatile, but they also promote a degree of uniformity that helps readers. Knowing how to navigate around a new page, based on your experience with similar pages put together from a common stock of elements, is handy, and templates also help ensure that related articles all contain similar information. Too many templates can, however, make an article hard to read and hard to edit. The pejorative cooker-cutter page also applies: Wikipedia articles should have a little more individuality than gingerbread men. See Wikipedia:Huge message boxes for a (humorous) warning to this effect.

To start a new template, begin a new page in the Template namespace. For instance, our template example will be called mywelcometemplate, and it will include a bold link to Wikipedia's help pages. On the page Template:Mywelcometemplate, you'd type the following:

click here for handy tips and help

and click Save. So far, so good. Now, when you type Template:Mywelcometemplate on any other page and click Save, you'll see this bold link rendered on the page: click here for handy tips and help.

You can then introduce a parameter. In the template definition, the formal parameter (the placeholder for the parameter value that is input) is a parameter name with three pairs of braces. So, for example, you would type {{{myVariableName}}} for a template parameter that you wanted to call myVariableName.

In this example, say you wanted to include a variable article name in your welcome message. You might type this:

If you need help with your article called "{{{articlename}}}", click here for handy tips and help.

When you include the template on a page, you'd type this:

Template:Mywelcometemplate

and when the page is rendered you'd see this:

If you need help with your article called "the article name you want to display", click here for handy tips and help.

You can also include unnamed parameters by using sequential numbers: {{{1}}}, {{{2}}}, and so on. In this case, the user could simply place the variable text he wanted to include in between pipe characters with no parameter name. For instance, if your template looks like this,

Dear {{{1}}}, if you need help with your article called "{{{2}}}", click here for handy tips and help.

you can fill it out as follows:

Template:Mywelcometemplate

And the following will display on page rendering:

Dear Mary, if you need help with your article called "Truly Tuesday", click here for handy tips and help.

Templates can become very complex, and it is beyond the scope of this book to give full instructions for coding them. Study existing templates first in order to get an idea of what is possible. Anything that may be included in a regular wiki page may also be included in a template—from ordinary text and images to wikisyntax, CSS, HTML, and even other templates. From the designer's point of view, wikisyntax still behaves as it normally would within templates. With template syntax and parser functions (template-like constructs that return a value based on at least one unnamed parameter) you can code extremely complicated templates.

The easiest way to learn how to build a template is to simply look at—and perhaps borrow—the source code of existing templates. If you are attempting to build a new infobox for a specific type of article, for instance, you can simply use existing infoboxes as a model, changing field names and sizes where necessary.

Further Reading

http://www.mediawiki.org/wiki/Help:Templates A quick, clear guide to using and creating templates with parameters

http://en.wikipedia.org/wiki/Help:A_quick_guide_to_templates A basic guide to using templates on Wikipedia

http://en.wikipedia.org/wiki/Help:Template Help with templates—advanced, detailed documentation on template features

http://en.wikipedia.org/wiki/Wikipedia:Template_namespace An introduction to templates and the Template namespace on Wikipedia

http://en.wikipedia.org/wiki/Wikipedia:Template A list of standard template messages for articles and project pages, including standard cleanup templates

http://en.wikipedia.org/wiki/Category:Citation_templates Citation and reference templates

Laying Out Articles

edit

Besides sections, paragraphs, and basic wikisyntax, templates and tables are the two primary tools used to lay out and format articles. Special layout templates have now replaced many of the functions that tables were once used for on Wikipedia (for example, infoboxes were once table-driven). However, tables are still very useful for presenting data, such as multicolumn lists. Templates and tables can also be combined; for instance, tables can be included in templates if necessary.

Tables

edit

Tables provide a neat way to organize any information that is best presented in a row-and-column format. Tables should always be used judiciously, however, because they make the wikisyntax less readable. Many dedicated "List of …" articles use tables because they can display several data elements compactly (see Figure 9.4, “A multirow, multicolumn list that uses a table form List of best-selling singles in Japan”). They are not usually necessary in basic articles; generally you can use a simple list instead.

Figure 9.4. A multirow, multicolumn list that uses a table form List of best-selling singles in Japan A multirow, multicolumn list that uses a table form List of best-selling singles in Japan

A table is the easiest way to lay out any kind of data array or multicolumn, multirow list. "When to Use Tables," a guide in the Manual of Style, says, "if the information you are editing is not tabular in nature, it probably does not belong in a table." For visual layout (i.e., laying out a page to look pretty, rather than presenting data), tables have been replaced by templates and embedded wiki markup, such as image markup and CSS.

MediaWiki provides an integrated table syntax, special wikicode used for brevity. This code functions much like and is structurally the same as table markup in HTML (which also works in MediaWiki, though it shouldn't generally be used). Table syntax uses the pipe (|) as the main separator element and is thus sometimes called pipe code. This code will now be described in detail. You may also read about pipe code at [[Help:Tables#Pipe syntax tutorial]], which details more elaborate table syntax, including formatting individual rows and cells. The entire table is encased with curly brackets and a vertical bar (a pipe). So you use {| to begin a table and |} to end it. Each tag needs to be on its own line: {| table code goes here |} Table formatting information, such as border width, can be placed on the first line, after {|. An optional table caption is included by inserting a line starting with a vertical bar and plus sign, |+, with the caption after it: {| border=1 |+ The table's caption table code goes here |} To start a new table row, type a pipe and a hyphen,|-, on its own line. The codes for the cells in that row will start on the next line. {| border=1 |+ The table's caption |- row code goes here |- row code goes here |} Type the codes for each cell in the row on a new line, starting with a pipe: {| border=1 |+ The table's caption |- | first cell code in the row goes here | second cell code in the same row goes here |- | first cell code in the next row goes ... |} Cells can be separated with either a new line and new pipe or by a double pipe (||) on the same line. Both produce the same output: {| border=1 |+ The table's caption |- |Row 1, Cell 1 || Cell 2 || Cell 3 |- |Row 2, Cell A |Cell B |Cell C |} Finally, column headers may be added with a line beginning with an exclamation point (!) at the beginning of the table. For instance, in Figure 9.5, “The two math styles from a section of the article on E=mc2”, the column headers are: {| !Rank !Year !Sales !Chart Peak !Title !Artist |- ... |} Column headers can also be separated by a double exclamation point (!!) on the same line. Column headers will typically display in bold font and be centered at the top of the column. Styling information for the column (such as width, color, etc.) may also be placed in a column heading, using CSS formatting; see [[Help:Table]] for details. One new development (since 2007) are sortable tables, where a reader can sort any column of data in a table by pressing a button at the top of a table column, first in ascending order and then toggling between ascending and descending order. This is achieved by using JavaScript. To make any table sortable, add class=sortable in the header of the template, next to {|, where style information and CSS also go. You can find more details at [[Help:Sorting]].

Formatting Columns

edit

If you simply want to format text into columns, rather than order it in table format, you can also use formatting templates. Templates or tables are the only ways to produce true column layout in MediaWiki. Any list of items can be broken into several columns with the templates {{col-begin}}, {{col-break}}, and {{col-end}}. These templates are a quick way to make a long list of short items take up less space on the page and save readers from excessive scrolling. Place {{col-begin}} to start the column section, {{col-break}} within the list at each column beginning, and {{col-end}} to close the column section. For instance, {{Col-begin}} {{Col-break}} Column 1 list items here {{Col-break}} Column 2 list items here {{Col-break}} Column 3 list items here {{Col-end}} will produce a three-column layout. More examples can be seen in the template documentation for the [[Template:Col-begin]] template. To produce a list of references in two or more columns, you need the {{reflist}} template, which can replace the <references/> tag when using footnoted references. For instance, if you have a long list of footnotes and you want them to display in two columns, use {{reflist|2}} in place of <references/>. Use {{reflist|3}} for a list of references in three columns, and so on. The {{reflist}} template also conveniently makes footnotes display in a smaller font, so they take up less space. Further Reading

http://en.wikipedia.org/wiki/Help:Tables Help with tables

http://en.wikipedia.org/wiki/Wikipedia:When_to_use_tables Guidelines for using tables in articles

http://en.wikipedia.org/wiki/Help:Sorting Information about sortable tables

http://en.wikipedia.org/wiki/Category:Table_and_column_templates Layout templates

Special Syntax

edit

Because MediaWiki serves many purposes, it has many resources for expanding and presenting standard text.

HTML and CSS

edit

Despite the encouraging remark made earlier, that you don't need to know HTML to edit Wikipedia, around 40 HTML tags are permitted. A full list is at [[Help:HTML in wikitext]].

HTML tags that are useful include <small> and <big> for making text small or large, respectively. In articles, these tags have few uses, but they can be helpful in laying out user pages or templates. Other HTML tags that are useful include <div> for making formatting divisions, <s> or <del> for strikethrough text, and <sub> and <sup> for making subscript or superscript characters. HTML should not generally be used for formatting tables or laying out pages. For most tasks that HTML can do, customized MediaWiki syntax exists instead. Whenever wikisyntax can do the job of HTML, the wikisyntax is preferred. Unnecessary HTML should not be used in articles. The use of Cascading Style Sheet (CSS) syntax is also widespread, primarily in formatting templates. The look of the site as a whole is styled with CSS skins that are individually customizable by any logged-in user; see Chapter 11, Becoming a Wikipedian. 4.2. Mathematical Formulas Science and technology articles may need a sprinkling of mathematical notations or symbols. As of 2008, the treatment of mathematics on Wikipedia is a mixture of two basic styles (and therefore is a potentially confusing work in progress). Definitive Math HTML is not yet in use. This is likely to remain the case until the development time is set aside to find a solution: In other words, it will be a while. The two ways to display mathematics are to use HTML coding or TeX markup, described here. A minimum requirement for writing basic mathematics is to be able to code exponents and subscripts, for example, to express a simple formula or to write numbers in scientific notation. Superscript text can be displayed with the <sup> tag. The text ''x''<sup>2</sup>

will display as

Therefore,

10<sup>100</sup>

displays as

(otherwise known as a googol).

Subscript text uses the <sub> tags; so H<sub>2</sub>O

displays as

A number of mathematical symbols have HTML codes, which can be inserted by typing

&codename;

where codename is a Greek letter or an abbreviation for some other symbol. For instance, √ displays as the square root sign (√), γ displays as the Greek letter γ, and Γ codes for the capital Greek letter Γ. For a list of supported symbols, see [[Wikipedia:Mathematical symbols]]. How these symbols are displayed depends in some cases on which browser you are using.

If you are interested in mathematics on Wikipedia, you can pick up more symbols as you go along; just consult articles such as [[square root of 2]] and examine the wikitext. Keep in mind, however, that more than one system is being used. In addition to HTML symbols, MediaWiki uses a subset of TeX markup (the standard for mathematical typesetting), including some extensions from LaTeX and AMSLaTeX. A full list of available TeX markup can be found at [[Help:Displaying a formula]].

Math markup in TeX goes inside the special <math> and </math> tags. A TeX formula is recognizable in the wikitext and looks something like this:

:<math>\pi = 3.141...</math>

Here the colon indents the formula, which is the convention on Wikipedia. This should display as

In TeX, extra spaces and newlines are ignored. The TeX code has to be put literally. MediaWiki templates, predefined templates, and parameters cannot be used within math tags, pairs of double braces are ignored, and # symbols produce error messages.

The Current Compromise

Here's the overall explanation of math symbols: Formulas can be displayed inline (with HTML formatting) or displayed as images, set apart from the text, which is the case if you use TeX formulas with the <math> tag. (Figure 9.5, “The two math styles from a section of the article on E=mc2” shows the difference between the two styles from the article [[Mass–energy equivalence]].) Unfortunately, TeX renders as PNG images, which can cause strange, disruptive effects in the page formatting. You may not see those effects; this is one of those cases where how a page looks depends on the browser you use. The working agreement, at least in the Wikipedia mathematical community, is a mongrel:

For displayed mathematics, use TeX or HTML.

For inline mathematics, use HTML or wiki markup only.

Because numerous symbols can also be used uncoded in the text, this means that three systems coexist in Wikipedia (rather like written Japanese, in fact, which uses two alphabets and a set of symbols).

Figure 9.5. The two math styles from a section of the article on E=mc2 The two math styles from a section of the article on E=mc2

Variables and Magic Words

edit

To insert the current date in numeric form, insert {{CURRENTDAY}} on a page. This is not a template, however, but rather a variable. MediaWiki has a wide choice of such variables; a list can be found at [[Help:Variables]]. Enclose them in double curly brackets to use them. They return a new value each time the page is rendered. This value may vary, accounting for the name, and it changes according to circumstances, for example, with the time ({{CURRENTTIME}}) or the total number of articles on the site at that moment ({{NUMBEROFARTICLES}}). Variables are just a subset of the larger class of so-called magic words. A list can be found at [[Help:Magic words]]. Magic words are symbols recognized by the MediaWiki software. When they are seen in the text of the page, they trigger the software to do something specific. For example, when the command __NOTOC__ (note the two underscores before and after NOTOC) is placed somewhere on the body of a page, it keeps a table of contents from appearing on a page. Using the magic word __FORCETOC__, on the other hand, will force a ToC to appear when not enough sections appear to automatically generate one. Few other magic words are very commonly used in articles. Formatting the Table of Contents In addition to the magic words listed above, the automatically generated table of contents (ToC) in an article can be formatted or moved with the use of special templates. To force the ToC to move to the left or right side of the page, add the template {{TOCleft}} or {{TOCright}} at the top of the page. Moving the ToC may improve page layout and image placement (this, like all CSS rendering, is always browser dependent to some extent). If you are developing a long list page, the special template {{compactTOC}} is convenient; it turns the ToC into alphabetical sections A–Z that display on one line rather than 26 separate lines. Several variations on the {{compactToC}} and explanations can be found at [[Wikipedia:Template messages/Compact tables of contents]]. For guidelines on reformatting the table of contents, see [[Help: Section#Floating_the_TOC]]. Further Reading

http://en.wikipedia.org/wiki/Help:Special_characters Help with special characters and unicode encoding in wikitext

http://en.wikipedia.org/wiki/Help:Advanced_editing#Special_characters A table of special characters and how to produce them in wikitext

http://en.wikipedia.org/wiki/Help:HTML_in_wikitext A list of what HTML tags are permitted in wikitext

http://en.wikipedia.org/wiki/Help:Displaying_a_formula Information about displaying math in articles

http://en.wikipedia.org/wiki/Wikipedia:WikiProject_Mathematics All about mathematics articles

http://en.wikipedia.org/wiki/Help:Magic_words A reference to all the magic words and variables available in MediaWiki

Summary

edit

Images, templates, tables, and special markup can all be used to carefully and accurately format pages and produce visually appealing and engaging layouts. Although every editor should have a passing knowledge of how images and templates work, learning the more complicated aspects of how they function is not necessary for most editing.

Wikipedia's technical resources offer immense possibilities—with some limitations. Learning advanced syntax occurs in three stages: recognizing a construction in wikitext, gaining familiarity with the principles of how it works, and gaining a working knowledge of some possible applications that interest you. Although looking around while working on the site will help, the third stage generally only occurs when developing a project of your own.