Mediawiki

From FroggDev - En
Jump to: navigation, search
Wikimedia Logo


Administration

  • password change
php maintenance/changePassword.php --user=UserName --password=newpassword
  • set an user as admin (require $wgShowExceptionDetails = true; in LocalSettings.php)
php maintenance/createAndPromote.php --user=UserName --sysop --force
  • set an user as admin via sql
INSERT INTO `user_groups` VALUES (userId, 'sysop');

Configuration

LocalSetting.php

Basis

  • server address
$wgServer = 'http://wiki.frogg.fr';
  • allow admin action
$wgShowExceptionDetails = true;
  • customisation
$wgFavicon = '/wiki/images/favicon.ico';
$wgLogo = '/wiki/images/logo.gif';
  • email confirmation
$wgEmailAuthentication = true;
$wgEmailConfirmToEdit = true;

Rights Management

my configuration:

  • offline users (*)
$wgGroupPermissions['*'    ]['createaccount']   = true;
$wgGroupPermissions['*'    ]['read']            = true;
$wgGroupPermissions['*'    ]['edit']            = false;
$wgGroupPermissions['*'    ]['createpage']      = false;
$wgGroupPermissions['*'    ]['createtalk']      = false;
$wgGroupPermissions['*'    ]['talk']            = false;
$wgGroupPermissions['*'    ]['purge']           = false;
$wgGroupPermissions['*'    ]['editmyprivateinfo']= false;
$wgGroupPermissions['*'    ]['editmyusercss']   = false;
$wgGroupPermissions['*'    ]['editmyuserjs']    = false;
$wgGroupPermissions['*'    ]['editmyoptions']   = false;
$wgGroupPermissions['*'    ]['editmywatchlist'] = false;
$wgGroupPermissions['*'    ]['writeapi']        = false;
$wgGroupPermissions['*'    ]['viewmywatchlist'] = false;
$wgGroupPermissions['*'    ]['viewmyprivateinfo']= false;
  • online users (user)
$wgGroupPermissions['user' ]['move']            = false;
$wgGroupPermissions['user' ]['read']            = true;
$wgGroupPermissions['user' ]['edit']            = false;
$wgGroupPermissions['user' ]['createpage']      = false;
$wgGroupPermissions['user' ]['createtalk']      = true;
$wgGroupPermissions['user' ]['edittalk']        = true;
$wgGroupPermissions['user' ]['talk']            = true;
$wgGroupPermissions['user' ]['upload']          = false;
$wgGroupPermissions['user' ]['reupload']        = false;
$wgGroupPermissions['user' ]['reupload-shared'] = false;
$wgGroupPermissions['user' ]['minoredit']       = false;
$wgGroupPermissions['user' ]['purge']           = false;
$wgGroupPermissions['user' ]['movefile']        = false;
$wgGroupPermissions['user' ]['move-subpages']   = false;
$wgGroupPermissions['user' ]['move-categorypages'] = false;
$wgGroupPermissions['user' ]['move-rootuserpages'] = false;
$wgGroupPermissions['user' ]['writeapi']        = false;
$wgGroupPermissions['user' ]['editmyusercss']   = false;
$wgGroupPermissions['user' ]['editmyuserjs']    = false;
$wgGroupPermissions['user' ]['editmyoptions']   = false;
$wgGroupPermissions['user' ]['editmywatchlist'] = false;
$wgGroupPermissions['user' ]['changetags']      = false;
$wgGroupPermissions['user' ]['applychangetags'] = false;
  • bot (bot)
$wgGroupPermissions['bot'  ]['bot']             = true;
$wgGroupPermissions['bot'  ]['autoconfirmed']   = false;
$wgGroupPermissions['bot'  ]['nominornewtalk']  = false;
$wgGroupPermissions['bot'  ]['autopatrol']      = true;
$wgGroupPermissions['bot'  ]['writeapi']        = false;
  • administrator (sysop)
