Project:Support desk

Jump to navigation Jump to search

About this board

Welcome to MediaWiki.org's Support desk, where you can ask MediaWiki questions!

There are also other places where to ask :

Before you post

Post a new question

  1. To help us answer your questions, please always indicate which versions you are using (reported by your wiki's Special:Version page):
    • MediaWiki
    • PHP
    • Database
  2. Please include the URL of your wiki unless you absolutely can't. It's often a lot easier for us to identify the source of the problem if we can look for ourselves.
  3. To start a new thread, click "Start a new topic".
Previous page history was archived for backup purposes at Project:Support_desk/old on 2015-07-30.
Other languages: English  العربية čeština Esperanto français 日本語 中文
Allbiomed (talkcontribs)

I am having a problem with my Module:TNT where I am getting an error


https://www.allbiomed.org/Module:TNT


Lua error at line 157: attempt to index field 'data' (a nil value).


This is in turn causing problems importing templates. I thought it had something to do with the JsonConfig, which I have installed, but it didn't change anything.


I am running

Product Version
MediaWiki 1.33.1
PHP 7.2.21 (cgi-fcgi)
MySQL 5.7.23-percona-sure1-log
ICU 57.1
Lua 5.1.5

I appreciate the help.

Bawolff (talkcontribs)
Allbiomed (talkcontribs)

Yeah, I saw that topic as well. It doesn't look like he figured it out either.

Reply to "Module:TNT error"

Add a page to the local mediawiki using API

1
SumanGadhawal (talkcontribs)

Hi all,

I am new here and currently I am trying to generate login token for my local url http://localhost/mediawiki/index.php/Main_Page but i am getting response 404


here is my code


import requests
S = requests.Session()
URL = "http://localhost/mediawiki/index.php/Main_Page"
# Retrieve login token first
PARAMS_0 = {
    'action':"query",
    'meta':"tokens",
    'type':"login",
    'format':"json"
}
R = S.get(url=URL, params=PARAMS_0)
print(R)
DATA = R.json()
LOGIN_TOKEN = DATA['query']['tokens']['logintoken']
print('data',DATA)
Reply to "Add a page to the local mediawiki using API"
Buman (talkcontribs)

MediaWiki 1.33.1

PHP 7.3.11 (cgi-fcgi)

MariaDB 10.3.17-MariaDB-1:10.3.17+maria~bionic

Wiki URL: http://www.seigmen.no/

Wiki Languate: Norwegian


Updating from 1.25.3 to 1.33.1 there have apparently been som encoding issuses, where pages having titles with non ASCII characters simply won't show. I've managed to locate pages being orphaned by this problem: http://www.seigmen.no/index.php?title=Spesial%3AForeldrel%C3%B8se_sider&limit=250&offset=0

Searching for a solution I came to the conlusion that the running of rebuildall.php / refreshLinks.php was needed. Unfortunately I can't get refreshLinks.php to work

> php refreshLinks.php

Refreshing redirects table.
Starting from page_id 1 of 915.
100
200
300
400
500
600
700
800
900
Refreshing links tables.
Starting from page_id 1 of 915.
[ad957bb037931af4f1c02f5b] [no req]   Error from line 3676 of ../httpd.www/includes/page/WikiPage.php: Call to a member function refreshCountsIfEmpty() on bool
Backtrace:
#0 ../httpd.www/includes/deferred/MWCallableUpdate.php(34): WikiPage->{closure}()
#1 ../httpd.www/includes/deferred/DeferredUpdates.php(274): MWCallableUpdate->doUpdate()
#2 ../httpd.www/includes/deferred/DeferredUpdates.php(231): DeferredUpdates::runUpdate(MWCallableUpdate, Wikimedia\Rdbms\LBFactorySimple, string, integer)
#3 ../httpd.www/includes/deferred/DeferredUpdates.php(143): DeferredUpdates::execute(array, string, integer)
#4 ../httpd.www/includes/deferred/DeferredUpdates.php(313): DeferredUpdates::doUpdates(string)
#5 ../httpd.www/includes/deferred/DeferredUpdates.php(104): DeferredUpdates::tryOpportunisticExecute(string)
#6 ../httpd.www/includes/Storage/DerivedPageDataUpdater.php(1601): DeferredUpdates::addUpdate(LinksUpdate, integer)
#7 ../httpd.www/includes/page/WikiPage.php(2134): MediaWiki\Storage\DerivedPageDataUpdater->doSecondaryDataUpdates(array)
#8 ../httpd.www/maintenance/refreshLinks.php(275): WikiPage->doSecondaryDataUpdates(array)
#9 ../httpd.www/maintenance/refreshLinks.php(198): RefreshLinks::fixLinksFromArticle(integer, boolean)
#10 ../httpd.www/maintenance/refreshLinks.php(83): RefreshLinks->doRefreshLinks(integer, boolean, string, boolean, boolean)
#11 ../httpd.www/maintenance/doMaintenance.php(96): RefreshLinks->execute()
#12 ../httpd.www/maintenance/refreshLinks.php(491): require_once(string)
#13 {main}

Any ideas?

Osnard (talkcontribs)

You are right. This is probably some encoding issue. Can you give insight on what is set in your wikis configuration for $wgDBTableOptions and what is actually set in your database (e.g. run SHOW CREATE TABLE page;)?

You might also try to truncate the "secondary links" tables categorylinks, externallinks and pagelinks. Run php maintenance/rebuildall.php afterwards. Make sure you have a backup of your database.

Buman (talkcontribs)

Truncating categorylinks, externallinks and pagelinks did the trick. I was now able to run php maintenance/rebuildall.php

But I'm still facing issues with dead links / pages with non-ASCII not showing up.


Regardring....

LocalSettings.php

# MySQL table options to use during installation or update
$wgDBTableOptions   = "ENGINE=InnoDB, DEFAULT CHARSET=binary";

Database

Since my post here, I have tried to change the encoding on the "page" table from latin1 to utf8mb4 (It's named "wikipage" in my database); Currently it looks like this:

CREATE TABLE `wikipage` ( `page_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `page_namespace` int(11) NOT NULL,
 `page_title` varbinary(255) NOT NULL,
 `page_restrictions` tinyblob NOT NULL,
 `page_is_redirect` tinyint(3) unsigned NOT NULL DEFAULT 0,
 `page_is_new` tinyint(3) unsigned NOT NULL DEFAULT 0,
 `page_random` double unsigned NOT NULL,
 `page_touched` binary(14) NOT NULL DEFAULT '\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
 `page_latest` int(10) unsigned NOT NULL,
 `page_len` int(10) unsigned NOT NULL,
 `page_content_model` varbinary(32) DEFAULT NULL,
 `page_links_updated` varbinary(14) DEFAULT NULL,
 `page_lang` varbinary(35) DEFAULT NULL,
 PRIMARY KEY (`page_id`),
 UNIQUE KEY `name_title` (`page_namespace`,`page_title`),
 KEY `page_random` (`page_random`),
 KEY `page_len` (`page_len`),
 KEY `page_redirect_namespace_len` (`page_is_redirect`,`page_namespace`,`page_len`)
 ENGINE=MyISAM AUTO_INCREMENT=916 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

I tried changing back to latin1 and running php maintenance/rebuildall.php a second time. But that didn't make any difference.

Kyr (talkcontribs)

I have exactly the same problem.

Running

PHP 7.0.33-0+deb9u6 (apache2handler)

MariaDB 10.1.41-MariaDB-0+deb9u1

while upgrading from Mediawiki 1.32.1 to 1.33.1.

After upgrading pages having titles with non ASCII characters simply won't show.


I'd executed refreshLinks.php and got exaxtly the same error.

[no req] Error from line 3676 of ../httpd.www/includes/page/WikiPage.php: Call to a member function refreshCountsIfEmpty() on boolean.


$wgDBTableOptions = "ENGINE=InnoDB";

Maybe a problem with the old

$wgDBMysql5 = true;

which is now removed?

Buman (talkcontribs)

Kyr, tid you try (SQL)

TRUNCATE TABLE categorylinks;
TRUNCATE TABLE externallinks;
TRUNCATE TABLE pagelinks;

And then running php maintenance/rebuildall.php ? That should at least eliminate the problem with

Error from line 3676 of ../httpd.www/includes/page/WikiPage.php: Call to a member function refreshCountsIfEmpty() on boolean.
Kyr (talkcontribs)

No, I did not truncate the tables. First I had to fight that character encoding problem. When installing MW a long time ago it set's $wgDBMysl5 = true; in the Localsettings.php. Now this is removed and that breaks my wiki. After that I'll check that rebuildall.php - problem. In my opinion it should be solved as well after solving the character encoding problem.

But many thanks for your answer.

Reply to "Error running refreshLinks.php"

Image upload : no thumbnail generated, error code =-1

5
Amagnien2 (talkcontribs)

I am using the latest version of Mediawiki (1.33.1). Standard installation, PHP 7.3, no fancy extensions. Computer is a PC, Windows 10, latest version.

On my first attempt to upload a small jpg (less than 1 MB), I got the error message - translated from French - saying "Error when creating thumbnail: Error code = -1".

Image itself is usable, apart from options: setting limits to width and height does not seem to work at all.

I have looked at recent posts regarding such issue and could draw no conclusions about how to correct those glitches:

- no thumbnail

- size limits not working (I'll open a topic later on about this one)

thanks for any hint

Bawolff (talkcontribs)

What are your image related configs in LocalSettings.php ?

I think the most likely cause is that either image magick (convert.exe) is not installed, or MediaWiki cannot locate it. MediaWiki normally uses that program to create thumbnails (although if the installer cannot find it, and the gd php extension is installed, sometimes the installer will configure to use that instead

Amagnien2 (talkcontribs)

You got it - ImageMagick was not installed. Now it is (last available version, static), and I have successfully tested it, using the command line.

I also updated localsettings.php with the following lines:

________________________

## To enable image uploads, make sure the 'images' directory

## is writable, then set this to true:

$wgEnableUploads = true;

$wgUseImageMagick = true;

$wgImageMagickConvertCommand = "C:\Program Files\ImageMagick-7.0.9-Q16\magick.exe";

________________________

Indeed, there is no convert.exe file any more; "magick" is now the proper command.

Still, I got in trouble, as any attempt to create a thumbnail on file import will result in the following report :

Erreur lors de la création de la miniature : /bin/bash: C:\Program Files\ImageMagick-7.0.9-Q16\magick.exe: command not found Error code: -1

(and the magick.exe file is definitely there; by the way, removing ".exe" from the path does not remove the error, which is hardly surprizing)


Maybe I should try an older version still using convert.exe ? (although I doubt it would solve anything)

Bawolff (talkcontribs)

Its weird that the error message includes "/bin/bash" in it. That is normally a unix thing. I wonder if somehow MediaWiki is not detecting you are on windows, and running the unix command instead.

Just to clarify, you are not running MediaWiki inside cygwin, or linux subsystem for windows, right?

Amagnien2 (talkcontribs)

Thanks for your replies. No, I am running MW on Windows 10. I have never used any Linux subsystem for Windows on this machine.

No trace of "Windows" or "Linux" in localsettings.php either. I could see some "bash" appearing in the files (bash_profile, bashrc) generated by my ISP when setting up the web server.

Reply to "Image upload : no thumbnail generated, error code =-1"

The sidebar automatically changes back to default on some wiki page

1
3Qvery (talkcontribs)

Hello, I am meeting trouble when I use mediawiki.

I have changed mediawiki:sidebar at first, and it worked well.

Then I edited LocalSettings.php , I changed the language.

$wgLanguageCode = "zh";

"zh" means Chinese, and it have many variant languages, such as Simplified Chinese, Traditional Chinese and so on. It can be changed at the top tab of webpage.

Then I found that, the sidebar of some of my wiki page changed back to default. But some wiki page still works well.

I found, if the wiki page have interwiki link (such as [[wikipedia:homepage]], [[en:homepage]]), the sidebar of this page will change back to default. Otherwise, the sidebar will be my custom configuration. Else, if I change the language back to "zh-hans-cn", it works well again.

So I want to ask how to solve this problem? I want to keep my language setting "zh", because I can turn it to simplified Chinese or traditional Chinese quickly, and I also want to change my sidebar.

Reply to "The sidebar automatically changes back to default on some wiki page"
Tviv54 (talkcontribs)

I have installed mediawiki 1.33.1 and working fine without LDAP. I try to do login using LDAP authentication. I have installed Auth_remoteuser, LDAPAuthentication2, LDAPAuthorization, LDAPProvider, LDAPUserInfo and PluggableAuth.   Please help me to do the configuration and autoauth using LDAP.


Here are the my Virtual host configuration details

<VirtualHost *:9004>
    ServerName localhost
    ServerAlias localhost
    DocumentRoot "${INSTALL_DIR}/www/mediawiki-1-33-1" 
    <Directory "${INSTALL_DIR}/www/mediawiki-1-33-1">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    AuthName "My Intranet"
    AuthType SSPI 
    SSPIAuth On 
    SSPIAuthoritative On
    SSPIDomain MyDomainName
    SSPIOmitDomain On
    SSPIOfferBasic On
    #SSPIBasicPreferred On
    #SSPIofferSSPI On
    require valid-user
    require user "NT AUTHORITY\ANONYMOUS LOGON" denied 
   </Directory>
</VirtualHost>


Here are the my Localsettings details

       $wgCookieSecure = false; 
       wfLoadExtensions([  'PluggableAuth',
         'Auth_remoteuser',
         'LDAPProvider',
         'LDAPAuthentication2',
         'LDAPAuthorization',
         'LDAPUserInfo'
 ]);
  $LDAPAuthorizationAutoAuthRemoteUserStringParser = 'username-at-domain';
  $LDAPAuthentication2UsernameNormalizer = 'strtolower';
  $LDAPAuthentication2AllowLocalLogin = false;
  $wgAuthRemoteuserAllowUserSwitch = true;
  $wgPluggableAuth_EnableLocalLogin = false;
 $wgAuthRemoteuserUserName = function() {
 $user = '';
 if( isset( $_SERVER[ 'REMOTE_USER' ] ) ) {
    echo $user = strtolower( $_SERVER[ 'REMOTE_USER' ] ); // Returns my remote user name
 }
 return $user;
};
$LDAPProviderDomainConfigProvider = function() {
$config = [
 'company.local' => [
   'connection' => [
      "server" => "coo.tc.net",
      "options" => [
            "LDAP_OPT_DEREF" => 1
      ],
      "basedn" => "o=Company",
      "groupbasedn" => "o=Company",
      "userbasedn" => "o=Company",
      "searchattribute" => "uid",
      "usernameattribute" => "uid",
      "realnameattribute" => "fullname",
      "emailattribute" => "mail",
      "grouprequest" => "MediaWiki\\Extension\\LDAPProvider\\UserGroupsRequest\\GroupMember::factory"
  ],
  'authorization' => [
     'rules' => [
        'groups' => [
           'required' => [
              'cn=WikiAccess,ou=Groups,o=Company'
            ]
         ]
      ]
  ],
 'userinfo' => [
        'attributes-map' => [
           'email' => 'mail',
           'realname' => 'fullname'
        ]
  ]
 ]
];
return new \MediaWiki\Extension\LDAPProvider\DomainConfigProvider\InlinePHPArray( $config );
};
Kking01 (talkcontribs)

Were you able to get this to work? I am having the same issue with the config. I was able to get it to return my full name from the table, but still wouldn't connect to Active Directory to login.

MarkAHershberger (talkcontribs)

@Kking01 what have you tried? Does your single sign on work outside of MW?

@Tviv54 How does your current configuration behave?

Kking01 (talkcontribs)

@MarkAHershberger Yes All single sign on works. We have quite a few other things that use LDAP and all work fine. This is an older instance of Mediawiki that I have upgraded through the years. I just pushed it from 1.29 to 1.33, and all plugins functioned correctly except for the LdapAuthentication. This is why I switched to use the LdapHub migration. Way more involved as it uses 6 plugins instead of just the one. I just maybe doing something wrong.

MarkAHershberger (talkcontribs)

We do need to improve the documentation, but it isn't that much more complicated. I see you already asked for help here. Let's continue there.

Tviv54 (talkcontribs)

$_SERVER[ 'REMOTE_USER' ] - Return my name from the Active directory.

My current configuration is not working properly. I tried with my windows user credential but Login attempt failed and returns "There seems to be a problem with your login session; this action has been canceled as a precaution against session hijacking. Please resubmit the form."


MarkAHershberger (talkcontribs)
$_SERVER[ 'REMOTE_USER' ] - Return my name from the Active directory.
Good.

Your current configuration, like @Kking01's is using both Auth_remoteuser and LDAPAuthentication2. Since REMOTE_USER is being set, remove LDAPAuthentication2.

Remove the snippet for setting $wgAuthRemoteuserUserName and just use its default.

Tviv54 (talkcontribs)

Would you please share the configuration details

MarkAHershberger (talkcontribs)

Based on my comments and your configuration, here is what I would do:

$wgCookieSecure = false; 
wfLoadExtensions([
         'PluggableAuth',
         'Auth_remoteuser',
         'LDAPProvider',
         'LDAPAuthorization',
         'LDAPUserInfo'
]);
$LDAPAuthorizationAutoAuthRemoteUserStringParser = 'username-at-domain';
$LDAPAuthentication2UsernameNormalizer = 'strtolower';
$LDAPAuthentication2AllowLocalLogin = false;
$wgAuthRemoteuserAllowUserSwitch = true;
$wgPluggableAuth_EnableLocalLogin = false;

$LDAPProviderDomainConfigProvider = function() {
$config = [
 'company.local' => [
   'connection' => [
      "server" => "corp.tcc.inet",
      "options" => [
            "LDAP_OPT_DEREF" => 1
      ],
      "basedn" => "o=Company",
      "groupbasedn" => "o=Company",
      "userbasedn" => "o=Company",
      "searchattribute" => "uid",
      "usernameattribute" => "uid",
      "realnameattribute" => "fullname",
      "emailattribute" => "mail",
      "grouprequest" => "MediaWiki\\Extension\\LDAPProvider\\UserGroupsRequest\\GroupMember::factory"
  ],
  'authorization' => [
     'rules' => [
        'groups' => [
           'required' => [
              'cn=WikiAccess,ou=Groups,o=Company'
            ]
         ]
      ]
  ],
 'userinfo' => [
        'attributes-map' => [
           'email' => 'mail',
           'realname' => 'fullname'
        ]
  ]
 ]
];
return new \MediaWiki\Extension\LDAPProvider\DomainConfigProvider\InlinePHPArray( $config );
};
Tviv54 (talkcontribs)

Thanks MArk but i am getting Notice error when i click login link Notice: Undefined index: wgPluggableAuth_Class in D:\wamp64\www\mediawiki-1-33-1\extensions\PluggableAuth\includes\PluggableAuth.php on line 40"

Reply to "Auto authentication using LDAP"

Category is displayed, but not inserted in the text

3
Max.megavolt (talkcontribs)

Hello!

I guess i made somehow a mistake with the masseditregex extension. I tried to insert a category in every page, but no category was inserted (in the wikitext was nothing), but on the bottom line the category is displayed as wanted in red.

I see no way to remove it without editing the mysql database, or is there another way?

If only editing the database is the solution. How could i remove the category safely?

Example Page: https://testwiki.2ix.de/index.php?title=en:201606_test

Category:Unadapted_templates

Software Version
MediaWiki 1.31.5
PHP 7.3.9 (fpm-fcgi)
MySQL 5.6.41-84.1-log
ICU 55.1
Lua 5.1.5


Anyone have an idea?

Thanks

Max.megavolt (talkcontribs)

I guess I made it. Here the solution:

  1. Set up a new mediawiki with the same extensions, skins and Localconfig.php.
  2. Create a dump.xml from the old mediawiki.
  3. Delete the unwanted categories with sed 's/\[\[Category:Unadapted templates\]\]//g' from the created dump.
  4. Import the dump to the new mysql database.

(still ongoing right now, but seems to look nice so far)

--Update It worked.

Bawolff (talkcontribs)

you probably just needed to make a single edit to LocalSettings.php (would force cache to be reset).

If that didnt work, the script refreshLinks.php would have probably fixed it (although first try running runJobs.php to make sure all jobs are completed, as that may also fix the issue)


[Edit: you claim that the category is not in wikitext, but later use sed to remove it from a wikitext dump. Both of these things cannot be true... the answer will of course vary depending on if the category really is in the wikitext]

Reply to "Category is displayed, but not inserted in the text"

Parser Output Not Properly formatted in CSS

5
162.245.77.13 (talkcontribs)

I'm having an issue with the parser output for TemplateStyles.

The parser doesn't add spaces between the mw-parser-output class and my CSS classes. This messes up the formatting of my templates. I tried adding spaces manually in front of my classes but that doesn't seem to help. Here's an example of the output:

.mw-parser-output .treeview ul{padding:0;margin:0}.mw-parser-output .treeview li{padding:0;margin:0;list-style-type:none;list-style-image:none}.mw-parser-output .treeview li li{background:url("//upload.wikimedia.org/wikipedia/commons/f/f2/Treeview-grey-line.png")no-repeat 0 -2981px;padding-left:21px;text-indent:0.3em}.mw-parser-output .treeview li li:last-child{background-position:0 -5971px}.mw-parser-output .treeview li.emptyline>ul>.mw-empty-elt:first-child+.emptyline,.mw-parser-output .treeview li.emptyline>ul>li:first-child{background-position:0 9px}


Any suggestions on a fix?

162.245.77.13 (talkcontribs)

Apologies. The pasted code doesn't seem to reflect the point I was trying to make.

There isn't actually a space between .mw-parser-output and .treeview when I inspect the page.

Bawolff (talkcontribs)

can you link to an example on your wiki?

206.126.121.37 (talkcontribs)

I operate a private wiki so unfortunately I can't provide a direct link. Would there be any other info I can provide that might be useful?

Bawolff (talkcontribs)

Just to ask the silly question - you're sure there really isn't a space there in the inspect page view, and its not just some weird font thing where the space is really small or something like that?

Reply to "Parser Output Not Properly formatted in CSS"

How can I install and enable LanguageConverter in Mediawiki1.33.0

8
TheEndOfKeyHighSchool (talkcontribs)
Malyacko (talkcontribs)

Hi, could you be more specific? What is the name of "the related .php file"?

TheEndOfKeyHighSchool (talkcontribs)

There is no /language folder in my Mediawiki software.Can I just add this folder to the Mediawiki's base path? If not, what should I do?

Bawolff (talkcontribs)

respectfully, you should stop looking at Mediawiki source files. All your posts are basically misinterpreting how mediawiki works. There is basically no reason you would have to modify any mediawiki includes files (other than adding things to the /extensions) If you didnt have the language directory nothing in mediawiki would work.


LanguageConverter is included with mediawiki by default. There are only a few languages it supports, and it will only be enabled if $wgLanguageCode is set to one of these languages (like zh or sr. If $wgUsePigLatinVariant also en)

What is your $wgLanguageCode set to, and what is the value of any other language config

TheEndOfKeyHighSchool (talkcontribs)

I have found the /language folder,but the LanguageConverter.php isnot available yet.How can I enable this class?

Malyacko (talkcontribs)

By being clearer. :) Nobody knows what "isnot available yet" means, nobody knows steps to reproduce, nobody knows which output you get where after which exact steps...

TheEndOfKeyHighSchool (talkcontribs)

I'm sorry for incomplete statements.

I add script below to my /LocalSettings.php:

$wgUsePigLatinVariant = true;

but the toolbar named 大陆简体 or Igpay Latin is only shown when navigating a page in namespace Module , and the translating flag such as

-{zh-cn:代码; zh-tw:原始碼;}-

is not translated and remain as it is in the source code.

Bawolff (talkcontribs)

That probably means that $wgLanguageCode is set to something that doesn't support language variants (presumably module is hardcoded english since it contains lua and not written text). What do you have $wgLanguageCode set to? If you want to use Chinese, it needs to be set to 'zh' (And *not* something like 'zh-Hans')

Reply to "How can I install and enable LanguageConverter in Mediawiki1.33.0"

WikiEditor button that inserts a string returned from an API call

6
FrugalTPH (talkcontribs)

I'm trying to add a button to wikieditor that executes an API call and places the returned string at the cursor.

I can add buttons fine using the below code example, but I'm struggling to replace "XXXXX" in with the result of my API call:

$.ajax({
    dataType: 'script',
    cache: true,
    url: 'https://meta.wikimedia.org/w/index.php?title=User:Krinkle/Scripts/InsertWikiEditorButton.js&action=raw&ctype=text/javascript'
    
}).then(function () {
    krInsertWikiEditorButton({
        id: 'mw-apiCall1',
        icon: '//upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Gnome-face-monkey.svg/22px-Gnome-face-monkey.svg.png',
        label: 'Api Call 1',
        sampleText: 'XXXXX'
    });
});

The API call I'm looking to make is: /api.php?action=idprovider-increment

And its return value is of the format. { "id": "1" }

Anyone got any pointers as to how I can do this?

FrugalTPH (talkcontribs)

(I can't get my head round how to post code here without it coming out in an unreadable format like above). :/

Bawolff (talkcontribs)

You would probably have to do something roughly like:

$.ajax({
    dataType: 'script',
    cache: true,
    url: 'https://meta.wikimedia.org/w/index.php?title=User:Krinkle/Scripts/InsertWikiEditorButton.js&action=raw&ctype=text/javascript'
    }).then(function () {
    krInsertWikiEditorButton({
        id: 'mw-apiCall1',
        icon: '//upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Gnome-face-monkey.svg/22px-Gnome-face-monkey.svg.png',
        label: 'Api Call 1',
        callback: function () { $.get( '/w/api.php?action=idprovider-increment&format=json' ).then( function( res ) { $('#wpTextbox1').textSelection('encapsulateSelection', { peri: JSON.stringify(res) } ); } ) }
    });
 });
FrugalTPH (talkcontribs)

Excellent, got this working now using...

/**
 * Extra buttons in toolbar
 * @stats [[File:Krinkle_InsertWikiEditorButton.js]]
 */
$.ajax({
    dataType: 'script',
    cache: true,
    url: 'https://meta.wikimedia.org/w/index.php?title=User:Krinkle/Scripts/InsertWikiEditorButton.js&action=raw&ctype=text/javascript'
    }).then(function () {
    krInsertWikiEditorButton({
        id: 'mw-apiCall1',
        icon: '//upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Gnome-face-monkey.svg/22px-Gnome-face-monkey.svg.png',
        label: 'Api Call 1',
        callback: function () { $.get( 'api.php?action=idprovider-increment&prefix=TEST&padding=2&skipUniqueTest=true&format=json' ).then( function( res ) { $('#wpTextbox1').textSelection('encapsulateSelection', { peri: res.id } ); } ) }
    });
 });
FrugalTPH (talkcontribs)

@Bawolff Any idea how I would stop the inserted text being selected right after its been inserted. It would be better if the cursor just sat at the end of the inserted string, as it would be too easy to accidentally type over the inserted unique ID the way its going in at the moment.

Bawolff (talkcontribs)

You have to add selectPeri: false to the object returned by the callback.

e.g. callback: function () { $.get( 'api.php?action=idprovider-increment&prefix=TEST&padding=2&skipUniqueTest=true&format=json' ).then( function( res ) { $('#wpTextbox1').textSelection('encapsulateSelection', { peri: res.id, selectPeri: false } ); } ) }

Reply to "WikiEditor button that inserts a string returned from an API call"