Skip to content

Commit

Permalink
Added "replacing bare ref with citation template" and added "combine …
Browse files Browse the repository at this point in the history
…duplicate references" quick fixes and inspections. Granted this kinda broke pseudo-legit [external links]
  • Loading branch information
drewmutt committed May 17, 2017
1 parent 8cc3ca0 commit 937e723
Show file tree
Hide file tree
Showing 23 changed files with 556 additions and 170 deletions.
42 changes: 35 additions & 7 deletions gen/com/mwplugin/parser/MediaWikiParser.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion out/production/wikimedia/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
<group id="MediaWiki.Actions" text="_Puggle" description="Puggle">
<add-to-group group-id="MainMenu" anchor="last" />
<action id="com.whatever" class="com.mwplugin.actions.OpenWikipediaArticleAction" text="Open Wikipedia Article" description="Open the source of an article on Wikipedia"/>
<action id="com.mwplugin.actions.ReplaceURLWithCitationAction"
class="com.mwplugin.actions.ReplaceURLWithCitationAction" text="Replace URL With Citation"
description="Replace URL With Citation from Citoid"/>
</group>

</actions>


Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/wikimedia/com/mwplugin/MediaWikiAnnotator.class
Binary file not shown.
6 changes: 3 additions & 3 deletions out/production/wikimedia/com/mwplugin/mediawiki.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ external-link ::=
methods=[getPresentation]
}

url ::= LEGAL_URL_ENTITY+//protocol url-path
url ::= protocol LEGAL_URL_ENTITY+//protocol url-path
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -1107,7 +1107,7 @@ named-reference-block-self-closing ::=
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

reference-content ::= all-inline-elements*
reference-content ::= url? all-inline-elements*

//Don't need quotes unless you have whitespace
property-assignment ::= (whitespace? doublequote? reference-name doublequote? whitespace?)//|(whitespace? doublequote reference-name whitespace doublequote whitespace?)
Expand Down Expand Up @@ -1273,7 +1273,7 @@ plain-text ::=
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

friendly-ref-link-char ::= ("!"|"$"|"%"|"&"|"("|")"|"*"|","|"-"|"."|":"|";"|"<"|"@"|"["|"]"|"^"|"_"|"`"|"{"|"|"|"}"|"~"|letter|decimaldigit|"–"|"'"|"/"|template-block|"?")
friendly-ref-link-char ::= ("!"|"$"|"%"|"&"|"("|")"|"*"|","|"-"|"."|":"|";"|"<"|"@"|"["|"]"|"^"|"_"|"`"|"{"|"|"|"}"|"~"|letter|decimaldigit|"–"|"'"|"/"|template-block|"?"|"’")

unicode-wiki ::=
letter |
Expand Down
Binary file modified out/production/wikimedia/com/mwplugin/parser/MediaWikiParser.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 5 additions & 3 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<idea-plugin version="2">
<id>org.wikipedia.tools.puggle</id>
<name>Puggle</name>
<version>0.9a</version>
<version>0.11a</version>
<vendor email="[email protected]" url="http://www.wikipedia.org">YourCompany</vendor>

<description><![CDATA[
A smart editor for editting MediaWiki
A smart editor for editing MediaWiki
]]></description>

