Difference between revisions of "MassEditRegex"

From Biowikifarm Metawiki
Jump to: navigation, search
(Extensions -> MediaWiki Extensions)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
'''MassEditRegex'''
 
'''MassEditRegex'''
  
This extension allows administrators to replace specific texts simultaneously in a larger number of pages. Adding texts like category assignments are also possible. The pagenames need to be specified which means a text search normally precedes the use of the extension. However, apart from providing a list of the pages to be edited other options like specifying the begining of the pagenames or categories are also possible. For categories all pages within a category are searched and edited. The extension is, for example, useful to change SemanticMW assignments, where lists of pages can be generated with the ask function.
+
This extension allows administrators to replace, add or delete specific texts simultaneously in a larger number of pages. The pagenames need to be specified which means a text search normally precedes the use of the extension. However, apart from providing a list of the pages to be edited other options like specifying the begining of the pagenames or categories are also possible. For categories all pages within a category are searched and edited. The extension is, for example, useful to change SemanticMW assignments, where lists of pages can be generated with the ask function.
  
 
Here are a few notes for administrators who are not familiar with this extension:
 
Here are a few notes for administrators who are not familiar with this extension:
Line 7: Line 7:
 
* Go to [[Special:MassEditRegex]]
 
* Go to [[Special:MassEditRegex]]
 
* Enter a list of pagenames into the box "Pages to be edited", placing each pagename into a new line
 
* Enter a list of pagenames into the box "Pages to be edited", placing each pagename into a new line
* Enter the search text using the [http://php.net/manual/en/function.preg-replace.php preg_replace] format. That means the search text needs to be enclosed in forward slashes and several signs need to be escaped, like [, /, (, ), or |. The use of [[wikipedia:Regular expression|regular expressions]] is also possible.
+
* Enter the search text using the [http://php.net/manual/en/function.preg-replace.php preg_replace] format. That means the search text needs to be enclosed in forward slashes and several signs need to be escaped, namely: \ ^ . $ | ( ) [ ] * + ? { } ,
 +
* The use of [[wikipedia:Regular expression|regular expressions]] in the search text is also possible.
 
* If the search text is not found in one of the pages listed no changes are done on that page.
 
* If the search text is not found in one of the pages listed no changes are done on that page.
 
* Normally it is advisable to use the "Show preview" option first. However, the preview is limited to the first 10 pages listed.
 
* Normally it is advisable to use the "Show preview" option first. However, the preview is limited to the first 10 pages listed.
Line 17: Line 18:
 
'''Example:'''<br/>
 
'''Example:'''<br/>
 
<pre>
 
<pre>
Search text - /(\|Publication authors=.*)A. Johnson/
+
Search text - /(\|Publication authors=.*)A\. Johnson/
 
Replace text - $1[[A. Johnson]]
 
Replace text - $1[[A. Johnson]]
 
</pre>
 
</pre>
Line 33: Line 34:
 
</pre>
 
</pre>
  
[[Category:Extensions]]
+
[[Category: MediaWiki Extensions]]

Latest revision as of 21:25, 13 November 2017

MassEditRegex

This extension allows administrators to replace, add or delete specific texts simultaneously in a larger number of pages. The pagenames need to be specified which means a text search normally precedes the use of the extension. However, apart from providing a list of the pages to be edited other options like specifying the begining of the pagenames or categories are also possible. For categories all pages within a category are searched and edited. The extension is, for example, useful to change SemanticMW assignments, where lists of pages can be generated with the ask function.

Here are a few notes for administrators who are not familiar with this extension:

  • Go to Special:MassEditRegex
  • Enter a list of pagenames into the box "Pages to be edited", placing each pagename into a new line
  • Enter the search text using the preg_replace format. That means the search text needs to be enclosed in forward slashes and several signs need to be escaped, namely: \ ^ . $ | ( ) [ ] * + ? { } ,
  • The use of regular expressions in the search text is also possible.
  • If the search text is not found in one of the pages listed no changes are done on that page.
  • Normally it is advisable to use the "Show preview" option first. However, the preview is limited to the first 10 pages listed.
  • Several search and replace expressions can be used simultaneously. For this each search and replace expression is entered in a new line, even if the replace line is blank.
  • Only one change is made per line and if the search text occurs several time in a line only the last occurrence is changed.
  • Search expressions in brackets (without escapes) can be referred to as $1, $2, etc. in the replace text.
  • A Gateway error might occur if too many pages are changed at once (e.g. more than 200).

Example:

Search text - /(\|Publication authors=.*)A\. Johnson/
Replace text - $1[[A. Johnson]]

This example places "A. Johnson" into double square brackets in all lines where "|Publication authors=" is found. The regular expression ".*" stands for any string, even for an empty string. Thus:

|Publication authors=John F. Smith and A. Johnson
becomes
|Publication authors=John F. Smith and [[A. Johnson]]

or
|Publication authors=A. Johnson and S. Wang
becomes
|Publication authors=[[A. Johnson]] and S. Wang