Jump to content

Topic on Project:Support desk

Automated way to add a Category to all pages in Namespace "Main"

3
Abhidevananda (talkcontribs)

Hi again. I have a wiki with close to 3000 articles in Namespace Main. Now I need to add a Category (the same category) to all of those articles (with only a few exceptions). I am looking for an automated way to do this, maybe a regex in Special:ReplaceText (or possibly in some other extension). I have researched this but could not find specific instructions. If this can be done, what would the regex(s) be... presumably in two parts (one for the Search string and the other for the Replace string? Thanks.

Bawolff (talkcontribs)
Abhidevananda (talkcontribs)

Thanks, Bawolff. Just found the answer through AI.

  Search for: (.+)$
  Replace with: $1\n

Here’s a breakdown of what these expressions do:

  (.+)$: This matches the entire content of the page.
  $1\n: This appends the category tag  to the end of the content.

Make sure to replace YourCategoryName with the actual name of the category you want to add. (Sorry, I had trouble typing all of the Replace string. Immediately after the $1\n must come two opening square brackets, then Category:YourCategoryName followed by two closing square brackets.)

I also found that for such a large number of results in the ReplaceText extension I had to extend the result limits from the default 250 to a much higher number. But the instructions for doing this (adding a line in LocalSettings) were explained in the ReplaceText extension doc.

Appreciate all your help.