Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8963199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:18:25+00:00 2026-06-15T16:18:25+00:00

I am trying to work on user input such as foo wikt:foo Bar#hi there

  • 0

I am trying to work on user input such as

  • foo
  • wikt:foo
  • Bar#hi there

to obtain a https link for the input, such as

  • https://en.wikipedia.org/wiki/foo
  • https://en.wiktionary.org/wiki/foo
  • https://en.wikipedia.org/wiki/Bar#hi_there

I am trying to do this in a least manual, most clean possible way, so I can upload my script somewhere and show it to people without being ashamed of its low quality. This means:

  • If I obtain an http link instead of https I would rather not hardcode a s/^http/^https/ substitution.
  • If I obtain an incomplete link I would rather not use regex to add missing things to it.

So far I have found two solutions but each of them has flaws.

Parse query

Run parse query on {{canonicalurl:user_input_here}} using canonicalurl magic word. It gives only http, not https links however.

#!/usr/bin/perl
use strict;
use warnings;
use MediaWiki::API;
use Data::Dumper;

my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = 'https://en.wikipedia.org/w/api.php';

my $info_ref = $mw->api ( {
    action      => 'parse',
    prop        => 'text',
    text        => '{{canonicalurl:Hello}}',
} ) or die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
my $html = $info_ref->{parse}{text}{'*'};
print Dumper $html;

Info query

Use info query. However it does not work for sections, i.e. “Foo#bar” input will get output linking to “Foo”.

#!/usr/bin/perl
use strict;
use warnings;
use MediaWiki::API;

my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = 'https://en.wikipedia.org/w/api.php';

sub get_url_by_title(){
  my $title = shift;

  my $info_ref = $mw->api ( {
    action      => 'query',
    prop        => 'info',
    inprop      => 'url',
    iwurl       => 1,
    titles     => $title,
  } ) or die $mw->{error}->{code} . ': ' . $mw->{error}->{details};

    if (exists $info_ref->{query}{pages}){
      return (values $info_ref->{query}{pages})[0]{'fullurl'};
    }
    elsif (exists $info_ref->{query}{interwiki}){
      return (values  $info_ref->{query}{interwiki})[0]{'url'};
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:18:26+00:00Added an answer on June 15, 2026 at 4:18 pm

    Canonical url refers to the type of url that is canonical for the wiki. In Wikimedia’s current config this is http. (I wouldn’t be surprised if that changes one day). What you can look at is {{fullurl:Pagename}}. It will respond with a url starting with “//” if both http and https are valid. Otherwise it will respond with a normal url.

    The info query (your second method) may be better since it does not invoke the parser (which is a little less work for the servers, although really that doesn’t matter). Its always possible to just plop the target (or whatever the part after the # sign is called no a days) on to the end of the url afterwards.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still learning how to work within classes. I'm trying to get user input
I'm trying to create User Control which will work like a rich button. It's
I am a noob Perl user trying to get my work done ASAP so
I can't get this to work. I am trying to prevent a user to
I've been trying to get user input from a Javascript prompt into a PHP
As per an user-request I'm trying to make my (PhoneGap) webapp work better with
I am trying to build a console application that takes user input. I was
I'm trying to have the user input a block of text to the console
I'm trying to write a regular expression that will validate that user input is
I'm trying to create a consent form, and having the user input their name.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.