From charlesreid1

Revision as of 03:29, 25 September 2015 by Admin (talk | contribs)

Installation

The instructions at http://mediawiki.org are really straightforward. All you have to do is unzip the MediaWiki tarball/zip file into your web server's main directory. Their recommendation is to put it in a folder called w/, and I recommend following their recommendation.

Permissions

Changing Namespace Permissions

This is a handy way for you to create custom permissions for parts of your wiki.

Step 1: Select Protected Namespace

This step consists of either selecting an existing namespace to protect, or creating a new namespace.

I will use the example of the "Secret" namespace. As an example, on a public wiki the page [[Message]] would be open to the public, and viewable by anyone. But if this were added to the Secret nanemspace, i.e. if it were at [[Secret:Message]], then it would only be viewable by those with permission to view the Secret namespace.

Add the new namespace to LocalSettings.php with the following code:

$wgExtraNamespaces = array( 100 => "Secret");

If you want to create more namespaces, you can number them 101, 102, 103, etc., or really, whatever you feel like. (Just keep the numbers big so they don't interfere with existing namespaces.)

Step 2: Modify includes/Title.php

The file includes/Title.php is a header file that is included on all MediaWiki pages. When pages are loaded, the load request is processed through Title.php.

Look for the piece of code that looks like this:

        if( $wgUser->isAllowed( 'read' ) ) {
            return true;
        } else {
            global $wgWhitelistRead;

This piece of code checks if a user has global "read" permissions, and if so, it proceeds to load the page.

We will create a new permission called "read_secret" that, if a user has, will allow them to see any page in the Secret namespace.

Add a check for the new "read_secret" permission:

        if( $this->getNamespace() == 100 ) { 
            //this is "Secret" namespace
            return $wgUser->isAllowed('read_secret');
        }   
        if( $wgUser->isAllowed('read') ) {
            return true;
        } else {
            global $wgWhitelistRead;

Step 3: Create a group with the new permission

The next step is to create a MediaWiki group that will have the just-created permission, "read_secret". I'll name this group something really creative like "secret":

$wgGroupPermissions['secret']['read_secret'] = true;

Step 4: Add users to new group

The last step is to add users to the new group. You can go to the page Special:UserRights on your wiki, and it will prompt you for a user. Once you enter a user's name, you will see a list of groups that are available to add a user to:

MWGroups.png

(Of course, this will depend on your wiki's configuration. Also, you have to be an administrator or a bureaucrat to add users to new groups.)

You can check the "secret" box, and the user will now be a member of the group "secret" and have the permission "read_secret", making him or her able to access pages in the Secret namespace!

Extensions

20 MediaWiki extensions that are pretty handy: http://blog.fedecarg.com/2008/03/08/20-mediawiki-extensions-you-should-be-using/

Math

I was having a lot of trouble getting the MediaWiki Math extension to work. I kept seeing the following error:

"Failed to parse (PNG conversion failed; check for correct installation of latex, dvips, gs, and convert)"

Here's how I resolved it:

Step 1: Install all the crap you need

# this is the "easy way" and is preferable
sudo apt-get install mediawiki-math

# this is the "manual way" and may not work
sudo apt-get install ghostscript imagemagick dvipng texlive-latex-base texlive-latex-extra

Step 2: Fix texvc

For me, I found the main problem was that I didn't have texvc. This page http://www.mediawiki.org/wiki/Texvc suggested installing mediawiki-math using aptitude, which the above instructions should help take care of.

Step 3: Test

You should be able to run the following command line and see some HTML:

$ texvc /tmp/junk /tmp/junk "y=x+2"
Cdaa63ef966cc412541190bc8794731de<i>y</i> = <i>x</i> + 2<mi>y</mi><mo>=</mo><mi>x</mi><mo>+</mo><mn>2</mn>-

And voila!

Moving MW From One Server To Another

Step 1: Set Up SQL

First step is NOT to copy everything from the original wiki to the clone wiki

The first step is to download mediawiki on your new wiki's server and install it like you would normally, to wherever you want to install it, but paying close attention to match the SQL settings in the original wiki's LocalSettings.php

This will then set up the necessary SQL framework.

You can throw away the new wiki you've set up, since the main point is to have MediaWiki create an empty SQL database with the right structure.

Step 2: Copy Apache Files

At that point you copy the original wiki to the clone wiki (at least, all the apache FILES).

Example: your old wiki is contained on your old server in /htdocs/wiki. Your new wiki is going onto your new server in the directory /apache/www/htdocs/wiki. You will copy /htdocs/wiki/ from your old server to /apache/www/htdocs/wiki on your new server.

Step 3: Copy MySQL

Last step remaining is covered on MySQL page: copy the actual database from one MySQL server (original wiki) to the other (clone wiki).

You can do this easily if you use PhpMyAdmin to administer your SQL databases. If not, you can do a SQL dump. If you're using MySQL, use mysqldump. See MySQL page.

Once you've loaded your old SQL database into your new SQL database, restart your MySQL server:

sudo service mysql restart

I also had to change my MySQL config file to make MySQL open to the public. (Apparently, this was not necessary.)

I have more information on my MySQL and PhpMyAdmin pages.

Problems with Cookies

When I migrated my MediaWiki site, I ran into some problems with cookies when trying to log in. I got error messages about my browser not accepting cookies, but cookies were enabled. It was independent of the browser or the machine.

This ended up being a permissions problem - MediaWiki didn't have permission to create files in the directory where it stored sessions. I was able to fix this by changing my LocalSettings.php file to specify a location for sessions. I added the following line to the bottom:

session_save_path('/tmp');

Skinning Mediawiki

This article is located at the Skinning MediaWiki page.

I have created two skins, along with explanations:

Errors

I got some errors after transitioning to nginx+Apache instead of Apache alone, whenever I tried uploading an image I would see this:

"Problem With File Upload: Could not acquire lock for [filename]"

The solution is basically to change the permissions of the images directory:

cd /www/w/
sudo chmod -R 777 images/


Debugging

If you are having problems (like, if your site suddenly becomes a blank white page!), try turning on errors from LocalSettings.php:

error_reporting( -1 );
ini_set( 'display_errors', 1 );

If that doesn't work, try php.ini (/etc/php5/apache2/php.ini on some Nix distros):

error_reporting = E_ALL
display_errors = On

or use .htaccess:

php_value error_reporting -1
php_flag display_errors On