$wgGroupPermissions['sysop']['move']            = true;
$wgGroupPermissions['sysop']['createpage']      = true;
$wgGroupPermissions['sysop']['createtalk']      = true;
$wgGroupPermissions['sysop']['edit']            = true;
$wgGroupPermissions['sysop']['block']           = true;
$wgGroupPermissions['sysop']['createaccount']   = true;
$wgGroupPermissions['sysop']['checkuser']       = true;
$wgGroupPermissions['sysop']['delete']          = true;
$wgGroupPermissions['sysop']['deletedhistory']  = true;
$wgGroupPermissions['sysop']['editinterface']   = true;
$wgGroupPermissions['sysop']['editusercssjs']   = true;
$wgGroupPermissions['sysop']['import']          = true;
$wgGroupPermissions['sysop']['importupload']    = true;
$wgGroupPermissions['sysop']['move']            = true;
$wgGroupPermissions['sysop']['patrol']          = true;
$wgGroupPermissions['sysop']['autopatrol']      = true;
$wgGroupPermissions['sysop']['protect']         = true;
$wgGroupPermissions['sysop']['proxyunbannable'] = true;
$wgGroupPermissions['sysop']['rollback']        = true;
$wgGroupPermissions['sysop']['trackback']       = true;
$wgGroupPermissions['sysop']['upload']          = true;
$wgGroupPermissions['sysop']['reupload']        = true;
$wgGroupPermissions['sysop']['reupload-shared'] = true;
$wgGroupPermissions['sysop']['unwatchedpages']  = true;
$wgGroupPermissions['sysop']['autoconfirmed']   = true;
$wgGroupPermissions['sysop']['upload_by_url']   = true;
$wgGroupPermissions['sysop']['ipblock-exempt']  = true;
$wgGroupPermissions['sysop']['blockemail']      = true;
$wgGroupPermissions['sysop']['purge']           = true;
$wgGroupPermissions['sysop']['writeapi']        = true;
  • user with confirmed email (emailconfirmed)
# Make it so users with confirmed e-mail addresses are in the group.
$wgAutopromote['emailconfirmed'] = APCOND_EMAILCONFIRMED;
# Hide group from user list.
$wgImplicitGroups[] = 'emailconfirmed';
# Finally, set it to true for the desired group.
$wgGroupPermissions['emailconfirmed']['createtalk']     = true;
$wgGroupPermissions['emailconfirmed']['editmyoptions']  = true;
$wgGroupPermissions['emailconfirmed']['editmywatchlist']= true;

#Force ConfirmEmail special pages acces
$wgGroupPermissions['*']['viewmyprivateinfo'] = true;
$wgGroupPermissions['*']['editmyprivateinfo'] = true;

upload/size limit

add the following lines to LocalSettings.php

$wgUploadSizeWarning = 15000000;
$wgMaxUploadSize = 15000000;

Also, modify the following lines in PHP.INI:

memory_limit = 1024M (need to be higher than upload limit)
post_max_size = 15M
upload_max_filesize = 15M

upload/mimes types management

  • mimes types list is in "includes/mime.types"
  • to remove all restriction, you need to add thoose line in LocalSettings.php:
$wgStrictFileExtensions=false;
$wgVerifyMimeType=false;

upload/extensions management

$wgFileExtensions is an array who contains all default extensions allowed, can be modified in LocalSettings.php :

Add an extension

$wgFileExtensions[] = 'pdf';

Add some extensions

$wgFileExtensions = array_merge( $wgFileExtensions, array( 'pdf', 'ppt', 'jp2', 'webp' ) );

Reset full array

$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'jp2', 'webp', 'ppt',
                           'pdf', 'psd', 'mp3', 'xls', 'xlsx', 'swf', 'doc',
                           'docx', 'odt', 'odc', 'odp', 'odg', 'mpp');

Content

Wikimedia Code

Table

Images

Gallery

Links

to force external link, you need to add in LocalSettings.php the line:

$wgExternalLinkTarget = '_blank';

HTML tags

  • allow html tags
$wgRawHtml = true;

this is not recommended, neither securized, and it can conflict with $wgUseTidy for some tags like the links

