MediaWiki

(Redirected from Mediawiki)
Jump to: navigation, search
Categories » Programming » Web Programming » PHP » MediaWiki

These are some notes about my installation of MediaWiki. Also see the MediaWiki FAQ.

Contents

ToDo

Useful Pages

Installation

Directories

I am using a wiki.example.com installation with the MediaWiki files in a directory called w.

.htaccess

At first I was having some issues with accessing certain articles (specifically the ASP.NET article due to the period in its name). This .htaccess file (from [1]) seems to work perfectly:

Options -Indexes
 
RewriteEngine On
RewriteRule ^/*$ /w/index.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /w/index.php?title=$1 [L,QSA]
 
<IfModule mod_security.c>
   SecFilterEngine Off
   SecFilterScanPOST Off
</IfModule>

The mod_security.c section disables a security module on this server that was interfering with certain article titles.

Configuration

LocalSettings.php

LocalSettings.php must be modified after the main MediaWiki installation.

Article URLs

This code works along with the .htaccess code above.

## The URL base path to the directory containing the wiki;
## defaults for all runtime URL paths are based off of this.
$wgScriptPath       = "/w";
$wgScriptExtension  = ".php";
$wgArticlePath = '/$1';
$wgUsePathInfo = true;

Require Login to Edit

In LocalSettings.php:

$wgGroupPermissions['*']['edit'] = false;

Require Login to View

In LocalSettings.php:

$wgGroupPermissions['*']['read'] = false;
$wgWhitelistRead = array("Main Page", "Special:Userlogin", "Special:RequestAccount", "Special:Confirmemail", "-");

File Uploading

Perform chmod 0777 on /w/images. Then, in LocalSettings.php:

$wgEnableUploads = true;
// add some more file types...
$wgFileExtensions[] = 'zip';
$wgFileExtensions[] = 'rar';

Allow Subpages in Main Namespace

In LocalSettings.php:

$wgNamespacesWithSubpages[NS_MAIN] = true;

Customization

Navigation Sidebar

The navigation bar on the left can be modified by editing MediaWiki:sidebar.

Editing Toolbar

See MediaWiki:Common.js and MediaWiki:Extraeditbuttons.js. Source

CSS Customization

CSS in MediaWiki:Common.css appears on all pages regardless of selected skin. I added the following:

/* Marking redirects in Special:Allpages  */
 .allpagesredirect { font-style: italic; }
 .watchlistredir { font-style: italic; }

PDF Link Highlight

I liked the PDF link icon on Wikipedia better than the default one.

Uploaded this image:File:Icons-mini-file acrobat.gif (source)

Added the following to MediaWiki:Common.css: (source)

/* Change the external link icon to an Adobe icon for all PDF files */
/* (in browsers that support these CSS selectors, like Mozilla and Opera) */
#bodyContent a[href$=".pdf"].external, 
#bodyContent a[href*=".pdf?"].external, 
#bodyContent a[href*=".pdf#"].external,
#bodyContent a[href$=".PDF"].external, 
#bodyContent a[href*=".PDF?"].external, 
#bodyContent a[href*=".PDF#"].external,
#mw_content a[href$=".pdf"].external, 
#mw_content a[href*=".pdf?"].external, 
#mw_content a[href*=".pdf#"].external,
#mw_content a[href$=".PDF"].external, 
#mw_content a[href*=".PDF?"].external, 
#mw_content a[href*=".PDF#"].external {
    background: url(http://wiki.ike.to/w/images/2/23/Icons-mini-file_acrobat.gif) center right no-repeat;
    padding-right: 16px;
}
 
