Topic on Project:Support desk

Uncaught TypeError: url.indexOf is not a function

3
Gaon12 (talkcontribs)

When you go to my MediaWiki site (https://www.gaonwiki.com), I get this error in the console.

Uncaught TypeError: url.indexOf is not a function

    at jQuery.fn.load (load.php?lang=ko&modules=ext.EnhanceMarkup.scripts%7Cjquery%2Coojs-ui-core%2Coojs-ui-widgets%7Cjquery.ui%7Coojs-ui.styles.icons-editing-advanced&skin=liberty&version=8mj0p:846:335)

    at <anonymous>:10:577

    at domEval (load.php?lang=ko&modules=startup&only=scripts&raw=1&skin=liberty:10:692)

    at runScript (load.php?lang=ko&modules=startup&only=scripts&raw=1&skin=liberty:12:439)

    at execute (load.php?lang=ko&modules=startup&only=scripts&raw=1&skin=liberty:13:489)

    at doPropagation (load.php?lang=ko&modules=startup&only=scripts&raw=1&skin=liberty:6:492)

jQuery.fn.load @ load.php?lang=ko&modules=ext.EnhanceMarkup.scripts%7Cjquery%2Coojs-ui-core%2Coojs-ui-widgets%7Cjquery.ui%7Coojs-ui.styles.icons-editing-advanced&skin=liberty&version=8mj0p:846

(anonymous) @ VM1451:10

domEval @ load.php?lang=ko&modules=startup&only=scripts&raw=1&skin=liberty:10

runScript @ load.php?lang=ko&modules=startup&only=scripts&raw=1&skin=liberty:12

execute @ load.php?lang=ko&modules=startup&only=scripts&raw=1&skin=liberty:13

doPropagation @ load.php?lang=ko&modules=startup&only=scripts&raw=1&skin=liberty:6

requestIdleCallback (async)

setAndPropagate @ load.php?lang=ko&modules=startup&only=scripts&raw=1&skin=liberty:7

implement @ load.php?lang=ko&modules=startup&only=scripts&raw=1&skin=liberty:18

(anonymous) @ load.php?lang=ko&modules=ext.EnhanceMarkup.scripts%7Cjquery%2Coojs-ui-core%2Coojs-ui-widgets%7Cjquery.ui%7Coojs-ui.styles.icons-editing-advanced&skin=liberty&version=8mj0p:1

I've tried overwriting it with the latest version of the MediaWiki file, I've tried running maintenance/update.php, but it still doesn't go away.

Also, the regex feature of the onParserBeforePreprocess function doesn't work in the extension I'm building, and I don't know why.

public static function onParserBeforePreprocess( &$parser, &$text, &$strip_state ) {
    $text = preg_replace(
        "/\[\*\s+([^ ]+)\s+(.*?)\]/",
        '<ref group="$1">$2</ref>',
        $text
    );

    $text = preg_replace(
        "/\[\*\s+([^ ]+)\s*\]/",
        '<ref group="$1" />',
        $text
    );

    return true;
}

How can I solve these problems? Thank you.

TheDJ (talkcontribs)

https://www.gaonwiki.com/w/%EB%AF%B8%EB%94%94%EC%96%B4%EC%9C%84%ED%82%A4:Common.js#L-503

That should be window.on( 'load', function() { // the code goes here } );. Or just $(function(){ // the code goes here }).


Regarding your hook. It's generally better to explain what you want to achieve, instead of asking why your chosen solution doesn't work. Because quite often it turns out that people are focusing on the incorrect solution to the problem.

Gaon12 (talkcontribs)

@TheDJ Thank you for your reply. I've removed the unnecessary parts from that page and no errors are occurring.

Let me elaborate on the issue with the onParserBeforePreprocess function not working.

extension.json:

{
    "name": "EnhanceMarkup",
    "description": "Provides enhanced markup functionalities",
    "version": "1.0",
    "author": [
        "Jeong Gaon"
    ],
    "url": "https://www.gaon.xyz/mw_extensions",
    "type": "other",
    "license-name": "Apache-2.0",
    "AutoloadClasses": {
        "EnhanceMarkupHooks": "includes/EnhanceMarkupHooks.php"
    },
    "ResourceModules": {
        "ext.EnhanceMarkup.styles": {
            "styles": "resources/ext.EnhanceMarkup.styles.css",
            "localBasePath": "",
            "remoteExtPath": "EnhanceMarkup"
        },
        "ext.EnhanceMarkup.scripts": {
            "scripts": ["resources/ext.EnhanceMarkup.scripts.js", "resources/lib/math.js"],
            "localBasePath": "",
            "remoteExtPath": "EnhanceMarkup"
        }
    },
    "Hooks": {
        "ParserFirstCallInit": "EnhanceMarkupHooks::onParserFirstCallInit",
        "BeforePageDisplay": "EnhanceMarkupHooks::onBeforePageDisplay"
    },
    "manifest_version": 2
}

includes/EnhanceMarkupHooks.php:

<?php
class EnhanceMarkupHooks
{
    public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin)
    {
        $out->addModules("ext.EnhanceMarkup.styles");
        $out->addModules("ext.EnhanceMarkup.scripts");
        return true;
    }

    public static function onParserFirstCallInit(Parser $parser)
    {
        // Register each of your custom parser functions with the parser
        $parser->setHook("random", [self::class, "randomRender"]);


        return true;
    }

    public static function onInternalParseBeforeLinks(Parser &$parser, &$text)
    {
        // - * 4+ == <hr>
        // Replace sequences of 3-9 '*', '-', or '_' with a horizontal rule
        $text = preg_replace('/^([-]{3,9})$/m', "<hr>", $text);

        // [pagecount] show all count of page
        // Replace [pagecount] with the total number of pages
        $text = preg_replace_callback(
            "/\[pagecount\]/",
            function ($matches) use ($parser) {
                $dbr = wfGetDB(DB_REPLICA);
                $count = $dbr->selectRowCount("page");
                return $count;
            },
            $text
        );

        // Replace [*A text] with <ref group="A">text</ref>
        $text = preg_replace(
            "/\[\*\s+([^ ]+)\s+(.*?)\]/",
            '<ref group="$1">$2</ref>',
            $text
        );

        // Replace [*A] with <ref group="A" />
        $text = preg_replace(
            "/\[\*\s+([^ ]+)\s*\]/",
            '<ref group="$1" />',
            $text
        );

        // Replace [* text] with <ref>text</ref>
        $text = preg_replace("/\[\*\s+(.*?)\]/", '<ref>$1</ref>', $text);

		// Replace [include text] with {{text}}
        $text = preg_replace("/\[\include\s+(.*?)\]/", '{{$1}}', $text);

        // Replace [br] with <br>
        $text = str_replace("[br]", "<br>", $text);

        // Font Size up {{{+1 (content) }}} - Range: 1~5
        $text = preg_replace_callback('/\{\{\{\+([1-5])\s*(.*?)\s*\}\}\}/s', function($matches) {
            return '<span style="font-size:'.(1 + $matches[1]).'em;">'.$matches[2].'</span>';
        }, $text);
        
        // Font Size down {{{-1 (content) }}} - Range: 1~5
        $text = preg_replace_callback('/\{\{\{-([1-5])\s*(.*?)\s*\}\}\}/s', function($matches) {
            return '<span style="font-size:'.(1 - $matches[1]/10).'em;">'.$matches[2].'</span>';
        }, $text);

        return true;
    }

    // Random
    // <random range="50">True|False</random>
    public static function randomRender(
        $input,
        array $args,
        Parser $parser,
        PPFrame $frame
    ) {
        // Disable caching
        $parser->getOutput()->updateCacheExpiry(0);

        // Parse the input
        $parts = explode("|", $input);

        // Get the range from args
        $range = isset($args["range"]) ? $args["range"] : 2; // default to 2

        // Generate a random number within the range
        $randomNumber = mt_rand(1, $range);

        // Choose the output based on the random number
        if ($randomNumber <= $range / 2) {
            // If the random number is in the first half of the range, return the first part
            return $parts[0];
        } else {
            // Otherwise, return the second part if it exists, or the first part if it doesn't
            return isset($parts[1]) ? $parts[1] : $parts[0];
        }
    }
}

Looking at the code, there doesn't seem to be anything particularly wrong with it - if it's supposed to work, typing something like [* texts] within the wiki should generate a footnote called texts, but for some reason it's outputting literally.

Reply to "Uncaught TypeError: url.indexOf is not a function"