FANDOM


This is the talk page for discussing improvements to the FindAndReplace page.

Sorry for my mistake

This FindAndReplace version (edited by me) broken FindAndReplace script.

My new local storage setting feature cause this problem.

I tested it on my browser with FindAndReplace edit page, but because i added "FindAndReplace" item to "localStroage" object manually, so no exception throwed.

Later, i used it on my Don't Starve game Wiki page (no "FindAndReplace" item existed), this error thorwed.

Cause

  • No "FindAndReplace" item in localStorage object.
  • Exception message: TypeError: Cannot read property 'sh' of null

Solution

Check st object if it is object or not equal to null before get it's properties (sh, gm, cs).

Update

This is fix and update version.

Change

  • Fixed new setting store feature exception throwed while run this script.
  • Remove Javascript ecscape character (\) when string declare with single quote (') character. Useless character.
  • Replace expand/collapse style by Wikia style (chevron, expand, collpase class).
  • Replace undo script by new undo script. Must confirm to undo.
  • Rename "expend" to "expand"

Code

//__NOWYSIWYG__ <source lang="javascript">
//<nowiki>
 
$(function() {
    'use strict';
    importArticle({
        type: "style",
        article: "u:dev:FindAndReplace/code.css"
    });
    var lng = {
        // English
        en: {
            far: 'Find and replace',
            farbuttontext: 'Find and Replace Text',
            findthis: 'Find this:',
            replacewith: 'Replace with:',
            globalm: 'Global matching.',
            casesensitive: 'Case sensitive.',
            undoedits: 'Undo edits',
            undoinfo: 'All edits, not only replaces',
            collapse: 'Collapse',
            expand: 'Expand',
            lbwarning: 'Warning: pressing Enter key\nwill publish your edits',
            farfound: 'found and replaced.',
            undomsg: 'This will undo all edited text, not only replaced text.\r\nAre you sure want to undo?'
        },
        // Deutsch (German)
        de: {
            far: 'Suchen und Ersetzen',
            farbuttontext: 'Suche und Ersetze Text',
            findthis: 'Suche nach:',
            replacewith: 'Ersetze mit:',
            globalm: 'Suche überall',
            casesensitive: 'Groß-/Kleinschreibung beachten.',
            undoedits: 'Bearbeitungen rückgängig machen',
            undoinfo: 'Alle Bearbeitungen, nicht nur Ersetzungen',
            collapse: 'Einklappen',
            expand: 'Ausklappen',
            lbwarning: 'Achtung: Das Drücken der Eingabetaste\nwird die Bearbeitungen speichern',
            farfound: 'gefunden und ersetzt.',
            undomsg: 'This will undo all edited text, not only replaced text.\r\nAre you sure want to undo?'  // New, needs tranlation.
        },
        // Español
        es: {
            far: 'Buscar y reemplazar',
            farbuttontext: 'Find and Replace Text', // New, needs tranlation.
            findthis: 'Buscar esto:',
            replacewith: 'Remplazar con:',
            globalm: 'Búsqueda global.', // better translate for "matching"?
            casesensitive: 'Distinción entre mayúsculas y minúsculas.',
            undoedits: 'Deshacer ediciones',
            undoinfo: 'Todas las ediciones, no solo reemplazos',
            collapse: 'Desplegar',
            expand: 'Ocultar',
            lbwarning: 'Advertencia: presionar la tecla Enter\npublicará tus ediciones',
            farfound: 'found and replaced.', // New, needs tranlation.
            undomsg: 'This will undo all edited text, not only replaced text.\r\nAre you sure want to undo?'  // New, needs tranlation.
        },
        // Français
        fr: {
            far: 'Trouver et remplacer',
            farbuttontext: 'Trouver et remplacer le texte',
            findthis: 'Trouver ceci :',
            replacewith: 'Et le remplacer avec :',
            globalm: 'Recherche globale.',
            casesensitive: 'Sensible à la casse',
            undoedits: 'Annuler les modifications',
            undoinfo: 'Toutes, pas seulement les remplacements',
            collapse: 'Masquer',
            expand: 'Afficher',
            lbwarning: 'Attention : appuyer sur la\ntouche Entrée entrainera une\npublication des modifications',
            farfound: 'trouvés et remplacés.',
            undomsg: 'This will undo all edited text, not only replaced text.\r\nAre you sure want to undo?'  // New, needs tranlation.
        },
        // Occitan
        oc: {
            far: 'Trobar e remplaçar',
            farbuttontext: 'Trobar e remplaçar lo tèxt', // New, needs tranlation.
            findthis: 'Trovar aquò',
            replacewith: 'E lo remplaçar amb :',
            globalm: 'Recèrca globala.',
            casesensitive: 'Sensible a la cassa',
            undoedits: 'Desfar las edicions',
            undoinfo: 'Totas, pas sonque los remplaçaments',
            collapse: 'Amagar',
            expand: 'Afichar',
            lbwarning: 'Atencion : apiejar sus "Enter" publicarà\nlas edicions',
            farfound: 'trobats e remplaçats.',
            undomsg: 'This will undo all edited text, not only replaced text.\r\nAre you sure want to undo?'  // New, needs tranlation.
        },
        // Polish
        pl: {
            far: 'Znajdź i zamień',
            farbuttontext: 'Find and Replace Text', // New, needs tranlation.
            findthis: 'Znajdź to:',
            replacewith: 'Zamień na:',
            globalm: 'Globalne dopasowanie.',
            casesensitive: 'Wielkość liter.',
            undoedits: 'Cofnij edycje',
            undoinfo: 'Wszystkie zmiany, nie tylko zamienione',
            collapse: 'Zwiń',
            expand: 'Rozwiń',
            lbwarning: 'Uwaga: naciskając klawisz Enter \nmożesz opublikować swoją edycję',
            farfound: 'found and replaced.', // New, needs tranlation.
            undomsg: 'This will undo all edited text, not only replaced text.\r\nAre you sure want to undo?'  // New, needs tranlation.
        },
        // Tiếng Việt (Vietnamese)
        vi: {
            far: 'Tìm và thay thế',
            farbuttontext: 'Tìm và Thay thế Văn bản',
            findthis: 'Tìm:',
            replacewith: 'Thay với:',
            globalm: 'Khớp toàn bộ.',
            casesensitive: 'Phân biệt hoa thường.',
            undoedits: 'Hoàn tác chỉnh sửa',
            undoinfo: 'Tất cả thao tác sửa, không chỉ thay thế',
            collapse: 'Thu gọn',
            expand: 'Mở rộng',
            lbwarning: 'Cảnh báo: nhấn phím Chọn (Enter)\nsẽ phát hành bản sửa của bạn.',
            farfound: 'đã tìm thấy và thay thế.',
            undomsg: 'Điều này sẽ hoàn tác tất cả văn bản đã chỉnh sửa, không chỉ văn bản đã thay thế.\r\nBạn có muốn hoàn tác?'
        } // No comma here
    };
    var st = $.storage.get("FindAndReplace");
    if (typeof st !== 'object' || st == null) st = {sh: false, gm: true, cs: false};
    lng = $.extend(lng.en, lng[mw.config.get('wgContentLanguage')], lng[mw.config.get('wgUserLanguage')]);
    $('.rail-auto-height').prepend('<div class="module far-module"><h3><span>' + lng.far + ' (' + (st.sh ? lng.collapse : lng.expand) + ')</span><img src="data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D" class="chevron ' + (st.sh ? 'collapse' : 'expand') + '"></h3><div class="module_content" id="findfielddiv" style="display: ' + (st.sh ? 'block' : 'none') + '; padding-top:5px;"><div>' + lng.findthis + '<div style="padding-top:3px;"><textarea id="find_this" style="margin: 0; width:100%;" rows="4" wrap="off"></textarea></div></div><div style="padding-top:8px;">' + lng.replacewith + '</div><div style="padding-top:3px;"><textarea id="replace_with" style="margin: 0; width:100%;" rows="4" wrap="off" placeholder=""></textarea></div><div style="padding:7px 0px 7px 0px;"><table><tr><td><label><input title="' + lng.globalm + '" type="checkbox" id="globl"' + (st.gm ? ' checked="checked"' : '') + '>' + lng.globalm + '</label></td></tr><tr><td><label><input title="' + lng.casesensitive + '" type="checkbox" id="case_sen"' + (st.cs ? ' checked="checked"' : '') + '>' + lng.casesensitive + '</label></td></tr><tr><td><span id="far-found"></span></td></tr></table><center><input type="button" value="' + lng.farbuttontext + '" id="find-and-replace"></center><br /><a href="javascript:void(0)" id="far-undo">' + lng.undoedits + '</a><sup><acronym title="' + lng.undoinfo + '" style="border: none;" class="icone-aide"><img src="http://img2.wikia.nocookie.net/__cb20141207003419/harrypotter/fr/images/thumb/6/6c/Icone-aide.png/12px-Icone-aide.png" alt="Icone-aide" class="lzyPlcHld  lzyTrns lzyLoaded" data-image-key="Icone-aide.png" data-image-name="Icone-aide.png" data-src="http://img2.wikia.nocookie.net/__cb20141207003419/harrypotter/fr/images/thumb/6/6c/Icone-aide.png/12px-Icone-aide.png" width="12" height="12"></acronym></sup></div></div></div>');
    $('#find-and-replace').click(function () {
        var searchfor = '',
            searchexp,
            $textarea = $('#wpTextbox1'),
            replacewith = $('#replace_with').val().replace(/\r/gi, ''),
            text = $textarea.val().replace(/\r/gi, ''),
            flagg = 'g',
            flagi = 'i';
        if ($('#globl').prop('checked') === false) {
            flagg = '';
        }
        if ($('#case_sen').prop('checked') === true) {
            flagi = '';
        }
        var flags = flagg + flagi + 'm';
        searchfor = $('#find_this').val().replace(/\r/gi, '').replace(/([.*+?^=!:${}()|\[\]\/\\])/g,'\\$1');
        searchexp = new RegExp(searchfor, flags);
        var rcount = 0;
        var matched = text.match(searchexp);
        if (matched !== null) {
            rcount = matched.length;
        }
        text = text.replace(searchexp, replacewith);
        $textarea.val(text);
        $('#far-found').text( rcount + ' ' + lng.farfound );
    });
    function getOldContent() {
        $("#wpTextbox1").val($("#wpTextbox1").text());
    }
    $('a#far-alb').click(function() { 
        $('#replace_with').val($('#replace_with').val()+'\n'); 
    })
    $('a#far-undo').click(function () {
        if (confirm(lng.undomsg)) getOldContent();
    });
    $(".far-module h3").click(function () {
        var $header = $(this);
        var $content = $header.next();
        var $visible = $content.is(":visible");
        $header.find('span').text(lng.far + " (" + ($visible ? lng.expand : lng.collapse) + ")");
        $header.find(".chevron").addClass($visible ? "expand" : "collapse").removeClass($visible ? "collapse" : "expand");
        $content.stop().slideToggle(500);
    });
    $(window).bind("beforeunload", function(){
        $.storage.set("FindAndReplace", {sh: $("#findfielddiv").is(":visible"), gm: $('#globl').prop('checked'), cs: $('#case_sen').prop('checked')});
    });
});
 
//</nowiki>
//</source>

Regards

SITUVN (talk) 12:45, January 31, 2015 (UTC)

No problem. Thank you for all these improvements. Only 1 thing doesn't work on my side : the storage of global matching and case sensitive checked status. I relpaced the data storage with a custom variable. I also added you amongst the authors of the script. —Hulothe @fandom 15:42, February 10, 2015 (UTC)

Don't work

It worked yesterday, but today it doesn't. Did you change the code? --YHY-WN723N-V1 12:18, February 27, 2015 (UTC)

No, the code didn't change since february 10th. Could you give it another try? Thank you. —Hulothe @fandom 23:41, February 27, 2015 (UTC)
I just found the problem: I used a full block comma(,) in my global JS. --YHY-WN723N-V1 12:57, February 28, 2015 (UTC)
Ok, no problem. —Hulothe @fandom 13:38, February 28, 2015 (UTC)

German Translation

I translated the missing German strings. Additionally I've done a few changes which imho improve the translation, namely:

  • Replaced "Bearbeitung" with "Änderung". It's a more common word and "Bearbeitung" refers rather to the process while "Änderung" refers to the changes.
  • "Suche überall" replaced with "Alle ersetzen" (replace all), which states more clearly what it does
  • Replaced "Ersetze mit:" with "Ersetzt durch:", which is more common
        de: {
            far: 'Suchen und Ersetzen',
            farbuttontext: 'Suche und Ersetze Text',
            farselbuttontext: 'Suche und Ersetze ausgewählten Text',
            selectedtext: 'Ausgewählter Text:',
            findthis: 'Suche nach:',
            replacewith: 'Ersetze durch:',
            globalm: 'Alle ersetzen',
            casesensitive: 'Groß-/Kleinschreibung beachten',
            enblregex: 'Reguläre Ausdrücke verwenden',
            undoedits: 'Änderungen rückgängig machen',
            undoinfo: 'Alle Änderungen, nicht nur Ersetzungen',
            collapse: 'Einklappen',
            expand: 'Ausklappen',
            lbwarning: 'Achtung: Das Drücken der Eingabetaste\nwird die Änderungen speichern',
            farfound: 'gefunden und ersetzt.',
            undomsg: 'Dies macht alle Änderungen rückgängig, nicht nur Ersetzungen.\r\nMöchtest Du wirklich fortfahren?',
            noselected: 'Es wurde kein Text ausgewählt.'
        },

-- NoWayThisUsernameIsAlreadyOwnedBySomeone (talk) 08:50, July 14, 2015 (UTC)

Completed I've added this to the code! - OneTwoThreeFall (talk) 09:41, June 15, 2016 (UTC)

Bug: Overlap

Since a few days the dropdown menu is overlapping with the others menus at the right. As can be seen here:

FindAndReplaceOverlapBug

-- DarkBarbarian.png Barbar (talk) 14:37, May 5, 2016 (UTC)

Pull this CSS code:
#findfielddiv { height: auto !important; }
yhynerson1 (talk, contribs) 07:42, May 8, 2016 (UTC)
How about this instead? #findfielddiv { overflow-y: auto; } Yours seems to make the field go way down the screen limit, making half of it unusable. -- Dorumin 22:41, May 8, 2016 (UTC)

Can someone just update the extension code instead? I see that the "fixed" css is not live. leviathan_89 @fandom 18:59, May 26, 2016 (UTC)

Fixed now! Syntaxhighlight tags had been added to the CSS page without being enclosed within a comment, causing it to be considered invalid. - OneTwoThreeFall (talk) 09:36, June 15, 2016 (UTC)

Infoboxes

On templates marked as "infoboxes" the extension is not loaded. I suppose that's because Wikia doesn't load all modules on such templates. leviathan_89 @fandom 15:13, July 6, 2016 (UTC)

Tool disappeared

Hi, the tool disappeared from by sidebar. I was using it less than 24 hours ago & today I look and it's gone. It's listed in my global.js file & the other imports are still working. Anyone know what's going on? Thanks, Janus100 (talk) 00:09, February 18, 2017 (UTC)

There were some extra characters that threw an error. I removed them, hopefully that will fix it, although we need to wait the code review. leviathan_89 @fandom 06:35, February 18, 2017 (UTC)
I am having the same issue but it is like that with other imports too such as PortableCSSPad and AutoEditPages. Christian Sirolli (Talk | Contribs) 16:55, February 18, 2017 (UTC)
Come to find out from KockaAdmiralac that this script being broken broke the rest of the scripts for me. So nevermind the rest of what I said above. Christian Sirolli (Talk | Contribs) 20:13, February 18, 2017 (UTC)
Seems like the newest revision is live right now, but this tool is still not showing up... Does it take time to process or is there something else wrong? Thanks, Janus100 (talk) 07:06, February 22, 2017 (UTC)
@Janus100 , I entered test mode with your edit and it works. Good job. For some reason the other type of spaces jacked up the code.Christian Sirolli (Talk | Contribs) 16:06, February 22, 2017 (UTC)
Yeah, there was a second set of bad spaces, like the kind leviathan_89 removed. The revision I made is now live and the tool has finally reappeared for me, so hopefully it's working for everyone now. Cheers, Janus100 (talk) 23:21, February 22, 2017 (UTC)

Possible Bug

Sometimes when I edit, the FindAndReplace thing (I don't know the technical term for what it is) is doubled.
FAR-doubled
I don't know what causes this to happen. Is this a bug in the code or what? It doesn't happen all the time, for example it isn't happening right now. But other times it does.Christian Sirolli (Talk | Contribs) 12:22, April 1, 2017 (UTC)
Have you checked to see if you’ve installed it into local JS files as well as Global.js? If a Wiki has it installed sitewide then it can cause these duplciates, ditto if you have it in a personal file locally, because both the local script & your global script are loaded at once.
UrsuulTalkVanguardDate11:55 AM Saturday, April 1, 2017 (UTC)
Apparently I had it in my personal js on the site I was having the issue on. But I thought I saw elsewhere where I wouldn't have had it imported twice. Perhaps not. Thanks for clarifying. Christian Sirolli (Talk | Contribs) 12:22, April 1, 2017 (UTC) (this time I signed it)

New Info Aide Thing

I had an idea that we place a message saying "Make replacements only within the selected text." in an abbr tag like thing next to the button that says "Find and Replace selected Text". Kinda like the message for undoing edits. You hover over the icon next to "Undo edits" and it displays a message. To help clarify what is meant by "Find and Replace selected Text", we could display a message there as well. I have already added the message in the lng variable. I have called it "farselmsg" since we have the "farselbuttontext" and "undomsg". If someone knows how to do this (which I don't, I have done as much as I could), then go ahead and add it unless there is any objection.

Christian Sirolli (Talk | Contribs) 16:36, April 26, 2017 (UTC)
Also, I noticed that many of the languages could use an update. Someone may need to translate a few lines that are new and haven't yet been translated. Christian Sirolli (Talk | Contribs) 16:39, April 26, 2017 (UTC)

Template Pages Only?

This appears to only work on Template namespace pages only. Is it supposed to/can it work on article pages? Monk Talk 19:11, May 10, 2017 (UTC)

It works on all pages (except on MediaWiki pages or any .css or .js page) as long as you are editing via Source Editor. If you use Visual Editor, it will not work. Christian Sirolli (Talk | Contribs) 19:55, May 10, 2017 (UTC)
That's strange. I'm using classic editor, it doesn't load. Only on template pages. Are you absolutely sure? Have you tested it? Monk Talk 19:13, May 12, 2017 (UTC)
Works for me all the time. I even have it here. I am not sure why it doesn't work for you. Christian Sirolli (Talk | Contribs) 13:17, May 16, 2017 (UTC)

I cant search for global matchings

Hi :)


I cant search for global matchings. Is this normal or can somebody add the code to search for global matchings & global replace? This would be a big help!

Regular expressions

Can someone give me an example of regular expressions? I need to get the next result:

{{#regex:number 12 id 000745|/\d+/|<code>$0</code>}}

but unlike RegexFun this extension dont work with $n or \n. How to do that? Sorry if my question is not exactly correct) Ebony Bleed (talk) 16:29, February 24, 2018 (UTC)

Not Working

I don't know if it's just me or not, but this script is not currently working—the module just doesn't appear. Patrik 20:29, July 13, 2018 (UTC)