Small wiki toolkits/Starter kit/Main page customization

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search

When you are a member of a new wiki community, you sometimes want to customize the main page (to make it look better on small screens), or change configuration settings.

This page explains some basics, so you can make these changes yourself. You will have to read a bit, might learn something new, and have to test yourself.

On most wikis, editing the "Main Page" requires permissions beyond what most editors have. Often this will be either administrator rights, interface administrator rights, or some permission group created specifically for the purpose. The exact configuration varies from wiki to wiki and you will have to check there to find out. To see the permissions set on your wiki, use the "Page information" link in the sidebar on the Main Page and look in the "Page protection" section.

Add responsive boxes to the main page[edit]

What you can learn on this page[edit]

Change the width of your browser window. Make it smaller and wider. See how arrangement of the boxes in the next line changes:

Box 1
Box 2
Box 3
Box 4
Box 5

This page explains how you can have this on your wiki.

Understand the background[edit]

Somehow, boxes are popular in web layout nowadays. If you put some boxes next to each other, then you also want these boxes to be readable on small screens. This is called responsive web design.

To put boxes next to each other, some people (ab)used tables in the past. Tables exist in wiki markup, but tables are a bad idea. Tables look bad on small screens (see this example image) and can create accessibility problems.

Unfortunately, the MediaWiki software does not provide responsive boxes as wiki markup. (Some boxes might exist as templates on some wikis, though.) And using MediaWiki:Common.css to store the layout ("CSS") for one single page is also a bad idea [1].

Hence on this page, we will

  • use HTML markup and wiki markup for the actual content,
  • save this content as a template in a new wiki page called Template:Main_page,
  • use CSS to define the layout part (boxes) in a new wiki page called Template:Main_page/styles.css,
  • use TemplateStyles to apply the layout to the content in the template via the line <templatestyles src="Main_page/styles.css"/>, and
  • on the main page, load and embed the template via the line {{Main_page}}.

Example[edit]

Create the main page template[edit]

First of all, create a new page called Template:Main_page on your wiki.

Add content to the main page template[edit]

In this step, we define the content by editing the new page called Template:Main_page.

In the box below, there is a skeleton with five boxes. Copy and paste the lines in that box into that page, and then adjust. It uses the HTML division element ("div"). You can of course change the number of boxes: To remove a box, remove everything between an opening <div> and its corresponding closing </div>. Make sure that these two elements match, otherwise weird stuff can happen.

The class parameters below define the CSS layout for these HTML elements. We will define the layout in the next step. The very first line <templatestyles src="Main_page/styles.css"/> loads the CSS layout.

<templatestyles src="Main_page/styles.css"/>
<div id="wikifrontpage_container" class="wikifrontpage_row">
<div class="wikifrontpage_box">
===Box 1===
* Item1 in the first box
* Item2 text in the first box
</div>
<div class="wikifrontpage_box">
===Box 2===
Some text in the second box
</div>
<div class="wikifrontpage_box">
===Box 3===
Some text in the third box
</div>
<div class="wikifrontpage_box">
===Box 4===
Some text in the fourth box
</div>
<div class="wikifrontpage_box">
===Box 5===
Some text in the fifth box
</div>
</div>

Define the CSS[edit]

Create the wiki page Template:Main_page/styles.css on your wiki.

The next lines define the layout of a box, and at which width a box moves from one line to the next line. You do not have to understand all the CSS below.

.wikifrontpage_row {
	display: flex;
	flex-direction: row;
	flex-flow: row wrap;
	justify-content: space-between;
	padding: 0;
	margin: 0 -5px 0 -5px;
}
.wikifrontpage_box {
	flex: 1;
	margin: 5px;
	min-width: 240px;
	border: 1px solid #CCC;
	padding: 0 10px 10px 10px;
	box-shadow: 0 2px 2px rgba(0,0,0,0.1);
}

The important parts in the CSS above are all lines with the word flex (which defines a flexible layout) and the line min-width: 240px; (which defines the width when to move a box from the same line to the next line).

Copy and paste these CSS definitions into the page Template:Main_page/styles.css and save the page.

Test[edit]

Add the template to your main page[edit]

Once you are content with the changes, embed the template in the main page itself: Edit your main page and add the line {{Main_page}} to it. As written above, this will usually require extended permissions.

That's all! Congratulations!

Problems[edit]

Other CSS options for smaller screens[edit]

Another option is to define CSS rules which are only used up to some window width. See CSS media queries if you are interested in experimenting with that.

Footnotes[edit]

  1. Using common.css for these extra classes will add to the page load cost for every page on your wiki even when they are not used in the content.