diff --git a/WikipediaCleaner/resources/tasks/frwiki/ListCheckWiki_List.txt b/WikipediaCleaner/resources/tasks/frwiki/ListCheckWiki_List.txt index d86211dfd..64a24dd54 100644 --- a/WikipediaCleaner/resources/tasks/frwiki/ListCheckWiki_List.txt +++ b/WikipediaCleaner/resources/tasks/frwiki/ListCheckWiki_List.txt @@ -1,4 +1,4 @@ DoTasks _Common.txt Set Namespaces 0 6 14 Set Prefix [[Utilisateur:WikiCleanerBot#T3|Bot_T3]] -ListCheckWiki frwiki-$-pages-articles.xml.bz2 wiki:Projet:Correction_syntaxique/Analyse_{0} 1 2 3 4 5 7 8 9 10 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 38 42 44 46 48 51 52 54 55 64 69 70 71 72 73 75 83 85 88 90 92 95 98 99 102 104 105 106 107 108 109 111 112 504 513 520 526 542 543 544 545 546 547 548 549 550 551 552 553 554 555 557 558 559 560 562 564 565 566 567 568 569 570 571 572 573 575 577 +ListCheckWiki frwiki-$-pages-articles.xml.bz2 wiki:Projet:Correction_syntaxique/Analyse_{0} 1 2 3 4 5 7 8 9 10 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 38 42 44 46 48 51 52 54 55 64 69 70 71 72 73 75 83 85 88 90 92 95 98 99 102 104 105 106 107 108 109 111 112 504 513 520 526 542 543 544 545 546 547 548 549 550 551 552 553 554 555 557 558 559 560 562 564 565 566 567 568 569 570 571 572 573 575 577 578 diff --git a/WikipediaCleaner/src/org/wikipediacleaner/api/check/algorithm/a5xx/a57x/a578/CheckErrorAlgorithm578.java b/WikipediaCleaner/src/org/wikipediacleaner/api/check/algorithm/a5xx/a57x/a578/CheckErrorAlgorithm578.java new file mode 100644 index 000000000..b253281ad --- /dev/null +++ b/WikipediaCleaner/src/org/wikipediacleaner/api/check/algorithm/a5xx/a57x/a578/CheckErrorAlgorithm578.java @@ -0,0 +1,169 @@ +/* + * WPCleaner: A tool to help on Wikipedia maintenance tasks. + * Copyright (C) 2013 Nicolas Vervelle + * + * See README.txt file for licensing information. + */ + +package org.wikipediacleaner.api.check.algorithm.a5xx.a57x.a578; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.annotation.Nonnull; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.wikipediacleaner.api.algorithm.AlgorithmParameter; +import org.wikipediacleaner.api.algorithm.AlgorithmParameterElement; +import org.wikipediacleaner.api.check.CheckErrorResult; +import org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithmBase; +import org.wikipediacleaner.api.configuration.WPCConfiguration; +import org.wikipediacleaner.api.data.Page; +import org.wikipediacleaner.api.data.PageElementListItem; +import org.wikipediacleaner.api.data.PageElementTemplate; +import org.wikipediacleaner.api.data.analysis.PageAnalysis; +import org.wikipediacleaner.api.data.contents.ContentsUtil; +import org.wikipediacleaner.i18n.GT; + + +/** + * Algorithm for analyzing error 578 of check wikipedia project. + *
+ * Error 578: Template in list. + */ +public class CheckErrorAlgorithm578 extends CheckErrorAlgorithmBase { + + @Nonnull private static final Logger log = LoggerFactory.getLogger(CheckErrorAlgorithm578.class); + + public CheckErrorAlgorithm578() { + super("Template in list"); + } + + /** + * Analyze a page to check if errors are present. + * + * @param analysis Page analysis. + * @param errors Errors found in the page. + * @param onlyAutomatic True if analysis could be restricted to errors automatically fixed. + * @return Flag indicating if the error was found. + */ + @Override + public boolean analyze( + PageAnalysis analysis, + Collection errors, boolean onlyAutomatic) { + if (analysis == null) { + return false; + } + + // Check each template + boolean result = false; + for (String templateName : templateNames) { + List currentTemplates = analysis.getTemplates(templateName); + for (PageElementTemplate template : currentTemplates) { + result |= analyzeTemplate(analysis, errors, template); + } + } + + return result; + } + + /** + * Analyze a template to check if errors are present. + * + * @param analysis Page analysis. + * @param errors Errors found in the page. + * @param template Template. + * @return Flag indicating if the error was found. + */ + private boolean analyzeTemplate( + PageAnalysis analysis, + Collection errors, + PageElementTemplate template) { + + // Check if template is in list item + PageElementListItem listItem = analysis.isInListItem(template.getBeginIndex()); + if (listItem == null) { + return false; + } + + // Report error + if (errors == null) { + return true; + } + int beginIndex = listItem.getBeginIndex(); + int endIndex; + if (template.getParameterCount() == 0) { + endIndex = template.getEndIndex() - 2; + } else { + endIndex = template.getParameterPipeIndex(0); + } + CheckErrorResult errorResult = createCheckErrorResult(analysis, beginIndex, endIndex); + String contents = analysis.getContents(); + int tmpBeginIndex = ContentsUtil.moveIndexAfterWhitespace(contents, beginIndex + listItem.getDepth()); + // TODO: Automatic fixing, be careful of not breaking list depths + errorResult.addReplacement(contents.substring(tmpBeginIndex, endIndex), false); + errors.add(errorResult); + + return true; + } + + /** + * Automatic fixing of all the errors in the page. + * + * @param analysis Page analysis. + * @return Page contents after fix. + */ + @Override + protected String internalAutomaticFix(PageAnalysis analysis) { + if (!analysis.getPage().isArticle()) { + return analysis.getContents(); + } + return fixUsingAutomaticReplacement(analysis); + } + + /* ====================================================================== */ + /* PARAMETERS */ + /* ====================================================================== */ + + /** Templates that shouldn't be used in list item */ + private static final String PARAMETER_TEMPLATES = "templates"; + + /** + * Initialize settings for the algorithm. + * + * @see org.wikipediacleaner.api.check.algorithm.CheckErrorAlgorithmBase#initializeSettings() + */ + @Override + protected void initializeSettings() { + String tmp = getSpecificProperty(PARAMETER_TEMPLATES, true, true, false); + templateNames.clear(); + if (tmp != null) { + List tmpList = WPCConfiguration.convertPropertyToStringList(tmp); + for (String tmpElement : tmpList) { + templateNames.add(Page.normalizeTitle(tmpElement)); + } + } + } + + /** Templates that shouldn't be used in list item */ + private final List templateNames = new ArrayList<>(); + + /** + * Build the list of parameters for this algorithm. + */ + @Override + protected void addParameters() { + super.addParameters(); + addParameter(new AlgorithmParameter( + PARAMETER_TEMPLATES, + GT._T("Templates that shouldn't be used in list item"), + new AlgorithmParameterElement[] { + new AlgorithmParameterElement( + "templates", + GT._T("Template that shouldn't be used in list item")) + }, + true)); + } +} diff --git a/WikipediaCleaner/src/org/wikipediacleaner/translation/WikiCleaner.pot b/WikipediaCleaner/src/org/wikipediacleaner/translation/WikiCleaner.pot index 4e43c0a8e..bcf37afa0 100644 --- a/WikipediaCleaner/src/org/wikipediacleaner/translation/WikiCleaner.pot +++ b/WikipediaCleaner/src/org/wikipediacleaner/translation/WikiCleaner.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: https://phabricator.wikimedia.org/project/board/4842/\n" -"POT-Creation-Date: 2023-02-28 22:29+0100\n" +"POT-Creation-Date: 2023-03-26 13:05+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -181,7 +181,7 @@ msgstr "" #: org/wikipediacleaner/api/check/algorithm/a0xx/a04x/a042/CheckErrorAlgorithm042_Old.java:64 #: org/wikipediacleaner/api/check/algorithm/a0xx/a04x/a043/CheckErrorAlgorithm043.java:152 #: org/wikipediacleaner/api/check/algorithm/a0xx/a04x/a045/CheckErrorAlgorithm045.java:131 -#: org/wikipediacleaner/api/check/algorithm/a0xx/a04x/a046/CheckErrorAlgorithm046.java:227 +#: org/wikipediacleaner/api/check/algorithm/a0xx/a04x/a046/CheckErrorAlgorithm046.java:228 #: org/wikipediacleaner/api/check/algorithm/a0xx/a04x/a047/CheckErrorAlgorithm047.java:152 #: org/wikipediacleaner/api/check/algorithm/a0xx/a04x/a048/CheckErrorAlgorithm048.java:185 #: org/wikipediacleaner/api/check/algorithm/a5xx/a51x/a515/CheckErrorAlgorithm515.java:103 @@ -1068,7 +1068,7 @@ msgstr "" #: org/wikipediacleaner/api/check/algorithm/a0xx/a09x/a091/CheckErrorAlgorithm091.java:428 #: org/wikipediacleaner/api/data/PageComparator.java:379 #: org/wikipediacleaner/gui/swing/linter/LinterErrorListTableModel.java:234 -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:206 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:209 msgid "Template" msgstr "" @@ -1928,6 +1928,14 @@ msgstr "" msgid "Prefix that can be safely deleted" msgstr "" +#: org/wikipediacleaner/api/check/algorithm/a5xx/a57x/a578/CheckErrorAlgorithm578.java:161 +msgid "Templates that shouldn't be used in list item" +msgstr "" + +#: org/wikipediacleaner/api/check/algorithm/a5xx/a57x/a578/CheckErrorAlgorithm578.java:165 +msgid "Template that shouldn't be used in list item" +msgstr "" + #: org/wikipediacleaner/api/configuration/CWConfiguration.java:83 #, java-format msgid "Fixed using {0}" @@ -2188,7 +2196,7 @@ msgstr "" #: org/wikipediacleaner/api/data/PageComparator.java:241 #: org/wikipediacleaner/gui/swing/RecentChangesTableModel.java:257 -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:212 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:215 msgid "Title" msgstr "" @@ -2789,7 +2797,7 @@ msgstr "" #: org/wikipediacleaner/gui/swing/MainWindow.java:585 #: org/wikipediacleaner/gui/swing/deadlink/DeadLinkListTableModel.java:219 #: org/wikipediacleaner/gui/swing/linter/LinterErrorListTableModel.java:226 -#: org/wikipediacleaner/gui/swing/pagelist/PageListTableModel.java:254 +#: org/wikipediacleaner/gui/swing/pagelist/PageListTableModel.java:241 msgid "Page" msgstr "" @@ -3014,7 +3022,7 @@ msgid "All namespaces" msgstr "" #: org/wikipediacleaner/gui/swing/MainWindow.java:1634 -#: org/wikipediacleaner/gui/swing/pagelist/PageListTableModel.java:244 +#: org/wikipediacleaner/gui/swing/pagelist/PageListTableModel.java:231 msgid "Main" msgstr "" @@ -3347,8 +3355,8 @@ msgid "Page comments - {0}" msgstr "" #: org/wikipediacleaner/gui/swing/PageCommentsWindow.java:122 -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:182 -#: org/wikipediacleaner/gui/swing/pagelist/PageListTableModel.java:250 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:185 +#: org/wikipediacleaner/gui/swing/pagelist/PageListTableModel.java:237 msgid "Comments" msgstr "" @@ -4678,135 +4686,135 @@ msgstr "" msgid "Select editor font size" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:143 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:146 msgid "Select other font name" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:158 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:161 msgid "Increase font size" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:188 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:191 msgid "Internal link" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:194 -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:296 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:197 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:299 msgid "Redirect link" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:200 -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:302 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:203 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:305 msgid "Missing link" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:218 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:221 msgid "Image" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:224 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:227 msgid "Category" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:230 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:233 msgid "Default sort" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:236 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:239 msgid "Language link" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:242 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:245 msgid "External link" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:248 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:251 msgid "Interwiki link" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:254 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:257 msgid "Tag" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:260 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:263 msgid "List items" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:266 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:269 msgid "Table" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:272 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:275 msgid "Reference" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:278 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:281 msgid "Programming elements" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:284 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:287 msgid "Disambiguation link" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:290 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:293 msgid "Normal internal link" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:308 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:311 msgid "Disambiguation template" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:314 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:317 msgid "Normal template" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:320 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:323 msgid "Help requested" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:326 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:329 msgid "Check wiki error" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:332 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:335 msgid "Check wiki warning" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:338 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:341 msgid "Check wiki OK" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:449 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:452 msgid "Italic" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:457 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:460 msgid "Bold" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:465 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:468 msgid "Underline" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:473 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:476 msgid "Strike through" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:481 -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:486 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:484 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:489 msgid "Foreground color" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:485 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:488 msgid "Choose foreground color" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:494 -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:499 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:497 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:502 msgid "Background color" msgstr "" -#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:498 +#: org/wikipediacleaner/gui/swing/options/FormattingOptionsPanel.java:501 msgid "Choose background color" msgstr "" @@ -5031,7 +5039,7 @@ msgstr "" msgid "Translate templates without parameters" msgstr "" -#: org/wikipediacleaner/gui/swing/pagelist/PageListTableModel.java:248 +#: org/wikipediacleaner/gui/swing/pagelist/PageListTableModel.java:235 msgid "Other" msgstr ""