/* Change the external link icon to an Adobe icon anywhere the PDFlink class */
/* is used (notably Template:PDFlink). This works in IE, unlike the above. */
span.PDFlink a {
    background: url(http://wiki.ike.to/w/images/2/23/Icons-mini-file_acrobat.gif) center right no-repeat !important;
    padding-right: 17px !important;
}

Now PDF links look like this.

Extensions

See Extension Matrix.
How to write an extension: MediaWikiWiki:Manual:Extensions

Confirm Account

This extension implements an account confirmation queue. It allows me to require manual approval of all new accounts.

I am using the following additional options for this extension:

$wgUseRealNamesOnly = false;
$wgAccountRequestMinWords = 0;
$wgAccountRequestExtraInfo = false;
$wgAccountRequestToS = false;

Interwiki Editor

This extension provides the page Special:Interwiki which allows you to view & edit the interwiki table.

The only modification I made to this extension is the option to restrict editing to SysOps.

Code Highlighting

Extension:SyntaxHighlight GeSHi

This is the extension used on Wikipedia. The above link has a list of supported languages.

I am using a slightly modified version of the PHP highlight definition file. There was a mistake in the one included with version 1.0.7.21.

/geshi/geshi/php.php lines 303-306 (as included):

'REGEXPS' => array(
            0 => 'color: #0000ff;',
            1 => 'color: #ff0000'
            ),

After modification:

'REGEXPS' => array(
            0 => 'color: #ff0000;',
            1 => 'color: #0000ff;'
            ),

Math

The following lines in LocalSettings.php were modified (instructions: [2]).

Note that my $wgUploadPath is slightly different from the linked instructions because of my URL structure.

// Modified the following line
$wgUseTeX = true;
// Added the following lines
$wgUploadPath = "/w/images";
$wgUploadDirectory = "images";
$wgMathPath = "{$wgUploadPath}/math";
$wgMathDirectory = "{$wgUploadDirectory}/math";
$wgTmpDirectory = "{$wgUploadDirectory}/tmp";

All done! Failed to parse (Missing texvc executable; please see math/README to configure.): \sqrt{Hello^{World!}}


ParserFunctions

Adds support for numerous functions, including automatic calculations.

Documentation (how to use it): Help:ParserFunctions

Simple usage: {{#expr: 2 + 2 }} produces 4

VariablesExtension

This adds basic variable support.

Usage:

ToggleDisplay

Allows the creation of simple toggled sections, like this:

I modified the code slightly so I could simply write <toggle> instead of <toggledisplay>.

// XML-style extension
$wgParser->setHook( 'toggledisplay', array( &$this, 'toggleDisplay' ) );
// next line added by me
$wgParser->setHook( 'toggle', array( &$this, 'toggleDisplay' ) );

I also modified the code so it would work with browsers that have JavaScript disabled.


Available attributes:

Parameter Default Explanation
status hide Initial state when the page is first displayed. May be hide or show.
showtext [show details] Link text when hidable area is hidden.
hidetext [hide details] Link text when hidable area is shown.
linkstyle font-size:smaller CSS style specification for the link.

SubPageList3

See also Allow Subpages in Main Namespace

This creates an ordered list of subpages of an article.

Simple usage: <splist />
Advanced usage:

<splist
 parent=
 showparent=yes
 sort=desc
 sortby=title
 liststyle=ordered
 showpath=no
 kidsonly=no
 debug=0
/>

Note: If new subpages aren't showing up, it's probably because of caching. Re-save the page to get around this.

NiceCategoryList2

Modifications

public function hookNcl($category, $argv, &$parser) {
 
// ikenote: added this
$parser->disableCache();
 
// Get any user-specified parameters, and save them in $this->settings.
foreach (array_keys($argv) as $key)
	$this->settings[$key] = $argv[$key];
...
// If we got some items, then display them in the requested style.
        if (count($pieces) > 0) {
            if ($this->settings['style'] == 'bullet')
                $output .= "* " . implode("\n* ", $pieces) . "\n";
            else {
// ikenote: added next line
if ($this->settings['headings'] == 'bullet')
// ikenote: disabled $level - 1 subtraction
                $pre = $level == 0 ? "<big>" : str_repeat('*', $level - 0) . ':';
// ikenote: added next 2 lines
else
                $pre = $level == 0 ? "<big>" : ':';
                $post = $level == 0 ? "</big>" : '';
                $output .= $pre . implode("&nbsp;&bull; ", $pieces) . $post . "<br>\n";
            }
        }

Development

http://svn.wikimedia.org/doc/

TODO: Add more links

Ideas

Personal tools
Namespaces
Variants
Actions
Navigation
Categories
Toolbox