Extension:WPMW

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
Crystal Clear action run.svg
WPMW
Release status: beta
Implementation User identity
Description Provides integration with WordPress as master authentication site, with MediaWiki as slave.
Author(s) Ciaran Gultnieks (CiaranGtalk)
Latest version 0.3.1 (2013-08-05)
MediaWiki 1.18.0+
License GNU General Public License 3.0 or later
Download external download at https://gitlab.com/CiaranG/wpmw
Example https://f-droid.org/
Parameters
  • $wgAuthWPRelPath
  • $wgAuth
Hooks used
UserLoadFromSession
UserLogout
Translate the WPMW extension if it is available at translatewiki.net
Check usage and version matrix.

WPMW is an extension for integrating a MediaWiki within a WordPress installation. It is currently working and useful, but beta-quality. (Not working since MW 1.27)

Installation[edit]

To install, it is assumed you already have a working WordPress installation. Although WPMW may work with other versions, it only tested and maintained on an ongoing basis against the latest WordPress, which is 3.6 at the time of writing. You will also need at least version 1.18.0 of MediaWiki.

Installing MediaWiki[edit]

The first thing to do is install MediaWiki in a 'wiki' directory below the root of your WordPress installation (or see #Other Install Locations if you want it somewhere else). You can use a separate database, or the same one as WordPress uses. Once installed, it's a good idea to set it up to use 'clean' URLs, although it won't affect WPMW if you don't. The following in wiki/LocalSettings.php should do it:

$wgUsePathInfo = false;
$wgArticlePath = '/wiki/page/$1';

when combined with something like this in .htaccess in the wiki directory:

RewriteEngine on
RewriteRule ^/$ /page/Main_Page
RewriteRule ^page/(.*)$ index.php?title=$1 [L]

If wordpress is already installed and it is giving you trouble installing MediaWiki into a folder under the wordpress root, add this to the .htaccess file in the wordpress root folder.

ErrorDocument 401 default
ErrorDocument 403 default

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteCond %{REQUEST_URI} ^/wiki/(.*)$
RewriteRule ^.*$ - [L]
</IfModule>

This tells wordpress installed to the "wp" folder to ignore the "wiki" folder and not to try to forward it to a "forbidden" page.

Wordpress Answers on ignoring a subfolder

Other Install Locations[edit]

If you already have, or want to have, MediaWiki installed at a different location relative to your WordPress installation, you can do that by specifying a relative path FROM the MediaWiki directory TO the WordPress directory. In the default setup where WordPress is at / and MediaWiki is at /wiki, this relative path is ../.

To change it, just add a line in your MediaWiki's LocalSettings.php. The following example is where /wiki contains MediaWiki and /wordpress contains WordPress:

$wgAuthWPRelPath = '../wordpress';

This line must be placed BEFORE require_once "$IP/extensions/AuthWP/AuthWP.php";.

However, if the MediaWiki directory doesn't sit below the WordPress directory, MediaWiki will not see the WordPress login cookies, so some of the integration will not work smoothly. To fix that, you simply need to install the root-cookie WordPress plugin or according to the discussion, navigate to your current WordPress theme's root directory, and add the following lines of code to functions.php:

function mw_logout() {
	// IMPORANT: Replace mediawiki_db with your wiki database name
	$wikiDatabaseName = "mediawiki_db";

	// Goes through all cookies, if it finds a cookie starting with your database name it will unset it.
	foreach($_COOKIE as $cookieKey => $cookieValue) {
		if(strpos($cookieKey,$wikiDatabaseName) === 0) {
			// remove the cookie
			unset($_COOKIE[$cookieKey]);
			
			// IMPORTANT: Replace .mediawiki.org with your domain name
			setcookie($cookieKey, '', time() - 3600, '/', '.mediawiki.org');
		}
	}
}
add_action('wp_logout', 'mw_logout');

Installing the MediaWiki Extension[edit]

You can either download the archive from GitLab or clone the git repository into the MediaWiki extensions directory, i.e. wiki/extensions. In either case name the folder AuthWP. Then add the following lines to LocalSettings.php:

require_once "$IP/extensions/AuthWP/AuthWP.php";
$wgAuth=new AuthWP();
Remember that if the relative url of wordpress is other than ../ you have to declare it before requiring the extension. For more details see #Other_Install_Locations.

Installing the WordPress Plugin[edit]

There isn't a WordPress plugin yet (although there may be later) so you've already finished the installation.

Single Registration Page[edit]

Although this setup supports allowing users to register via either the WordPress or MediaWiki user interface, you may wish to restrict registration to the WordPress interface only. This provides less of an 'attack surface' for automated spammy registrations. To do so, simply disable registration in the MediaWiki configuration:

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

Everything else will still function as normal.

Usage[edit]

Once everything is set up there is not much else you need to do.

What Works[edit]

A.k.a. what should work - bug reports welcome:

  • If you have a Wordpress account, you can use the same details to log into MediaWiki. If there is not already a MediaWiki account for the user, it is created there and then.
  • If you register an account via the MediaWiki interface, an account is automatically created in WordPress. The account will have default settings for most things - specifically the role will be Subscriber, the same as if the user registered via WordPress. (But I suggest turning this off, as detailed above)
  • If you log in on the WordPress site, you will automatically be logged in to MediaWiki when you visit it.
  • If you log in on MediaWiki, you are automatically logged in to WordPress.
  • If you log out of MediaWiki, you will automatically be logged out of WordPress.
  • If you change your email address or real name in WordPress, the MediaWiki account details will be updated the next time you log in there (which includes simply visiting it while logged in to WordPress).
  • Changing email address and real name in MediaWiki is disabled - you have to change them via WordPress.

What Doesn't Work Yet[edit]

A.k.a todo list:

  • You can register an account in WordPress that has a user name that is invalid in MediaWiki. In that case, you won't be able to log in to MediaWiki.
  • If you log out on WordPress, you stay logged in on MediaWiki.
  • If you create an account in MediaWiki and don't specify an email address, the corresponding WordPress account will not be usable until you do specify one. To fix this, either update your profile in MediaWiki, or an admin should do it for you in WordPress. It is suggested to turn off Mediawiki registrations, see #Single_Registration_Page.
  • I thought WordPress should be sending a 'new user' notification email to the site admin when a user registered on MediaWiki, but it doesn't seem to be working currently.