<change-notes><![CDATA[
Expand Down Expand Up @@ -44,8 +44,10 @@
<group id="MediaWiki.Actions" text="_Puggle" description="Puggle">
<add-to-group group-id="MainMenu" anchor="last" />
<action id="com.whatever" class="com.mwplugin.actions.OpenWikipediaArticleAction" text="Open Wikipedia Article" description="Open the source of an article on Wikipedia"/>
<action id="com.mwplugin.actions.ReplaceURLWithCitationAction"
class="com.mwplugin.actions.ReplaceURLWithCitationAction" text="Replace URL With Citation"
description="Replace URL With Citation from Citoid"/>
</group>

</actions>


Expand Down
122 changes: 0 additions & 122 deletions src/com/mwplugin/CreatePropertyQuickFix.java

This file was deleted.

68 changes: 67 additions & 1 deletion src/com/mwplugin/MediaWikiAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.containers.HashMap;
import com.mwplugin.psi.*;
import com.mwplugin.quickfix.CombineDuplicateReferencesQuickFix;
import com.mwplugin.quickfix.ConvertUrlToCitationQuickFix;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;

public class MediaWikiAnnotator implements Annotator
{
Expand Down Expand Up @@ -79,6 +85,66 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
// List<MediaWikiProperty> properties = MediaWikiUtil.findProperties(project, key);
// if (properties.size() == 1)
// {

if(element instanceof MediaWikiReferenceBlock)
{
MediaWikiReferenceBlock referenceBlock = (MediaWikiReferenceBlock) element;
MediaWikiTemplateBlock innerTemplateBlock = PsiTreeUtil.findChildOfAnyType(referenceBlock, MediaWikiTemplateBlock.class);
MediaWikiUrl innerUrlBlock = PsiTreeUtil.findChildOfAnyType(referenceBlock, MediaWikiUrl.class);

if(innerTemplateBlock == null && innerUrlBlock != null)
{
TextRange range = new TextRange(element.getTextRange().getStartOffset(), element.getTextRange().getEndOffset());
holder.createWeakWarningAnnotation(range, "Can use cite template").registerFix(new ConvertUrlToCitationQuickFix(innerUrlBlock));
}

MediaWikiFile mediaWikiFile = PsiTreeUtil.getParentOfType(element, MediaWikiFile.class);
Collection<MediaWikiReferenceBlock> references = PsiTreeUtil.findChildrenOfAnyType(mediaWikiFile, MediaWikiReferenceBlock.class);

ArrayList<MediaWikiReferenceBlock> duplicateRefs = new ArrayList<>();
MediaWikiReferenceContent refBlockContent = PsiTreeUtil.findChildOfAnyType(referenceBlock, MediaWikiReferenceContent.class);
if(refBlockContent != null)
{
String refBlockContentString = refBlockContent.getText();
for (MediaWikiReferenceBlock refBlock : references)
{
// if (refBlock != referenceBlock)
// {
MediaWikiReferenceContent thisRefContent = PsiTreeUtil.findChildOfAnyType(refBlock, MediaWikiReferenceContent.class);
if(thisRefContent != null)
{
String refContent = thisRefContent.getText();
if (Objects.equals(refContent, refBlockContentString))
{
duplicateRefs.add(refBlock);
}
}
// }
}
}

//We're expecting to have yourself in there
if(duplicateRefs.size() > 1)
{

for (MediaWikiReferenceBlock ref : duplicateRefs)
{
if(ref != referenceBlock)
{
TextRange range = new TextRange(ref.getTextRange().getStartOffset(), ref.getTextRange().getEndOffset());
holder.createWeakWarningAnnotation(range, "Duplicate Reference").registerFix(new CombineDuplicateReferencesQuickFix(duplicateRefs));
}
}
// TextRange range = new TextRange(element.getTextRange().getStartOffset(), element.getTextRange().getEndOffset());
// holder.createWeakWarningAnnotation(range, "Duplicate Reference").registerFix(new ConvertUrlToCitationQuickFix(innerUrlBlock));
}


}




for (Map.Entry<Class, TextAttributesKey> entry : keysMap.entrySet())
{
if(entry.getKey().isInstance(element))
Expand Down Expand Up @@ -128,7 +194,7 @@ public void annotate(@NotNull PsiElement element, @NotNull AnnotationHolder hold
// {
// TextRange range = new TextRange(element.getTextRange().getStartOffset() + 8, element.getTextRange().getEndOffset());
// holder.createErrorAnnotation(range, "Unresolved property").
// registerFix(new CreatePropertyQuickFix(key));
// registerFix(new ConvertUrlToCitationQuickFix(key));
// }
}

Expand Down
Loading

0 comments on commit 937e723

Please sign in to comment.