Jump to content

Project:Support desk

About this board

Welcome to the MediaWiki Support desk. This is a place where you can ask any questions you have about installing, using or administrating the MediaWiki software.

(Read this message in a different language)

See also

Before you post

Post a new question

  1. To help us answer your questions, please indicate which version of MediaWiki you are using, as found on your wiki's Special:Version page:
  2. If possible, add $wgShowExceptionDetails = true;error_reporting( -1 );ini_set( 'display_errors', 1 ); to LocalSettings.php in order to make MediaWiki show more detailed error messages.
  3. Please include the web address (URL) to your wiki if possible. It's often easier for us to identify the source of the problem if we can see the error directly.
  4. To start a new thread, click the box with the text "Start a new topic".

nginx rewrite rules for multiple wikis

1
Teer.8 (talkcontribs)

Can anyone please help me set up nginx rewrite rules for multiple wikis with a common installation? I have a separate wiki for each language. E.g.

   example.org/wiki/en
   example.org/wiki/fr/

Problem: Both wikis load with the correct URLs, but any action re-directs to the English wiki.

   E.g. creating a new page on the French (i.e. example.org/wiki/fr/) wiki re-directs to the English (i.e. example.org/wiki/en/) wiki.
   And if I try to create `Main_page` on the French wiki, it re-directs and opens editing the existing Main_page on the English wiki @ example.org/wiki/en/Main_Page.

How do I rectify this? Thanks in advance, I am completely stumped and any help will be GREATLY appreciated.

nginx config:

   server 
   {
       ssl_certificate     /etc/letsencrypt/live/example.org/fullchain.pem;    # managed by Certbot
       ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;      # managed by Certbot
       listen          443 ssl;
       server_name     example.org;
       root            /srv/live/static/example.org/www;   # wiki is not root page
       access_log      /var/log/nginx/example.org/access.log;
       error_log       /var/log/nginx/example.org/error.log;


       location ^~ /wiki/
       {
           alias /srv/live/php/mediawiki-1.42.1/;
           # Redirect /wiki/ to /wiki/en/
           location = /wiki/
           {
               return 301 $scheme://$host/wiki/en/;
           }
           try_files $uri $uri/ @mediawiki;
           # PHP handling for wiki
           location ~ \.php$ 
           {
               fastcgi_pass    unix:/var/run/php/php8.3-fpm.sock;
               fastcgi_index   index.php;
               fastcgi_param   SCRIPT_FILENAME $request_filename;
               fastcgi_param   MW_DB $arg_lang;
               include fastcgi_params;
           }
       }
       location @mediawiki
       {
           set $lang 'en';
           if ($uri ~ "^/wiki/(en|fr)/")
           {
               set $lang $1;
           }
           set $wiki_id 'example_org_en';
           if ($lang = 'fr') 
           {
               set $wiki_id 'example_org_fr';
           }
           rewrite "^/wiki/([a-z]{2})/(.*)$" /wiki/index.php?title=$2&lang=$1 last;
           fastcgi_param MW_DB $wiki_id;
       }
   }

