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

  • SEARCH
  • Home
  • 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 8077413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:28:07+00:00 2026-06-05T15:28:07+00:00

I’m running into trouble accessing global variables when I make an AJAX call to

  • 0

I’m running into trouble accessing global variables when I make an AJAX call to a php function in the MediaWiki framework.

My jQuery AJAX call looks like this:

jQuery.ajax({
    url: 'GeneralFunctions.php',
    type: 'GET',
    dataType: 'json',
    data: {
        text: anchorText
    },
    success: function (data) {
        alert("data: " + data);
    }
});

My GeneralFunctions.php file looks like this:

<?php
if (isset($_GET['text'])) {
    jsonInlineParse((string) $_GET['text']);
}
function jsonInlineParse($wikiText)
{
    global $wgOut;
    $return = $wgOut->parseInline($wikiText); //fails here
    echo json_encode($return);
}
?>

When I run the jQuery call through a click event I get as far as the parseInline() function. The global variable is never defined in the scope and I get the error:

Fatal error: Call to a member function parseInline() on a non-object in /path/to/file/GeneralFunctions.php on line 54

I’m not sure how to make the parse call and define the global variable when the AJAX call is made?

UPDATE

$wgOut is the OutputPage object associated with MediaWiki. It holds all the HTML of the page and is used throughout the MediaWiki framework to add content to a page or article. It is used on the server side to create customized output for wiki articles. I use it to create forms or add HTML on many of our wikis.

More info here: http://www.mediawiki.org/wiki/Manual:$wgOut

UPDATE 2

@Juhana I changed my function to look like this which results in the same error as before. Each echo outputs “NULL”.

<?php
function jsonInlineParse($wikiText)
{
    include_once '/path/to/file/includes/OutputPage.php';
    include_once '/path/to/file/includes/parser/Parser.php';
    echo var_dump($wgOut);
    global $wgOut;
    echo var_dump($wgOut);

    $return = $wgOut->parseInline($wikiText);
    echo $return;
    echo json_encode($return);
}
?>
  • 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-05T15:28:08+00:00Added an answer on June 5, 2026 at 3:28 pm

    I took a different approach after running into global variable problems. I changed the AJAX call I was making and the code below works very well for me. I’m using the editable jquery table you can find here.

    PHP

    function ajax_parse(){
            global $wgRequest;
            if($wgRequest->wasPosted()){
                $text = $wgRequest->getVal("text");
                wfDebug("Recieving::::".$text);
                if(!strpos($text, "href")){
                    $text = myInlineParse($text);
                    $text = str_replace("<pre>", "", $text);
                    $text = str_replace("</pre>", "", $text);
                }
                wfDebug("Returning::::".$text);
                echo $text;
            }
            exit;
        }
    
    function myInlineParse( $wikiText ) {
        global $wgOut;
        return $wgOut->parseInline( $wikiText );
    }
    

    JavaScript

    // inject wikitext after hitting save
    function postSave(o) {
    var response = new Array("");
    for(var i=0;i<o.row.length;i++){
         new Ajax.Request(wgScript +'/Special:EditClass/ajax_parse',
        {
            asynchronous: false,
            parameters: {'text': o.row[i].innerHTML},
            onSuccess: function(text){
                response.push(text.responseText);
            }
        }            
        );
    }
    
    return response;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the

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.