Project:Support desk

About this board

Welcome to the MediaWiki Support desk, where you can ask MediaWiki questions!

(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 versions you are using, as found on your wiki's Special:Version page:
    • MediaWiki version
    • PHP version
    • Database type and version
  2. 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.
  3. To start a new thread, click "Start a new topic".

How to display only part of an image

4
Xelgen (talkcontribs)

Hi folks,

Is there a way to display just small, defined area of image using MediaWiki's [[Image:]]?

Let's say you have a scan of book page, and you want to show only illustration on that page, without showing whole scanned page (with text, etc..). Speaking more techicaly let's say we have image of 1000x800px and you want to display only a small part of it starting from possition 200,50 and with height width, 100 and 300.

Is it currently possible? Or planned in near future? I guess this will be very useful, especially for Wikisource.

I've googled for a while, and looked thorugh MedaWiki manuals, but didn't find an answer. I understand that currently there's no way to make it using only HTML <img> tag, but this can be done, using block elements, or displaying image as background.

Thanks beforehad,

MarkAHershberger (talkcontribs)

You could probably do something with jcrop.

Xelgen (talkcontribs)

Yes, that's what I'm using now. But JCrop is good for making a crop selection, and after that we have to crop it on 3rd party server, and upload a new cropped version of files back to wiki.

What I meant, was to use something in native MediaWiki Syntax, e.g. [[Image:Book_page_scan1|crop=X1,Y1,X2,Y2|thumb|this image shows only portion of page with X1, Y1 topleft corner, and X2, Y2 bottom right corner]] without having to upload new file, and just using what we already have.

You can probably do something like this with Divs and templates, but then image will be div's background, and won't behave the way regular images do.

But in the end of the day, visitors will have to load full image, to see just small part of it, and as I wanted to use it for few thousands images, on hopefully popular pages, I guess cropping and uploading new cropped images, is the way to go.

Thanks for your response.

Dabed (talkcontribs)

I want the same but although this question is more than 11 years old I guess there is still no way to do it or did you learn how?

Reply to "How to display only part of an image"

promoting common templates to several wikis to global level

3
Wladek92 (talkcontribs)

What is the best: to recopy the template on each wiki ? or to declare the template as global ?

example: the template Tunit is defined in Commons and re copied in MediaWiki

And where can we propose the template to be global ?

Thanks. --Christian 🇫🇷 FR (talk) 11:20, 11 April 2024 (UTC)

TheDJ (talkcontribs)

there is no such thing as a global template at this point in time.

Wladek92 (talkcontribs)

ok, thanks; so we agree to duplicate, of course as long as function remains compatible.

Reply to "promoting common templates to several wikis to global level"

How can I get a right logintoken?

2
Creamycd (talkcontribs)

I read the API:Login and API:Tokens and here's my code in Python to get a logintoken and try to find out whether or not it's valid:

import requests

# get logintoken
response = requests.get('https://www.mediawiki.org/w/api.php?action=query&meta=tokens&format=json&type=%2A')
data = response.json()
logintoken = data['query']['tokens']['logintoken']
print(f'logintoken: {logintoken}')

# check the token
post_response = requests.post(
    'https://www.mediawiki.org/w/api.php?action=checktoken&type=login&format=json',
    data={'token': logintoken}
)
print(post_response.json())

And then, always I get something like:

logintoken: e54db578b836e3a6d353bcc24a92048f6619080d+\
{'checktoken': {'result': 'invalid', 'generated': '2024-04-12T10:08:13Z'}}

How can I get a right logintoken?

Thank you!

Bawolff (talkcontribs)

Save and send cookies with your response

Reply to "How can I get a right logintoken?"

A segment of Common.js on my wiki should be correct, but throws up an error detected by MS Edge

6
Slgrandson (talkcontribs)

For the past several days, I have retooled the latter half of my Miraheze wiki's Common.js code with help from Stack Overflow, JSFiddle, and JSHint. (Recall from past correspondence that JavaScript is not a big strength of mine, and I learn by example.)

At this writing, here's what this segment looks like:

var toc = document.querySelector('.ns-3030 #toc'),
    firstHeading = document.querySelector('#firstHeading .mw-page-title-main').innerHTML,
    rcTitle = document.querySelector('#bodyContent .mw-changeslist-title').innerHTML,
    morphemeTitle = document.querySelector('.ns-3036 #firstHeading').innerHTML;
/* MagicNumberedHeadings substitute (exclusive to Grammar pages on this site) */
/* MNH is no longer supported on MW per [[wmphab:T284921]] */
/**
 * Auto-number headings
 *
 * @source https://mediawiki.org/wiki/Snippets/Auto-number_headings
 * @author Krinkle
 * @version 2021-10-03
 */
if (toc) {
  document.querySelectorAll('.mw-parser-output :is(h1,h2,h3,h4,h5,h6) .mw-headline').forEach(function (headline) {
    var num = toc.querySelector('a[href="#' + CSS.escape(headline.id) + '"] .tocnumber');
    if (num) headline.prepend(num.textContent + '. ');
  });
} else {
  document.body.classList.add('tpl-autonum');
}
/* Slash breaks on long page titles, especially as far as "Unspooled" infrastructure is concerned */
/* Source: https://stackoverflow.com/questions/36012874/how-to-wrap-a-text-after-slash */
if (firstHeading) {
     var s = document.querySelector('.mw-page-title-main').innerHTML;
     s = s.replace(/\//g,"/<wbr>"); 
     document.querySelector('.mw-page-title-main').innerHTML = s;
}
if (rcTitle) {
    var s2 = document.querySelector('.mw-changeslist-title').innerHTML;
    s2 = s2.replace(/\//g, "/<wbr>");
    document.querySelector('.mw-changeslist-title').innerHTML = s2;
}
/* DisplayTitle hack on pages for morpheme tables */
if (morphemeTitle) {
   var s3 = document.querySelector('.ns-3036 .mw-page-title-main').innerHTML;
   if (s3.match(/^-|-$/)) {
       s3 = morphemeTitle.replace("Morpheme","Affix");
   } else {
       s3 = morphemeTitle.replace("Morpheme","Root");}
   document.querySelector('.ns-3036 #firstHeading').innerHTML = s3.replace();
}

This is supposed to be properly coded, but Microsoft Edge insists otherwise. Inspecting this segment (under the "Console" pane) brings up an error:

Uncaught TypeError: Cannot read properties of null (reading 'innerHTML')
    at <anonymous>:1:900
    at globalEval (startup.js:1123:17)
    at runScript (startup.js:1274:6)
    at execute (startup.js:1385:4)
    at doPropagation (startup.js:737:6)

triggered by rcTitle = document.querySelector('#bodyContent .mw-changeslist-title').innerHTML for whatever reason. From here, how else can it be resolved? (Pinging Bawolff (talk · contribs) for help.)

(MW 1.41.0/PHP 8.2.7)

--Slgrandson (talk) 17:54, 11 April 2024 (UTC)

TheDJ (talkcontribs)
  1. you should not use innerHTML. I know there are lots of examples that use it, but don't use it. It breaks any other javascript that has to work with that piece of html. Please read this https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Manipulating_documents#creating_and_placing_new_nodes on how to modify the structure of HTML properly.
  2. The error in general means: you are trying to access innerHTML on something that doesn't exist. (and so.. don't do that).
  3. Specifically here, your firstHeading, rcTitle and morphemeTitle variables right at the very top, are looking for content that MIGHT not be available on the page you are at. For instance rcTitle is only present on recent changes pages and not on any other type of page. As such, the lookup rcTitle = document.querySelector('#bodyContent .mw-changeslist-title') returns absolutely nothing and you cannot access innerHTML on it. Instead, remove the .innerHTML from those lines. Then your variable indicates if the element exists and your conditions later on the page can check those variables, before continuing operations, like reading from or writing to them.
Bawolff (talkcontribs)

The code doesn't look correct. I would be very surprised if it is only microsoft edge complaining.

The part at the beginning (first 4 lines) should not have .innerHTML

Slgrandson (talkcontribs)

Having taken care of the "innerHTMLs" an hour and a half ago, only one problem remains:

Uncaught TypeError: morphemeTitle.replace is not a function
    at <anonymous>:2:778
    at globalEval (startup.js:1123:17)
    at runScript (startup.js:1274:6)
    at execute (startup.js:1385:4)
    at doPropagation (startup.js:737:6)

triggered by s3 = morphemeTitle.replace("Morpheme", "Root");. Once again, I thought I really had it made... --Slgrandson (talk) 22:21, 11 April 2024 (UTC)

Bawolff (talkcontribs)

that part needs the innerHTML

Slgrandson (talkcontribs)

After what seemed like ages, I finally got the final segment to work an hour ago (with doublechecking conducted on JSFiddle). Years of worrying are finally over:

/* DisplayTitle hack on pages for morpheme tables */
if (morphemeTitle) {
   var s3 = document.querySelector('#firstHeading').innerHTML;
   var s4 = document.querySelector('.mw-page-title-main').innerHTML;
   if (s4.match(/^-|-$/)) {
       s3 = s3.replace("Morpheme","Affix");
   } else {
       s3 = s3.replace("Morpheme","Root");}
   document.querySelector('#firstHeading').innerHTML = s3;
}

To @Bawolff: /@TheDJ: Thanks for your troubleshooting assistance. Take care! (Posted via my Galaxy Tab A.) --Slgrandson (talk) 21:41, 12 April 2024 (UTC)

Reply to "A segment of Common.js on my wiki should be correct, but throws up an error detected by MS Edge"

Unable to install pgpool 4.5.1

2
Summary by 2804:D51:4B3F:6D00:5426:77AF:6DC8:1A01
Manukapoor1978 (talkcontribs)

Hi ! I have been trying to install pgpool-II 4.5 for postgres 16 however I have been getting: Problem: cannot install the best candidate for the job - nothing provides libmemcached.so.11()(64bit) needed by pgpool-II-pg16-4.5.1-1pgdg.rhel9.x86_64 from pgpool45

More details:

OS: Red Hat Enterprise Linux 9.3

Commands used: dnf install -y pgpool-II-pg16

Output:

Updating Subscription Management repositories.

Last metadata expiration check: 0:01:47 ago on Fri 12 Apr 2024 07:01:40 PM IST.

Error:

Problem: cannot install the best candidate for the job

  - nothing provides libmemcached.so.11()(64bit) needed by pgpool-II-pg16-4.5.1-1pgdg.rhel9.x86_64 from pgpool45

(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

Any help towards this will be greatly appreciated

Malyacko (talkcontribs)

@Manukapoor1978 Welcome to the MediaWiki support desk. How is your question related to MediaWiki? For RHEL package dependency issues you need to ask in a RHEL support forum.

Reply to "Unable to install pgpool 4.5.1"

1.41.x Docker: "There is currently no text in this page." (Solved)

1
92.70.74.171 (talkcontribs)

Using Docker. After upgrading from 1.40.3 to 1.41.0 (or 1.41.1), all the Wiki content was "gone". In a container with 1.40.3 again, everything was back.

Solved: In 1.41.0 after running "php maintenance/update.php" the content is shown again.

Reply to "1.41.x Docker: "There is currently no text in this page." (Solved)"

Align speciesbox on the right

2
89.108.148.53 (talkcontribs)

I have created a template Template:Speciesbox (like on Wikipedia) and I want to align it on the right…

Any idea how I can do that? If it needs setting the CSS, what code I have to add in the Common.css page?

Also, I want the same Speciesbox (but this time on mobile) to be aligned in the center and fill the screen side-to-side, what code do I have to add in Mobile.css?

Bawolff (talkcontribs)

wrap template in <div style="float:right"> ... template here ... </div>

Reply to "Align speciesbox on the right"

What is mwstore:// ?

4
Kjecl (talkcontribs)

When I upload new files to our wiki, the thumbnails are not created. Turning on $wgDebugLogFile gives me messages like:

TransformationalImageHandler::doTransform: creating 500x277 thumbnail at mwstore://local-backend/local-thumb/e/e9/Eclypse_Sales_Graphic.jpg/500px-Eclypse_Sales_Graphic.jpg using scaler im

or:

[FileOperation] FileBackendStore::ingestFreshFileStats: File mwstore://local-backend/local-public/1/14/Favicon1.jpg does not exist

Note that thumbnails created prior to applying 1.39.5 still work fine. So apparently the location where new thumbnails would be created has changed with 1.39.5. Because where mwstore points changed? How can I find out where mediawiki is trying to create files?

This post was hidden by Ciencia Al Poder (history)
Ciencia Al Poder (talkcontribs)

local-backend should refer to $wgLocalFileRepo, which gets automatically populated from other variables. local-thumb would be "$wgUploadDirectory/thumb" and local-public would be just $wgUploadDirectory.

Defining $wgLocalFileRepo yourself and setting pathDisclosureProtection to 'simple' should disclose the full paths.

Kjecl (talkcontribs)

Thank you so much for trying to help. I probably don't understand.

So mwstore://local-backend/local-thumb would translate to:

mwstore://$wgLocalFileRepo/$wgUploadDirectory/thumb ?

When I force pathDisclosureProtection to 'none' -- here's the section from my modified FileRepo.php:

private function getErrorCleanupFunction() {

       $this->pathDisclosureProtection = 'none';

       switch ( $this->pathDisclosureProtection ) {

               case 'none':

               case 'simple': // b/c

                       $callback = [ $this, 'passThrough' ];

                       break;

               default: // 'paranoid'

                       $callback = [ $this, 'paranoidClean' ];

       }

       return $callback;

}

I am still getting error messages like:

File::transform: Doing stat for mwstore://local-backend/local-thumb/e/e9/Eclypse_Sales_Graphic.jpg/500px-Eclypse_Sales_Graphic.jpg

Apparently my search-fu is weak, but I have tried to find an explanation of the meaning of mwstore:/ and have come up empty.

I appreciate that the developers get to make the rules. But, I confess that I am baffled by the thinking that obscuring the filenames in a debug log file that is only created if enabled in a configuration file controlled by root is useful. Several of the problems I have encountered would have been solved much more quickly if the debug logfile used actual system file paths for reporting. Or even if there was an obvious way to translate "mwstore://local-backend/local-thumb/" to a system file path.

The good news is that I have solved the problem that brought me to ask about mwstore in the first place.

Thanks and regards,

Reply to "What is mwstore:// ?"

Problem with Mustache_engine

3
Dazwarier99 (talkcontribs)

I am getting an error that states class mustache engine not found. AFAIK I am the first person on the planet this has happened to

Bawolff (talkcontribs)

You could try running composer update see if that helps.

Dazwarier99 (talkcontribs)

i fixed that problem but now my shorturl goes to /whtml instead of /w

Reply to "Problem with Mustache_engine"

error installing citoid.

2
Frigariione (talkcontribs)

unfortunately, it is not possible to install the project due to an error when installing its dependencies

npm ERR! Error while executing:

npm ERR! /usr/local/bin/git ls-remote -h -t ssh://git@github.com/zotero/wicked-good-xpath.git

npm ERR!

npm ERR! git@github.com: Permission denied (publickey).

npm ERR! fatal: Couldn't read from an external repository.

npm ERR!

npm ERR! Make sure that you have the necessary access rights

npm ERR! and the repository exists.

npm ERR!

npm ERR! exited with error code: 128

TheDJ (talkcontribs)

You probably don't have ssh configured for your github account and so github won't allow you to download the sources via that method.

Reply to "error installing citoid."