LocalSettings.php

   <?php
   # Protect against web entry
   if ( !defined( 'MEDIAWIKI' ) ) {
       exit;
   }
   
   # Multi-wiki configuration
   $wgConf = new SiteConfiguration();
   $wikiLangMap = [
       'example_org_en' => 'en',
       'example_org_fr' => 'fr',
   ];
   
   $wgConf->wikis = array_keys($wikiLangMap);
   
   $wgConf->settings = [
       'wgServer' => [
           'default' => 'https://example.org',
       ],
       'wgSitename' => [
           'default' => 'example Wiki',
       ],
       'wgLanguageCode' => $wikiLangMap,
       'wgDBprefix' => [
           'example_org_en' => 'example_org_en_',
           'example_org_fr' => 'example_org_fr_',
       ],
   ];
   
   # Determine the current wiki
   $wikis = [
       'example.org/wiki/en' => 'example_org_en',
       'example.org/wiki/fr' => 'example_org_fr',
   ];
   
   if ( defined( 'MW_DB' ) ) 
   {
       $wikiID = MW_DB;
   }
   else
   {
       $uri = $_SERVER['REQUEST_URI'] ?? ;
       $parts = explode('/', trim($uri, '/'));
       $lang = $parts[1] ?? 'en';  // Default to 'en' if not specified
       $wikiID = $wikis["example.org/wiki/$lang"] ?? 'example_org_en';
   }
   
   # Apply the settings
   $wgConf->extractAllGlobals( $wikiID );
   
   # Common settings
   $wgScriptPath       = '/wiki';
   $wgResourceBasePath = $wgScriptPath;
   $wgArticlePath = "/wiki/$wgLanguageCode/$1";
   
   $wgLogos = [
       '1x' => "$wgResourceBasePath/resources/assets/change-your-logo.svg",
       'icon' => "$wgResourceBasePath/resources/assets/change-your-logo.svg",
   ];
   
   $wgEnableEmail = true;
   $wgEnableUserEmail = true;
   $wgEmergencyContact = ;
   $wgPasswordSender = ;
   $wgEnotifUserTalk = true;
   $wgEnotifWatchlist = true;
   $wgEmailAuthentication = true;
   
   ## Database settings
   
   $wgDBtype     = 'mysql';
   $wgDBserver   = 'localhost';
   $wgDBname     = 'mediawiki_docs_db';
   $wgDBuser     = 'wiki_example_org';
   $wgDBpassword = 'password';
   
   # MySQL specific settings
   
   $wgDBssl = false;
   $wgDBTableOptions = "ENGINE=InnoDB, DEFAULT CHARSET=binary";
   
   # the rest are defaults, will post if requested!


.../mediawiki-1.42.1/settings/example.org/LocalSettings.en.php

   <?php
   $wgLanguageCode = 'en';
   $wgSitename     = 'example.org Wiki';

.../mediawiki-1.42.1/settings/example.org/LocalSettings.fr.php

   <?php
   $wgLanguageCode = 'fr';
   $wgSitename     = 'example.org Wiki';
Reply to "nginx rewrite rules for multiple wikis"

Pre-commit hook Errors

3
AnujAgrawal380 (talkcontribs)

I'm trying to commit the changes i made for while now. Whenever i tried to git commit it give error: I will now check that you built them using the correct Node.js version v18.20.2.

Note: You are using v18.20.2.

Building assets...

2024-07-19 18:13:14: webpack compiled

M       resources/dist/mobile.special.watchlist.scripts.js

M       resources/dist/mobile.special.watchlist.scripts.js.map.json

M       resources/dist/mobile.startup.js.map.json

After I built the assets, I noticed differences in the contents to what you committed.

Try running `npm run build` again or removing the node_modules folder and running npm install with the correct node version.

pre-commit:

pre-commit: We've failed to pass the specified git pre-commit hooks as the `precommit`

pre-commit: hook returned an exit code (1). If you're feeling adventurous you can

pre-commit: skip the git pre-commit hooks by adding the following flags to your commit:

pre-commit:

pre-commit:   git commit -n (or --no-verify)

pre-commit:

pre-commit: This is ill-advised since the commit is broken.

pre-commit:

Also, i installed all the necessary packages. I think the issue lies in the not adding package.json and package-lock.json to the staging area. Also, i didnt build the directory using npm run build. It would be really helpful if someone could assist me.

Note: This is the MobileFrontend extension directory.

Malyacko (talkcontribs)

Where exactly can this output be seen after you ran "git commit"? In your command line?

AnujAgrawal380 (talkcontribs)

after output of all tests.

Reply to "Pre-commit hook Errors"

MediaWiki:GlobalBlock Extension

4
Nexovia (talkcontribs)