the best is to use the extension https://www.mediawiki.org/wiki/Extension:Secure_HTML

Advanced

  • Modify side bar content
index.php/MediaWiki:Sidebar
  • Style sheet

files are in /skins/{skinName}

  • purge pages cache
{URL}?action=purge
  • purge all cache
php maintenance/purgeList.php --purge --all
  • force page access without cache
$wgUseFileCache=false;
  • Magic words

official doc: http://en.wikipedia.org/wiki/Help:Magic_words

for example __NOTOC__ Suppresses the appearance of the page's TOC. Can be used anywhere on a page.

  • Special pages
/index.php/Special:SpecialPages
/index.php/Special:Allpages all pages
/index.php/Special:Version description of current wiki
/index.php/Special:Gather list of gathered pages
/index.php/Special:Statistics global stats

Update

official doc: https://www.mediawiki.org/wiki/Manual:Upgrading

you can see your curent version in source code off any page in the meta name generator: <meta name="generator" content="MediaWiki 1.25alpha">

  1. get last version of wikimedia on http://www.mediawiki.org/wiki/Download
  2. save your configuration file Localsettings.php, skins & extensions folder
  3. extract new wiki files
  4. put saved Localsettings.php in the new wiki files
  5. add back your extensions & skins
  6. set web user/group rigths (www-data) and if needed, link it to webserver
  7. remove execution from image folder : chmod 550 ${wikifolder}images/* -R
  8. update the database with the linecommand : php maintenance/update.php

Skins & Extensions

Skins

  • all referenced skins:

http://www.mediawiki.org/wiki/Category:All_skins

Extensions

all existing extensions: http://www.mediawiki.org/wiki/Category:All_extensions

  • installed extensions:
index.php/Special:Version

ShortUrl

official doc: https://www.mediawiki.org/wiki/Manual:Short_URL/en

  • in LocalSettings.php
$wgScriptPath = "";
$wgArticlePath="/$1";
  • in apache web config
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php [L]

Multilanguage

official doc: http://www.mediawiki.org/wiki/Manual:Wiki_family

installation description with some wiki who share same ressources (Scenario 4)

Create each wiki

  • install each wiki:

for each language, a wiki need to be created in is own folder; the best practice is to set them in the same main folder, for example:

{Path}/wiki/fr                wiki in french
{Path}/wiki/en                wiki in english
{Path}/wiki/pool              common files

You can use the bash script available there

  • web symbolic links
ln -s {Path}/wiki/fr /var/www/wiki/fr
ln -s {Path}/wiki/en /var/www/wiki/en
ln -s {Path}/wiki/pool /var/www/wiki/pool
  • database installation

you can set a database for each wiki, but the best practice is to set them in the same database with different prefix

préfix fr_          for french wiki
préfix en_          for english wiki
préfix pool_        for common files
  • configuration

interwiki table need this configuration information(ou use special page interwiki menu):

INSERT INTO `wiki`.`interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('pool', 'http://pool.wiki.frogg.fr/index.php/$1', '1', '1');
INSERT INTO `wiki`.`interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('fr', 'http://fr.wiki.frogg.fr/index.php/$1', '1', '1');
INSERT INTO `wiki`.`interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('en', 'http://en.wiki.frogg.fr/index.php/$1', '1', '1');

INSERT INTO `wiki`.`fr_interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('pool', 'http://pool.wiki.frogg.fr/index.php/$1', '1', '1');
INSERT INTO `wiki`.`fr_interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('fr', 'http://fr.wiki.frogg.fr/index.php/$1', '1', '1');
INSERT INTO `wiki`.`fr_interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('en', 'http://en.wiki.frogg.fr/index.php/$1', '1', '1');

INSERT INTO `wiki`.`en_interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('pool', 'http://pool.wiki.frogg.fr/index.php/$1', '1', '1');
INSERT INTO `wiki`.`en_interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('fr', 'http://fr.wiki.frogg.fr/index.php/$1', '1', '1');
INSERT INTO `wiki`.`en_interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('en', 'http://en.wiki.frogg.fr/index.php/$1', '1', '1');

INSERT INTO `wiki`.`pool_interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('pool', 'http://pool.wiki.frogg.fr/index.php/$1', '1', '1');
INSERT INTO `wiki`.`pool_interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('fr', 'http://fr.wiki.frogg.fr/index.php/$1', '1', '1');
INSERT INTO `wiki`.`pool_interwiki` (`iw_prefix`, `iw_wikiid`, `iw_local`, `iw_trans`) 
	VALUES ('en', 'http://en.wiki.frogg.fr/index.php/$1', '1', '1');
  • LocalSettings.php of each wiki need extra command lines:
 $wgGroupPermissions['sysop']['interwiki'] = true ;
  • common file sharing
$wgUseSharedUploads = true;
$wgHashedSharedUploadDirectory = true;
$wgUploadNavigationUrl = $wgServer."/wiki_pool/index.php/Special:Upload";
$wgSharedUploadPath = $wgServer."/wiki_pool/images";
$wgSharedUploadDirectory = "/opt/wiki/pool/images/";

$wgFetchCommonsDescriptions = true;
$wgSharedUploadDBname = 'wiki';
$wgSharedUploadDBprefix = 'pool_';
$wgRepositoryBaseUrl = $wgServer."/wiki_pool/index.php/Image:";
  • database sharing
$wgInterwikiCentralDB = 'wiki';
$wgSharedDB = 'wiki';
$wgSharedPrefix = 'fr_';
$wgSharedTables = array('user','user_groups','interwiki','ipblocks');
  • multidomain interwiki cookie sharing
$wgCookieDomain = '.frogg.fr';

Optimisation

to prevent to much duplicated configuration , LocalSetting.php can be split with common part in shared config file, this is my version: click here to see all detail of my optimised settings

Add lang tag in your pages

  • to activate lang, you need to add this code in each pages:
[[en:{{PAGENAME}}]]
[[fr:{{PAGENAME}}]]

Site Map

  • generate sitemap.xml
cd /opt/web/wiki/fr
mkdir -p sitemap
php maintenance/generateSitemap.php \
	--fspath sitemap \
	--server http://88.181.108.14:777/wiki \
	--urlpath http://88.181.108.14:777/wiki/sitemap \
	--conf LocalSettings.php
  • bonus 1: move & rename xml generated to root/sitemap.xml
mv $(echo sitemap/*.xml) sitemap.xml
  • bonus 2: register sitemap on google webmaster tools:

https://www.google.com/webmasters/tools/sitemap-list

Increase security

Official Doc

  • Security

http://www.mediawiki.org/wiki/Manual:Security

  • Anti Spam/Robot

http://www.mediawiki.org/wiki/Manual:Combating_spam

Wiki configuration

  • modify the secret key in LocalSetting.php (with a random long text)
$wgSecretKey = "H3r34nYT3xT2S2cUR3y0uRW1k1";
  • check user email on account creation
$wgEmailConfirmToEdit = true;
$wgEmailAuthentication = true;
  • set user rights

Link to Rights Management

  • Add my script to remove Special page & purge access to non-sysop users

Link to Remove access to non-sysop user script

Wiki Extensions

  • Add an anti-bot captcha

http://www.mediawiki.org/wiki/Extension:ConfirmEdit

  • convert email adress in images anti-bot

http://www.mediawiki.org/wiki/Extension:EmailAddressImage

  • visualize user rights

http://www.mediawiki.org/wiki/Extension:GlobalUserGroups

PHP Configuration

modify php config file php.ini (under linux : /etc/php5/apache2/php.ini)

allow_url_fopen off

Increase performances

Official doc: http://www.mediawiki.org/wiki/Manual:Performance_tuning

Mediawiki

  • LocalSettings.php
# Uncomment this to disable output compression
# $wgDisableOutputCompression = true;
 
# Shared memory settings
$wgMainCacheType = CACHE_ACCEL; #PHP APC
#$wgMainCacheType = CACHE_NONE;
$wgMemCachedServers = array(); 

# Parser Cache
$wgParserCacheExpireTime = 604800; #1 Week

# Load.php expires
$wgResourceLoaderMaxage['versioned']['server'] = 604800;
$wgResourceLoaderMaxage['versioned']['client'] = 604800;
$wgResourceLoaderMaxage['unversioned']['server'] = 604800;
$wgResourceLoaderMaxage['unversioned']['client'] = 604800;

# Job.php rate
$wgJobRunRate = 0;

# Sidebar cache
$wgEnableSidebarCache = true;

# File cache
$wgUseFileCache = true;
$wgFileCacheDirectory  = "$IP/cache";
$wgUseGzip = true;
$wgFileCacheDepth = 0;

# Cache folder
$wgCacheDirectory = "$IP/cache";
  • $wgJobRunRate = 0 will no longer starts job each x pages, so task has to be added to /etc/crontab instead
0 0 * * * /usr/bin/php php /var/www/wiki/fr/maintenance/runJobs.php --conf /var/www/wiki/fr/LocalSettings.php > /var/log/wiki/runJobsFr.log 2>&1

Apache

/etc/apache2/sites-available/{YourSite}

# MOD_DEFLATE COMPRESSION
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application$

# DEFLATE NOT COMPATIBLE BROWERS
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# NOT CHACHING IF ALREADY CACHED
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip

# EXPIRE HEADERS
<IfModule mod_expires.c>
ExpiresActive On
#Images
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
AddType image/x-icon .ico
ExpiresByType image/ico "access plus 1 year"
ExpiresByType image/icon "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
#Elements
ExpiresByType application/xhtml+xml "access plus 1 week"
ExpiresByType text/html "access plus 1 week"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType text/x-javascript "access plus 1 week"
#Others
ExpiresDefault "access plus 1 month"
</IfModule>

# CACHE-CONTROL HEADERS
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|jpe?g|png|gif|swf|gz|ttf)$">
Header set Cache-Control "max-age=2797200, public"
</FilesMatch>
<FilesMatch "\\.(css)$">
Header set Cache-Control "max-age=2797200, public"
</FilesMatch>
<FilesMatch "\\.(js)$">
Header set Cache-Control "max-age=2797200, private"
</FilesMatch>
<filesMatch "\\.(html|htm)$">
Header set Cache-Control "max-age=86400, public"
</filesMatch>
# Disable caching for scripts and other dynamic files
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>
</IfModule>

For more information about Apache click here

Result

server statistic: http://info.home.frogg.fr

Google Pagespeed Insights results

Script

Script install/update/save/rollback

https://github.com/Fro99666/BASH_froggLinuxWikiFamilyManager

  • options for wiki:
    • bash wikiManager.sh -install : to install wiki
    • bash wikiManager.sh -update : to update wiki
    • bash wikiManager.sh -backup : to backup wiki
    • bash wikiManager.sh -rollback : to rollbak wiki
  • options for mysql & phpmyadmin:
    • bash wikiManager.sh -mysqlupdate: to update mysql & phpmyadmin
    • bash wikiManager.sh -mysqlbackup : to backup mysql & phpmyadmin
    • bash wikiManager.sh -mysqlrollback : to rollback mysql & phpmyadmin
  • more options:
    • bash wikiManager.sh -changepass : to linux & wiki password change
    • bash wikiManager.sh -{command} -confirm : autoconfirmation

Remove access to non-sysop user

  • remove the access to non-sysop user for Special & Purge (redirect user to login screen)

wiki extension : https://github.com/Fro99666/PHP_Mediawiki_removeSpecialPageAccess

Debug

  • Global Debug
$wgShowExceptionDetails = true;
$wgDebugToolbar = true;
$wgShowDebug = true;
$wgDevelopmentWarnings = true;
  • Sql Debug
$wgShowSQLErrors = true;
$wgDebugDumpSql = true;
$wgShowDBErrorBacktrace = true;
  • Debug in LogFile
 $wgDebugLogFile = "/tmp/{$wgSitename}-debug.log"

Support

IRC server & IRC chanel