Page MenuHomePhabricator

AWB Regex Tester doesn't understand %%pagename%%
Open, Needs TriagePublicFeature

Description

AWB Find+Replace rules can refer to the current page name using pseudo-variables such as %%pagename%%. This doesn't work in the Regex Tester, even though the current page text is copied in to the "Text to search" box.

Discussion at
https://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser#.25.25pagename.25.25_not_working_in_the_.27Replace_with.27_field

Related Objects

Event Timeline

John_of_Reading raised the priority of this task from to Needs Triage.
John_of_Reading updated the task description. (Show Details)
John_of_Reading subscribed.

I found this also and submitted it and it was closed as invalid but the problem still exists.

But how would this work?

The regex tester has no context as to what those variables would be replaced with, whereas, during the workflow of processing a page, it would do.

So, we'd have to have a title field (or similar), for most of these to actually work...

Or, are you only asking for this to work when coming from the Advanced Find and replace?

        // Covered by ToolsTests.ApplyKeyWords()
        /// <summary>
        /// Applies the key words "%%title%%" etc.
        /// https://meta.wikimedia.org/wiki/Help:Magic_words
        /// </summary>
        public static string ApplyKeyWords(string title, string text, bool escape)
        {
            if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(title) && text.Contains("%%"))
            {
                string titleEncoded = WikiEncode(title);

                text = text.Replace("%%title%%", escape ? Regex.Escape(title) : title);
                text = text.Replace("%%titlee%%", titleEncoded);
                text = text.Replace("%%fullpagename%%", escape ? Regex.Escape(title) : title);
                text = text.Replace("%%fullpagenamee%%", titleEncoded);
                text = text.Replace("%%key%%", MakeHumanCatKey(title, text));

                string titleNoNamespace = RemoveNamespaceString(title);
                string basePageName = BasePageName(title);
                string subPageName = SubPageName(title);
                string theNamespace = GetNamespaceString(title);

                text = text.Replace("%%pagename%%", escape ? Regex.Escape(titleNoNamespace) : titleNoNamespace);
                text = text.Replace("%%pagenamee%%", WikiEncode(titleNoNamespace));

                text = text.Replace("%%basepagename%%", escape ? Regex.Escape(basePageName) : basePageName);
                text = text.Replace("%%basepagenamee%%", WikiEncode(basePageName));

                text = text.Replace("%%namespace%%", theNamespace);
                text = text.Replace("%%namespacee%%", WikiEncode(theNamespace));

                text = text.Replace("%%subpagename%%", subPageName);
                text = text.Replace("%%subpagenamee%%", WikiEncode(subPageName));

                // we need to use project's names, not user's
                // text = text.Replace("{{CURRENTDAY}}", DateTime.Now.Day.ToString());
                // text = text.Replace("{{CURRENTMONTHNAME}}", DateTime.Now.ToString("MMM"));
                // text = text.Replace("{{CURRENTYEAR}}", DateTime.Now.Year.ToString());

                text = text.Replace("%%server%%", Variables.URL);
                text = text.Replace("%%scriptpath%%", Variables.ScriptPath);
                text = text.Replace("%%servername%%", ServerName(Variables.URL));
            }
}

After you've clicked the start button, AWB has a "current page" and displays its name in the title bar. Could that be passed in to the regex tester?

And when you're not on a page?

Noting, we only pass in page text by default in certain circumstances as it is

When its not on a page, %%pagename%% can be blank.

Or rather, that %%pagename%% return itself, "%%pagename%%", if no substitute exists.

Aklapper changed the subtype of this task from "Task" to "Feature Request".Nov 22 2022, 5:18 PM