Hello, I have followed all instruction as tolded in Extension:GlobalBlocking but when after I added the wfLoadExtension and entered my wiki it says the following error whats the solution of this

Database error

A database query error has occurred. This may indicate a bug in the software.

[ZpeOYZ36VsF47Yx6zkYYuwAAAAs] 2024-07-17 09:26:58: Fatal exception of type "Wikimedia\Rdbms\DBQueryError"

Bawolff (talkcontribs)

As a first step, set $wgShowExceptionDetails = true; in LocalSettings.php

Did you create all the appropriate database tables in the appropriate databases?

Nexovia (talkcontribs)

How can I create that table and what should I place.

Bawolff (talkcontribs)
Reply to "MediaWiki:GlobalBlock Extension"

MediaWiki in WordPress

3
きくらげさん (talkcontribs)

(Translated to English by Google)

I installed MediaWiki under a directory where WordPress is located (e.g. example.jp/wordpress/w/index.php), but the URLs were displayed in the format /w/index.php?title=$1, which was hard to read, so I changed it to /wiki/$1.

But then the pages were loaded on WordPress instead of MediaWiki, and I got a WordPress 404 error. What can I do to get them to display correctly?

I tried removing the permissions from WordPress to /wiki/ and /w/ in .htaccess, but it didn't work.

