Extension:Replace Text/fr

Replace Text est une extension de MediaWiki qui fournit une page spéciale, ainsi qu'un script de ligne de commande, pour permettre aux administrateurs de faire une chaîne globale find-and-replace sur le texte et les titres des pages de contenu du wiki.

L'opération de remplacement de texte est une opération différée et validée dans la file d'attente des travaux. Vous pouvez exécuter  à partir du dossier   pour effectuer le remplacement immédiatement et traiter la file d'attente des travaux.

Utilisation
Replace Text définit une page spéciale, à "Special:ReplaceText" (ou son équivalent dans une autre langue), qui gère la recherche globale et le remplacement ; il définit également un script, replaceAll.php, qui fait la même chose à partir de la ligne de commande. Cette documentation couvrira d'abord la page spéciale, puis le script de ligne de commande.

La page Special:ReplaceText affiche initialement un formulaire pour qu'un administrateur remplisse les détails de la recherche et du remplacement : l'administrateur entre une chaîne de recherche et son remplacement, l'ensemble d'espaces de noms sur lequel effectuer la recherche, et choisit de remplacer le texte dans le contenu de la page, les titres de la page ou les deux. En option, l'administrateur peut également ajouter deux filtres supplémentaires : nom d'une catégorie à laquelle toutes les pages doivent appartenir et préfixe par lequel tous les noms de pages doivent commencer. Lorsque ce formulaire est soumis, une liste de toutes les pages contenant cette chaîne de recherche ou de toutes les pages dont les titres contiennent la chaîne de recherche, ou les deux, s'affiche. À côté de chaque nom de page figure une case à cocher pour chaque page, afin qu'ils puissent désélectionner les pages qu'ils ne souhaitent pas remplacer. L'utilisateur peut alors appuyer sur "Remplacer" pour effectuer le remplacement réel. Une fois qu'un remplacement de texte est fait, il n'est pas directement impossible ; bien que vous puissiez toujours exécuter un remplacement "inverse", en remplaçant la nouvelle chaîne par la chaîne d'origine. Pour cette raison, si la chaîne de remplacement est vide ou s'il s'agit d'une chaîne qui existe déjà dans le wiki, l'utilisateur reçoit un message d'avertissement.

Si la chaîne de recherche est contenue plusieurs fois sur une page, toutes ces instances sont remplacées. Les remplacements de chaque page s'affichent sous la forme d'une modification wiki (mineure), avec l'administrateur qui a effectué le remplacement de texte comme l'utilisateur qui a effectué l'édition et un résumé d'édition qui ressemble à "Remplacement de texte :

Le titre d'une page ne peut pas être déplacé vers un titre qui existe déjà dans le wiki, ou vers un titre à plusieurs lignes. Les pages qui ne peuvent pas être déplacées seront simplement listées sur la page de sélection comme étant non déplaçables, sans case à cocher près d'elle

La recherche est sensible à la casse. Voir ci-dessous pour savoir comment le rendre insensible à la casse.

Considérations

 * 1) ReplaceText ne traite que 250 pages à la fois par défaut. Pour changer cela, vous pouvez affecter   à une valeur plus grande dans votre fichier LocalParamètres.php. Cependant, vous pouvez être limité par le   de PHP ; si l'extension signale un tel avertissement, vous devrez peut-être le changer.
 * 2) Tous les remplacements sont placés dans la file d'attente des travaux. Ainsi, si vous devez traiter un grand nombre de pages, vous devrez exécuter Replace Text puis " " (potentiellement plusieurs fois).

Utilisation les expressions régulières
Si vous utilisez une base de données MySQL ou PostgreSQL, vous verrez une case à cocher "Utiliser des expressions régulières" dans le formulaire Special:ReplaceText. Cette case à cocher n'apparaît pas pour les bases de données SQLite, car SQLite n'a pas d'opérateur natif « REGEXP ».

