Topic on Extension talk:Replace Text

How to remove lines starting with pipe symbol "|" on Wiki pages?

6
Sochin67 (talkcontribs)

Dear all,

I have some redundant information in my Wiki which I would like to clean up and remove.

I'm talking about an SMW attribute named "Titel". Each page in my wiki has this attribute.

So my task is to remove a line as follows on each page:

|Titel=Some individual text...

So the search string should be something like: |Titel.*

which I would then replace with an empty string.

Unfortunately this search gives me a database error:

____________

[X@287-FSfWJq11TyEbd5ZgAADQA] /index.php?title=Spezial:Text_ersetzen Wikimedia\Rdbms\DBQueryError from line 1603 of /www/htdocs/w00997ce/hvg-wiki-2020-03/includes/libs/rdbms/database/Database.php: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading?

Query: SELECT page_id,page_namespace,page_title,old_text FROM `page`,`revision`,`text`,`slots`,`content` WHERE (old_text REGEXP '|Titel=.*') AND page_namespace = '0' AND (rev_id = page_latest) AND (rev_id = slot_revision_id) AND (slot_content_id = content_id) AND (SUBSTRING(content_address, 4) = old_id) ORDER BY page_namespace, page_title LIMIT 250

Function: ReplaceTextSearch::doSearchQuery

Error: 1139 Got error 'empty (sub)expression' from regexp (localhost)

...

____________

Root cause of this issue seems to be the pipe symbol, if I leave this out it seems to work.

However, I need to remove the entire line incl. the pipe symbol on each page.

Does anybody have a hint how to overcome this problem?

Many thanks!

Tenbergen (talkcontribs)

You need to "escape" the pipe. I think it's done as \| in regular expressions but have not tested it with ReplaceText right now. Tenbergen (talk) 14:31, 31 December 2020 (UTC)

Sochin67 (talkcontribs)

Dear Tina,

thanks for your feedback!

I tried it with a search for the following string:

\|Titel=.*

The DB error is gone.

However, unfortunately only the string from the search field ("|Titel=") is removed but the rest of the line remains.

I also tried this without the escape + pipe (just "Titel=.*") and the result is the same.

So for some reason the wildcard functionality is not working correctly.

Do you have any idea concerning this issue?

Many thanks!

Dinoguy1000 (talkcontribs)

You need some character or string which is guaranteed to be after the wildcard, to force the regex to match the whole line. Probably the simplest, if you're certain the parameter will have an entire line to itself, would be something like \|Titel=.*\n. Another suggestion would be if it's always followed by another parameter, in which case you could match a second pipe: \|Titel=.*\|, though note that this will require you to replace with a pipe instead of an empty string, and will also not work correctly if piped links can appear in the "Titel" parameter.

Sochin67 (talkcontribs)

It worked with \|Titel=.*\n - thank you very much!!

MvGulik (talkcontribs)

Cool. Did not know missing support for \n was added/fixed.

Two other cents, to find any and all variations. (assuming one template parameter per line)
Search: "(?i)(\n) *\| *tItEl *=.*\n"
Replace: "$1"