(I'm a beginner, so my explanation may be poor or my measures may be strange, but please bear with me.)


(Original: Japanese text)

WordPress のあるディレクトリの下 (例: example.jp/wordpress/w/index.php) に MediaWiki を導入してみたのですが、URL が /w/index.php?title=$1 の形式で表示されていて見にくかったので、/wiki/$1 の形式に変更しました。

すると MediaWiki 側ではなく WordPress 側でページが読み込まれ、WordPress の 404 エラーが出てしまいます。 正常に表示させるにはどうすればよいでしょうか?

.htaccess で、WordPress から /wiki/ と /w/ への権限をなくしてみましたが効果はありません。

(初心者のため、伝え方が下手だったり施策がおかしかったりするかもしれませんが、ご容赦願います)

Fokebox (talkcontribs)

Why do you need CMS at the same directory. Have them at separate directories and set up both to use scripts paths to the direcotries. More over you can have bothsites at ceperate domain names like wiki.mysite.jp and wordpress.mysite.jp

Bawolff (talkcontribs)

You probably need different rewrite rules in .htaccess to control which application handles the url. There arent guides for when both wordpress and mediawiki are together - so if you are a new user i would reccomend not having them together so you can just follow manual:ShortURL

Reply to "MediaWiki in WordPress"

JS of my special page extension not loading only on smartphone

2
Aphfug (talkcontribs)

On my wiki I made a special page that display recent changes in a pinterest style. Fort the image, it fetchs them using mediawikiParserOutput as a thumb 100px and then with js, I fetch the big images and put them where it should go. On desktop the js is loaded properly but on smartphone (and mozilla firefox smartphone simulation), it doesn't load.

It doesn't even matter what is in the js, if the js is only composed of a console.log("loaded"), there will be nothing in the console.

Here's my extension.json :

{
"manifest_version": 1,
"name": "ArchiRecentChanges",
"version": "1.1",
"license-name": "GPL-3.0",
"author": "Aymeric Feltz",
"description": "Custom pages for archi-wiki.org that display a pinterest style list of recent changes",
"type": "specialpage",
"SpecialPages": {
"ArchiRecentChanges": "ArchiRecentChanges\\SpecialArchiRecentChanges"
},
"AutoloadClasses": {
"ArchiRecentChanges\\SpecialArchiRecentChanges": "SpecialArchiRecentChanges.php"
},
"MessagesDirs": {
"ArchiRecentChanges": [
"i18n"
]
},
"ResourceModules": {
"ext.archirecentchanges": {
"scripts": [
"js/archirecentchanges.js"
],
"messages":[
"readthis"
]
}
},
"ResourceFileModulePaths": {
"localBasePath": "",
"remoteExtPath": "ArchiRecentChanges"
},
"ExtensionMessagesFiles": {
"ArchiRecentChangesAlias": "ArchiRecentChanges.i18n.alias.php"
}
}


The page in question

archi-mediawiki/extension/archiRecentChanges (commit 58bfb64de078fc436b60993f0f726f5cc15e4fd5, 19/07/24)

Product Version
MediaWiki 1.39.7
PHP 7.4.33 (fpm-fcgi)
MariaDB 10.11.6-MariaDB-0+deb12u1-log
ICU 72.1
elasticsearch 6.8.23

We also have some js in our hack.js in our skin folder (that we deploy with npm), and this js works perfectly fine. It's only with the js of the extension that I have problems with

Bawolff (talkcontribs)

I think on 1.39 you have to specify targets in ResourceModules in extension.json for the js to load on mobile. This requirement was removed in newer versions of mediawiki.

Reply to "JS of my special page extension not loading only on smartphone"
Lamarkdavis (talkcontribs)

Hello, I was wondering does Wiki make changes if a person names and hometown is wrong on the site? If yes, I will forward you the correct information once I get an answer from you.


Thanks,

LaMark Davis

Bawolff (talkcontribs)

Generally yes if you have a reference to cite in order to know the information is correct. In fact (in most cases) you can make the change yourself.

However, this is the wrong place to ask these types of questions. Please ask questions about contributing to english wikipedia at w:WP:TEAHOUSE as they will be able to help you better.

Reply to "Name wrong"

Wiki pages with somewhat long titles error when saving

15
Kupirijo (talkcontribs)

Hello,

I have upgraded to MediaWiki 1.39.7 with the following components:

Product Version
MediaWiki 1.39.7
PHP 7.4.33 (apache2handler)
MariaDB 10.5.25-MariaDB
ICU 74.2

I have been getting errors from the web browser such as "The connection was reset" when I try to edit and save pages with somewhat long titles (about 30 characters). Note that the titles are in the Greek alphabet, so I do not know if this plays a role regarding the size of character encoding. From what I read online, the maximum size for a page title is 255 bytes.

Also sometimes when saving is successful, I get lines of the form "<<<<<<< /private/var/tmp/merge-old-6jssyq" incorporated into the page's contents.

Note that I did not have problems of this sort with older versions of MediaWiki (or MySQL). I also do not have any problems with pages that have shorter page titles.

Any help on the matter is appreciated.

Thank you in advance.

TheDJ (talkcontribs)

> I get lines of the form "<<<<<<< /private/var/tmp/merge-old-6jssyq" incorporated into the page's contents

This sounds like you have a git merge conflict in a file of your mediawiki installation.

Kupirijo (talkcontribs)

Thank you @TheDJ

Could you explain how git is involved in this error please? Aren't characters "<<<<<<<<" and ">>>>>>>>" used more widely and not only in git?

Btw, this type of lines appears in the source of a wiki page, when I am editing a section of the page.

TheDJ (talkcontribs)

merge-old is what was triggering me. That is the prefix for the filenames that git uses when encountering two conflicting versions.

Bawolff (talkcontribs)

Greek characters are 2 bytes each. 30 character greek title = 60 bytes. So its probably not a length issue.

It could also be something going wrong with edit conflict merging which also uses diff3 (and uses the merge-old-xxxxx convention), but i've never heard that happening before. See also manual:$wgDiff3


Can you check your php error log.

Kupirijo (talkcontribs)

Thank you. I checked /var/log/apache2/error.log

and I get

[Thu Jul 11 08:52:19.418457 2024] [core:notice] [pid 137] AH00052: child pid 21546 exit signal Segmentation fault (11)

[Thu Jul 11 08:52:19.418818 2024] [core:notice] [pid 137] AH00052: child pid 21052 exit signal Segmentation fault (11)


Also I have the following values in LocalSettings.php

## Shared memory settings

$wgMainCacheType    = CACHE_NONE;

$wgMemCachedServers = array();


Thank you in advance.

Bawolff (talkcontribs)

Debugging php segfaults can be pretty difficult if you arent familiar with php internals. Normally i suggest updating your version of php to see if that helps.

Kupirijo (talkcontribs)

Thank you. Shall I update to PHP 8.1?

Want (talkcontribs)

What is the distribution on the server? Or do you operate in a container?

Kupirijo (talkcontribs)

Hi. By "distribution" do you mean the current version of PHP? If yes, it is on the first message in the thread (7.4.33 (apache2handler)). I am running the wiki locally (MacOS).

Want (talkcontribs)

Ok. If MasOS used, probably is created any container. It is possible that something is missing from it.

Want (talkcontribs)
Kupirijo (talkcontribs)
Want (talkcontribs)

Yes, but not use bitnami prefabricated package. It's Debian on a VM, with MW instalation from Git repositories.

Bawolff (talkcontribs)

Its worth a shot.

Reply to "Wiki pages with somewhat long titles error when saving"

How to disable caching for files for good?

8
Kghbln (talkcontribs)

On a wiki, I have the problem that uploaded new versions of existing files are not directly updated on pages linking them. If I click on a link, I get the previously uploaded version of the file. These are mainly PDF files, so no thumbnailing is involved if this matters.

LocalSettings.php
$wgMainCacheType = CACHE_MEMCACHED;
$wgParserCacheType = CACHE_NONE;
$wgSessionCacheType = CACHE_DB;
$wgMessageCacheType = CACHE_MEMCACHED;
$wgMemCachedServers = [
      '127.0.0.1:11211'
];

$wgCachePages = false;
$wgUseLocalMessageCache = true;
$wgEnableParserCache = false;

$wgGenerateThumbnailOnParse = false;
VitualHost
<IfModule mod_headers.c>
	<filesMatch ".(pdf|odt|ott|doc|docx|dot|ods|ots|xls|xlsm|xlsx|xlt|odp|otp|ppt|pptx|pot|svg|jpg|jpeg|png|gif)$">
		Header set Cache-Control "no-cache, no-store, must-revalidate"
		Header set Pragma "no-cache"
		Header set Expires 0
	</filesMatch>
	...
</IfModule>

The issue persists. I suspect that I also need to set the main cache to $wgMainCacheType = CACHE_NONE; and forget about the message cache.

Perhaps there is something else I am missing?

TheDJ (talkcontribs)

There is no cache for this that is part of your localsettings.

Your webserver configuration is only disabling the cache for files which are served from disk. If they still need to be generated (by a 404 handler, or if they are always provided by thumb.php, then your filesMatch won't do anything, as they are not files. They are files streamed though a php script in that case.

Kghbln (talkcontribs)

To rephrase your reply since I am not sure if I understand correctly:

I need to set up a working 404 handler to prevent file caching? From what I posted, you cannot see if it is set up properly.

In this case, I can provide specific information:

LocalSettings.php

$wgGenerateThumbnailOnParse = false;
$wgThumbnailScriptPath = "$wgScriptPath/thumb.php";

Virtual Host

<Directory /path/to/wiki/>
    AuthType Basic
    AuthName "Access to my wiki"
    AuthUserFile "/var/htfiles/.htpasswd"
    <RequireAny>
        Require valid-user
        Require ip 127.0.0.1
        Require ip 82.202.93.130
        Require ip 86.34.125.129
    </RequireAny>
</Directory>

<Directory /path/to/wiki/images/>
    AllowOverride None
    AddType text/plain .html .htm .phtml .shtml .lua .php .pl .py .rb .sh
    php_flag engine off
</Directory>

# Exclude thumb.php from authentication
<Files "thumb.php">
    Satisfy Any
    Allow from all
</Files>

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^/?p(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
    RewriteRule ^/?$ %{DOCUMENT_ROOT}/w/index.php [L]

    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
    RewriteRule ^/?w/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2 [L,QSA,B]

    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
    RewriteRule ^/?w/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
</IfModule>

My second interpretation is to remove the existing thumb handling by setting wgGenerateThumbnailOnParse = true;

Ultimately, I want to provide the most recent version of an uploaded file no matter what.

TheDJ (talkcontribs)

> I need to set up a working 404 handler to prevent file caching?

No, I wasn't sure what setup you are running and indicating that what you have configured SO FAR

OK, so you are using thumb.php. In that case, you should see in your browser that all requests for images are of the form https://commons.wikimedia.org/w/thumb.php?f=Example.png&w=600&p=206

You'll want to modify the <Files "thumb.php"> block to add headers that disable the cache.

Kghbln (talkcontribs)

> No, I wasn't sure what setup you are running and indicating that what you have configured SO FAR

In other words, do I need to disable the 404 handler?

> OK, so you are using thumb.php. In that case, you should see in your browser that all requests for images are of the form

This is correct. Files are served via "thumb.php?f=FileName.pdf&widht=120.."

> You'll want to modify the <Files "thumb.php"> block to add headers that disable the cache.

I believe this should do the job:

<Files "thumb.php">
    Satisfy Any
    Allow from all
    <IfModule mod_headers.c>
        Header set Cache-Control "no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires 0
    </IfModule>
</Files>

I am still unsure if I should have a 404 handler in the first place.

Kghbln (talkcontribs)

@TheDJ: What is your opinion on having a 404 handler in the setup? :)

Bawolff (talkcontribs)

I would also suggest checking your browsers network tab to verify that all the headers are being set, and what caching behaviour is actually taking place (e.g. verify there isnt incorrect 304 responses or something)

Kghbln (talkcontribs)

The network analyses reveal no caching, i.e., I get "Answers from cache: 0." There is no 304 status to see—all 200, at least from my side. I am now hoping that the most current files are being served. The users need to verify. Let's wait for TheDJs' reply.

Reply to "How to disable caching for files for good?"

所有的新页面都是404

2
对此佛具 (talkcontribs)

按道理说当访问到一个不存在的wiki页面应该展示新建页面的选项,但是现在会直接显示404页面,即使是全新安装的wiki也是,我该如何解决这个问题?

Bawolff (talkcontribs)

Its hard to say. Possibly your webserver or hosting provider is intercepting and replacing 404 messages.

很难说。可能是你的网络服务器或托管提供商拦截并替换了 404 消息。

Reply to "所有的新页面都是404"

Redirect to log in page if user not logged in

1
Rakon12 (talkcontribs)

Hello

I'm creating a private wiki. My goal is to have the user immediately redirected to the login page from any page when they're not logged in. But I cannot get it to work without changing the mediawiki sources. I do not want to change the sources for security reasons.

My versions are:

MediaWiki 1.39.4
PHP 8.2.4 (apache2handler)
MariaDB 10.4.28-MariaDB
ICU 71.1

I tried to use a hook but since the not logged in page is a permissionErrorPage the redirect is not executed. The hooks I tried were BeforeInitialize and BeforePageDisplay.

Below my hook handle which i wrote into LocalSettings.php:

$wgHooks['BeforeInitialize'][] = function ( $title, $unused, $output, $user, $request, $mediaWiki ) {
    # Check if the user is not logged in and not login Page
    if ( $user->isAnon() && 
         strcmp($title, SpecialPage::getTitleFor( 'Userlogin' ))) {
        # Get URL
        $title = SpecialPage::getTitleFor( 'Userlogin' );
        $url = $title->getFullURL();
        # Redirect to login page
        $output->redirect( $url );
        return;
    }
    return true;
};

Is there a way to implement my request without changing the mediawiki sources? Or a different handle that suits my needs? I already searched through Manual:Hooks.

Thanks in advance

Reply to "Redirect to log in page if user not logged in"