Page MenuHomePhabricator

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


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

Event Timeline

John_of_Reading updated the task description. (Show Details)
John_of_Reading raised the priority of this task from to Needs Triage.
John_of_Reading added a subscriber: John_of_Reading.
Restricted Application added subscribers: StudiesWorld, Josve05a, Aklapper. · View Herald TranscriptJan 21 2016, 5:33 PM

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

Reedy added a subscriber: Reedy.EditedApr 1 2016, 2:07 PM

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.
        /// </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?

Reedy added a comment.Apr 1 2016, 6:08 PM

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.