MediaWiki

From IT Wiki
Jump to navigation Jump to search

Add Favicon

To add a Favicon to your wiki, add:

/* For Favicon */

document.write("<link rel='shortcut icon' href='URL of Favicon image you want' type='image/x-icon'>");

to MediaWiki:Monobook.js.

This only works for the Monobook style, but most people use that style. Many wikis only allow that style anyway.

Note: If you add it to Common.js, it seems to work on all styles.

Adding Google Analytics (or other script code)

In order to add Analytics to MediaWiki, you first need the script code from Google. It should look something like this:

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">

</script>

<script type="text/javascript">

_uacct = "UA-XXXXX-X";

urchinTracker();

</script>

We need to insert the script code into MediaWiki so that it appears in every page generated. But where? In the MediaWiki's base skin php file. If you haven't changed the skin from the default, then you have the "MonoBook" skin. Edit the following file:

/wiki/skins/MonoBook.php

And insert the Google script code near the end of the file, just above the </body></html> tags. That's it. All pages will now execute the script.

Note: This can be used to add Magelo tool tips to your site. Also, Vector is now the default skin, just edit Vector.php.

Allow capital letters in Sidebar headings

Add the following to your Common.CSS:

.portlet h5, .portlet h6 {

text-transform:none;

}

Column alignment per column

Add class to table, e.g. class="wikitable col-3-right col-4-right", and put into MediaWiki:Common.CSS the following:

table.col-1-center td:nth-child(1) { text-align: center; }
table.col-2-center td:nth-child(2) { text-align: center; }
table.col-3-center td:nth-child(3) { text-align: center; }
table.col-4-center td:nth-child(4) { text-align: center; }
table.col-5-center td:nth-child(5) { text-align: center; }
table.col-6-center td:nth-child(6) { text-align: center; }
table.col-7-center td:nth-child(7) { text-align: center; }
table.col-8-center td:nth-child(8) { text-align: center; }
table.col-9-center td:nth-child(9) { text-align: center; }

table.col-1-right td:nth-child(1) { text-align: right; }
table.col-2-right td:nth-child(2) { text-align: right; }
table.col-3-right td:nth-child(3) { text-align: right; }
table.col-4-right td:nth-child(4) { text-align: right; }
table.col-5-right td:nth-child(5) { text-align: right; }
table.col-6-right td:nth-child(6) { text-align: right; }
table.col-7-right td:nth-child(7) { text-align: right; }
table.col-8-right td:nth-child(8) { text-align: right; }
table.col-9-right td:nth-child(9) { text-align: right; }

Copy & Paste Excel-to-Wiki Converter

error_log

In your main MediaWiki folder, a file called "error_log" will be created if MediaWiki encounters an error that can be logged. Checking this every so often can be useful.'

One step in troubleshooting that should be taken first is to delete the contents of your "/cache" folder and see if the errors continue.

Note: Do not delete the ".htaccess" file in your cache folder (it should contain only "Deny from all").

Error reporting

MediaWiki can report errors that do not affect usage. It can report errors and warnings that are used in development but should be ignored in a live server. To disable error reporting, add the following to your LocalSettings.php:

error_reporting( 0 );

Hide section edit links

Put __NOEDITSECTION__ on the page.

Online HTML to Wiki converter

The following code, added to your LocalSettings.php file, will randomize your site's logo. A different logo (random) will appear for each page:

$logoNames[] = "Logo01.png";
$logoNames[] = "Logo02.png";
$logoNames[] = "Logo03.png";
$logoNames[] = "Logo04.png";
$logoNames[] = "Logo05.png";

Now you need to add the code to randomize and set the logo. Mediawiki installations up to MediaWiki 1.35.0 used $wgLogo. Mediawiki installations after MediaWiki 1.35.0 should be using $wgLogos as $wgLogo is no longer supported.

# $wgLogo (up to MediaWiki 1.35.0)
$wgLogo             = "/myWiki/skins/common/images/" . $logoNames[array_rand($logoNames)];
# $wgLogos (after MediaWiki 1.35.0)
$wgLogos = [
    '1x' => "$wgScriptPath/fanra/logo/" . $logoNames[array_rand($logoNames)],
    'icon' => "$wgScriptPath/fanra/logo/" . $logoNames[array_rand($logoNames)]
];

Simply create your logos, put them in the proper directory, and modify the LocalSettings.php file with the code above.

Issues

This may not seem to work as well if you are caching pages. One work-around is to make the logo file names unique by appending the current time to them, as shown here:

# $wgLogo (up to MediaWiki 1.35.0)
$logoNames[] = "Logo01.png?<?php echo time(); ?>";

or

# $wgLogos (after MediaWiki 1.35.0)
$wgLogos = [
    '1x' => "$wgScriptPath/fanra/logo/" . $logoNames[array_rand($logoNames)] . "?version=" . time(),
    'icon' => "$wgScriptPath/fanra/logo/" . $logoNames[array_rand($logoNames)] . "?version=" . time()
];