Si vous cliquez sur cette case, vous pouvez utiliser regular expressions, ou regexps, dans les chaînes de recherche et de remplacement. The set of regular expressions allowed is basically a small subset of the PHP and MySQL/PostgreSQL regular-expression set. The special characters that one can use in the search string are " . * + ? [ ] |", and within the replacement string one can use values like $1, $2 etc. (To use these as regular characters, you just need to escape them by adding a "\" beforehand - which you would also need to do with the "/" character.) This section will not give a tutorial on using regular expressions (the Wikipedia article is a good place to start for that, as is this page on MySQL regexps), but here is the basic example listed in the inline explanation:


 * Search string:
 * Replacement string:

This would look for pages containing the letter 'a', the letter 'c', and any text in between (signified by the ".*"). It would then put that middle text after the 'a' and 'c' - the "$1" in the replacement string refers to the first element of the search string contained within parentheses (in this case, there's only one).

For every page for which the replace is actually called, the replacement would happen for every occurrence of the search string, not just one - just as happens with regular, non-regular-expression search.

More complex regexps

 * Search string:
 * Replacement string:

This would replace "hello222.555" with "222,555" and "hello2.55" with "2,55"

First the word "hello" is matched. In brackets follows an expression to search for any digits "0-9". The following asterisk finds multiple matches of the preceding element. The brackets and the asterisk get enclosed with parantheses, so we match the complete term and transfer it to $1. The "\." indicates that it's a true dot, and not a special character. The second expression within parentheses is matched and put into $2.

Replacements followed by numbers
The following will not work:
 * Search string:
 * Replacement string:

That's because the search will think the number of the replacement is 1123456, not 1. Instead, you should have the following:
 * Replacement string:

In general, you can always enclose numbered values in curly brackets.

Case-insensitive search
To make your search case-insensitive, use regular expression and the case-insensitive modifier, :
 * Search string:
 * Replacement string:

The above will unify the casing of all mentions of iPhone/iphone/IPHONE to iPhone.

Command-line script: replaceAll.php
Replace Text offers a script, replaceAll.php, in the /maintenance directory, which can be run from the command line, and which does all the same replacements that the page Special:ReplaceText does. The first two arguments for this script should be the search text and the replacement text; you can call this script simply like the following: php replaceAll.php "Leningrad" "St. Petersburg"

If you use numbered values like $1 in the replacement string, you have to either escape them inside double quotes like  or use single quotes. Otherwise the shell will put blanks in their place as it thinks they are variables.

Other possible arguments/flags for this script are:
 * - only find the search texts, without doing any actual replacements
 * - regular expressions should be used (default is false)
 * - the user to attribute the replacements to (default is the user with ID 1)
 * - skip all prompts with an assumed "yes"
 * - set a custom edit summary for the replacement edits
 * - rename page titles instead of replacing contents
 * - do not announce edits on Special:RecentChanges or watchlists
 * - set a comma-separated list of the namespaces to search
 * - search on all the namespaces; overrides any value set for "--ns"
 * - the name of a file holding a tab-separated list of replacements to make
 * - display the replacements being made

Additionally, there are two flags that strictly print out helpful information unrelated to a specific text replacement:
 * - show a description of the file format to use with
 * - show a list of all namespaces on this wiki

(You can also see all of these options by calling "php replaceAll.php --help".)

Assigning replacements to a user
By default, all replacements are credited in the page history to the user who initiated them. However, you can instead have replacements be credited to a pre-set user -- such as a bot account -- by adding a line like this to LocalSettings.php, below the inclusion of Replace Text:

The username specified must already be an account on the wiki. It will be added to MediaWiki's array of usernames which may not be registered or logged in from.

Auteurs
Replace Text was mostly written by Yaron Koren, reachable at yaron57@undefinedgmail.com. Important contributions were also made by Niklas Laxström, Ankit Garg (who contributed much of the regular expression code), Mark Hershberger (who wrote the command-line script), Brent Laabs, Cindy Cicalese, Nikhil Kumar, Umherirrender, James Forrester, Fomafix, Marijn van Wezel, Sahaj Khandelwal and others.

Historique des versions
Replace Text is currently at version 1.7. See the entire version history.

Captures d’écran
Below are images of the workflow of Replace Text. First, the initial page in which "George F. Will" and "George Will" are entered for the target string and replacement string, respectively, and replacing text in page titles is specified as well, on Discourse DB:



Note: the check "All" and "None" boxes only show up when using the Vector skin, or skins based off of it.

And here is what the page looks like after the user hits "Continue":



Hitting "Replace" would replace this value in all of the listed pages, as well as moving the page at the end to its new value.

Problèmes connus

 * The replacement actions themselves are structured as MediaWiki "jobs", to ensure that the system is not overloaded if the user wants to do many at the same time. This means that a large set of replacements will not be done immediately, and may take minutes, hours or even longer to complete. Normally, jobs get activated every time a page is viewed on the wiki; to speed up the process (or slow it down), you can change the number of jobs run when a page is viewed; the default is 1. Thus a Replace Text request can stall soon after it starts if there is not enough front-end activity on the wiki to outrun the other sources of new batch jobs. For information on how to change the default, see the  page. To force the wiki to run all jobs immediately, go to the shell and execute the script ; there generally isn't a way to do this from the wiki's front end.
 * For getting the jobs to run on a seldom-used wiki, for instance a working wiki for a small hobby project team, you can for instance force a refresh of the "All pages" special page. This can be done for instance by using the following shell script on Unix:
 * If you are still having a problem with getting Replace Text's jobs to run, adding the following to LocalSettings.php may fix the problem:
 * If you are still having a problem with getting Replace Text's jobs to run, adding the following to LocalSettings.php may fix the problem:


 * In order for redirects not to be created on page moves (i.e. if the "Save the old titles as redirects to the new titles" checkbox is unchecked), you will have to give the relevant user the 'suppressredirect' permission. Assuming you've given the 'replacetext' permission to a "trusted-editor" user group, you would need to add the following to LocalSettings.php:


 * If your revisions are compressed (that is, if is enabled in  or the script  has been executed with the option  ) then ReplaceText will not work, because it makes use of SQL queries that can't search compressed text. (see the MassEditRegex extension as an alternative in this case.)
 * If you have a large number of replacements, some of them may not get done; or you may see an error message that reads "You must select at least one namespace." In both cases, that's due to a limit on the number of form inputs that PHP accepts. This can be fixed in a number of ways:
 * If you have the Suhosin PHP extension installed on your server, that may be source of the problem. You can increase the value of the variables  and  ; or simply try temporarily disabling Suhosin while you do the replacements.
 * The PHP setting  (available since PHP 5.3.9) also affects the number of replacements you can do at any time - you can try setting this to a very large number, like 3000.

Bugs and feature requests
Send any bug reports and requests to Yaron Koren, at yaron57@undefinedgmail.com.

Contributing patches to the project
If you found some bug and fixed it, or created a new feature, please either do a Git commit with your code, or create a patch by going to the "ReplaceText" directory, and typing:

If you created a patch, please send it, along with a description, to Yaron Koren.

Traductions
Translation of Replace Text is done through translatewiki.net. The translation for this extension can be found here. To add language values or change existing ones, you should create an account on translatewiki.net, then request permission from the administrators to translate a certain language or languages on this page (this is a very simple process). Once you have permission for a given language, you can log in and add or edit whatever messages you want to in that language.

Voir aussi

 * Extension:MassEditRegex - A similar extension using regular expressions to edit multiple pages at once