This makes each image have a different name and is thus cached as a different image each time it is downloaded from the server. The problems with this is that they fill up the user's cache folder with multiple copies of the same image, as well as defeating server page caching.

However, it seems to work reasonably well without this and this does not always defeat caching.

Reduce references text size

In the Common.css file add the following:

/* Reduce the size of the text in references */

.references-small { font-size: 90%;}

Remove Main Page heading

To removing the heading "Main Page" from the main page, add:

/* Remove the heading "Main Page" from the main page */

body.page-Main_Page h1.firstHeading { display:none; }

to MediaWiki:Common.css.

Security

Security is a complex subject. Any advice given here is without any warranty, use at your own risk.

localsettings.php

Suggested chmod: 600

images folder

Create (if one does not already exist, otherwise add to it) a .htaccess file in your images folder and put the following in it:

# Ignore .htaccess files

AllowOverride None

# Serve HTML as plaintext, do not execute SHTML

AddType text/plain .html .htm .shtml .php

# Do not run arbitrary PHP code.

php_admin_flag engine off

php_flag engine off


Note that if you upgrade MediaWiki, you might have to redo this, as the .htaccess file may get overwritten.

Depending on your hosting, AllowOverride None and php_admin_flag engine off and php_flag engine off might cause issues with images. You may need to skip using them.

MySQL

When not installing or upgrading or otherwise messing with the software, the database user only needs to have SELECT, INSERT, UPDATE and DELETE permissions for the database.

Using content from Wikipedia

Backing up

Wiki pages

To back up the contents of the wiki (not including the database), there are several ways. One way is to install Extension:MaintenanceShell. Once that is installed, run dumpBackup.php with the following Command line options:

--full --output=file:foobar

This will dump all revisions of every page into a html file called foobar in the /maintenance folder. If you use --current instead of --full it will dump only the latest revision of every page. You can also try "gzip", "bzip2" or "7zip" instead of "file" if you want to see if that will compress the html file for faster downloading with less bandwidth.

Extension:Facebook

Extension:Facebook is an extension that lets you link your wiki with Facebook. One of the best things is that it allows users to log in to your wiki with their Facebook account.

The instructions for Extension:Facebook mention that you need to perform a database update in order to get it to work. This can be difficult without server command line access. The instructions mention running update.php. If you can't get that to work, you can use phpMyAdmin (or any way to run SQL queries) to create the table needed:


CREATE TABLE /*$wgDBprefix*/user_fbconnect ( user_fbid BIGINT unsigned NOT NULL PRIMARY KEY, user_id int(10) unsigned NOT NULL ) /*$wgDBTableOptions*/;

CREATE INDEX /*$wgDBprefix*/user_fbconnect_user ON /*$wgDBprefix*/user_fbconnect(user_id);


In addition, you may wish to change the Type of table from MyISAM to InnoDB (InnoDB is the default storage engine for MySQL and is generally considered better). To do so, run the following SQL query:


ALTER TABLE user_fbconnect ENGINE = INNODB;

Improving performance

Editing:

  • MediaWiki:Aboutsite
  • MediaWiki:Aboutpage - Not sure about this one
  • MediaWiki:Pagetitle
  • MediaWiki:Pagetitle-view-mainpage
  • opensearch-desc tagline - Not sure about this one
  • tooltip-search system messages - Not sure about this one

by changing {{SITENAME}} into your proper site name. Parsing curly braces adds milliseconds.

Cache

Create (if it doesn't exist) a folder called cache in the main wiki folder.

Make sure LocalSettings.php has:

## Set $wgCacheDirectory to a writable directory on the web server

## to make your wiki go slightly faster. The directory should not

## be publically accessible from the web.

$wgCacheDirectory = "$IP/cache";


# Cache Sidebar

$wgEnableSidebarCache = true;


# Cache static pages for non-logged-in users to reduce database traffic

$wgFileCacheDirectory = "$IP/cache";

$wgUseFileCache = true;


## Depth of subdirectory hierarchy under $wgFileCacheDirectory (above) Note: 0 is recommended

## for small wikis, very large ones should use a higher number or otherwise investigate this setting

$wgFileCacheDepth = 0;


Additionally:

Some shared hosting do not have any of the shared caching methods available (APC, memcached, etc.) due to the security risks and resource usage these caches would take. You are therefore limited to caching either in files or in your database.

For MediaWiki, database caching is accomplished by setting $wgMainCacheType = CACHE_DB; in your LocalSettings.php -- see if that offers any improvements over not caching at all (it might, it might not).

Cloudflare

Restore original visitor IP

Note: It is believed this is no longer necessary.

Go to line 1210 in /includes/GlobalFunctions.php, change REMOTE_ADDR to HTTP_CF_CONNECTING_IP.
Next, go to /includes/WebRequest.php, in lines 1174 to line 1182, change REMOTE_ADDR to HTTP_CF_CONNECTING_IP (four instances in three lines to change).

Note that the line numbers given above may change with new versions of MediaWiki. Therefore, you can just search the text for REMOTE_ADDR and replace it with HTTP_CF_CONNECTING_IP.