Skip to content

Commit

Permalink
Fix for special chars in file name upon article fetch.
Browse files Browse the repository at this point in the history
  • Loading branch information
drewmutt committed May 13, 2017
1 parent 4e30fe3 commit ed16914
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 23 deletions.
5 changes: 2 additions & 3 deletions out/production/wikimedia/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin version="2">
<id>org.wikipedia.tools.puggle</id>
<name>Puggle</name>
<version>0.7a</version>
<version>0.9a</version>
<vendor email="[email protected]" url="http://www.wikipedia.org">YourCompany</vendor>

<description><![CDATA[
Expand All @@ -17,9 +17,7 @@

<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<!-- uncomment to enable plugin in all products
<depends>com.intellij.modules.lang</depends>
-->

<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
Expand All @@ -38,6 +36,7 @@
<completion.contributor language="MediaWiki" implementationClass="com.mwplugin.MediaWikiCompletionContributor"/>
<lang.braceMatcher language="MediaWiki" implementationClass="com.mwplugin.MediaWikiPairedBraceMatcher"/>
<editorTypedHandler implementationClass="com.mwplugin.bracematching.TagMatchTypedActionHandler"/>
<lang.commenter language="MediaWiki" implementationClass="com.mwplugin.MediaWikiCommenter"/>
</extensions>


Expand Down
Binary file modified out/production/wikimedia/com/mwplugin/MediaWikiLexer.class
Binary file not shown.
35 changes: 19 additions & 16 deletions out/production/wikimedia/com/mwplugin/mediawiki.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
tablestart = "{|"
tableend = "|}"
tableheaderdoubledelimiter = "!!"
tablecelldoubledelimiter = "||"
doublepipe = "||"
htmlcommentopen = "<!--"
htmlcomentclose = "-->"
htmlcommentclose = "-->"
openbracket = "["
closebracket = "]"
refopencomplete = "<ref>"
refopen = "<ref"
refclose = "</ref>"
htmltagselfclose = "/>"
openbracket2 = "[["
closebracket2 = "]]"
newline='regexp:[\r\n]'
Expand Down Expand Up @@ -183,7 +184,7 @@ symbol ::=
underscore|
"."|
","|
"("|")"|"-"|":"|"#"|"/"|"'"|";"|"|"|"–"|doublequote|"!"|"%"|"?"|"_"|"—"|"+"|"$"|"~"|"·"|"’"|equals|"†"|"½"|"*"|"@"|"−"|"‘"|"^"|"ᴥ"|"•"|"…"
"("|")"|"-"|":"|"#"|"/"|"'"|";"|"|"|"–"|doublequote|"!"|"%"|"?"|"_"|"—"|"+"|"$"|"~"|"·"|"’"|equals|"†"|"½"|"*"|"@"|"−"|"‘"|"^"|"ᴥ"|"•"|"…"|"`"|tableheaderdoubledelimiter|"“"|"”"|htmltagselfclose
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -537,7 +538,7 @@ link ::=
}

internal-link ::=
internal-link-start article-link ("#" section-id)? ("|" (internal-link-property | internal-link-unassigned-property))* internal-link-end extra-description?
internal-link-start article-link ("#" section-id)? (("|"|doublepipe) (internal-link-property | internal-link-unassigned-property))* internal-link-end extra-description?
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -961,12 +962,12 @@ media-extension ::=
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

html-tag ::= "<!" html-tag-name html-tag-properties? ((">" html-tag-content html-tag-close)|"/>")
html-tag ::= ("<!" html-tag-name html-tag-properties? ((">" html-tag-content html-tag-close)|"/>")) | html-tag-linebreak
html-tag-close ::= "</" html-tag-name ">"
html-tag-properties ::= (!">" (letter | decimaldigit | symbol | whitespace))*
html-tag-name ::= (letter | decimaldigit)+
html-tag-content ::= paragraph

html-tag-linebreak ::= "<br" whitespace? "/>"

text-with-formatting ::=
formatted-text |
Expand Down Expand Up @@ -1008,19 +1009,19 @@ bold-text ::=
}

italic-text ::=
quote2 inline-text quote2
quote2 inline-text (quote2|quote3)
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

noparse-block ::=
html-comment|
nowiki-block|
html-block|
reference-block|
// math-block|
pre-block|
html-comment
pre-block
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -1087,13 +1088,13 @@ named-reference-block-url ::=
}

named-reference-block-self-closing ::=
reference-opening-tag whitespace? (("name" | "group") whitespace? "=" property-assignment)+ "/" unescapedgreaterthan
reference-opening-tag whitespace? (("name" | "group") whitespace? "=" property-assignment)+ htmltagselfclose
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

reference-content ::= paragraph-and-more
reference-content ::= 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 All @@ -1120,6 +1121,8 @@ html-opening-tag ::=
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}



reference-opening-tag-complete ::=
refopencomplete

Expand Down Expand Up @@ -1179,7 +1182,7 @@ pre-closing-tag ::=
}

html-comment ::=
htmlcommentopen whitespace? paragraph whitespace? htmlcommentclose
htmlcommentopen whitespace? all-inline-elements* whitespace? htmlcommentclose
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down Expand Up @@ -1257,7 +1260,7 @@ plain-text ::=
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

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

unicode-wiki ::=
letter |
Expand Down Expand Up @@ -1398,7 +1401,7 @@ bullet-item ::=
}

table ::=
table-start (space table-parameters)? (table-block)* newline? table-end
table-start (space? table-parameters)? (table-block)* newline? table-end
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand All @@ -1412,7 +1415,7 @@ table-parameters ::=
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

table-cell-double-delimited-start ::= tablecelldoubledelimiter
table-cell-double-delimited-start ::= doublepipe
table-cell-double-delimited ::= table-cell-double-delimited-start cell-content newline?
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
Expand Down Expand Up @@ -1490,7 +1493,7 @@ cell-formatting ::= cell-content
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}

cell-content ::= ((!tableheaderdoubledelimiter !tablecelldoubledelimiter !(newline whitespace? (tablesectionstart | tablesectionstartcaptionable))) (!(newline whitespace? "|}")) !(newline whitespace? "|") (!(newline whitespace? "!")) all-inline-elements)*
cell-content ::= ((!tableheaderdoubledelimiter !doublepipe !(newline whitespace? (tablesectionstart | tablesectionstartcaptionable))) (!(newline whitespace? "|}")) !(newline whitespace? "|") (!(newline whitespace? "!")) all-inline-elements)*
{
mixin="com.mwplugin.psi.impl.MediaWikiNamedElementImpl"
implements="com.mwplugin.psi.IMediaWikiNamedElement"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified out/production/wikimedia/com/mwplugin/psi/MediaWikiTypes.class
Binary file not shown.
Binary file modified out/production/wikimedia/com/mwplugin/psi/MediaWikiVisitor.class
Binary file not shown.
2 changes: 1 addition & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin version="2">
<id>org.wikipedia.tools.puggle</id>
<name>Puggle</name>
<version>0.7a</version>
<version>0.9a</version>
<vendor email="[email protected]" url="http://www.wikipedia.org">YourCompany</vendor>

<description><![CDATA[
Expand Down
14 changes: 14 additions & 0 deletions src/com/mwplugin/MediaWikiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,18 @@ public static List<MediaWikiProperty> findProperties(Project project)
}
return result;
}*/

public static String sanitizeFileName(String fileName)
{
fileName = fileName.replace("<", "");
fileName = fileName.replace(">", "");
fileName = fileName.replace(":", "");
fileName = fileName.replace("\"", "");
fileName = fileName.replace("/", "");
fileName = fileName.replace("\\", "");
fileName = fileName.replace("|", "");
fileName = fileName.replace("?", "");
fileName = fileName.replace("*", "");
return fileName;
}
}
4 changes: 3 additions & 1 deletion src/com/mwplugin/actions/OpenWikipediaArticleAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.io.IOException;
import java.util.Objects;

import static com.intellij.openapi.util.io.FileUtil.sanitizeFileName;
import static com.mwplugin.api.WPApiManager.getPageContent;
import static com.mwplugin.psi.MediaWikiElementFactory.createFile;

Expand Down Expand Up @@ -90,7 +91,8 @@ public void actionPerformed(AnActionEvent e)
}

String fileName = templateDialog.selectedArticle.getName();

fileName = sanitizeFileName(fileName);
fileName = fileName.replace("_", " "); //Because I like spaces!
ScratchFileService.Option option = ScratchFileService.Option.create_if_missing;
VirtualFile f = ScratchRootType.getInstance().createScratchFile(e.getProject(), PathUtil.makeFileName(fileName, "mediawiki"), MediaWikiLanguage.INSTANCE, content, option);
if (f != null) {
Expand Down
20 changes: 18 additions & 2 deletions src/com/mwplugin/dialogs/InsertTemplate.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.mwplugin.dialogs;

import com.intellij.codeInsight.completion.InsertHandler;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.editor.event.DocumentListener;
import com.intellij.openapi.project.Project;
Expand Down Expand Up @@ -79,7 +82,19 @@ protected String getLookupString(@NotNull Article item)
return item.getName();
}


@Nullable
@Override
protected InsertHandler<LookupElement> createInsertHandler(@NotNull Article item)
{
return new InsertHandler<LookupElement>()
{
@Override
public void handleInsert(InsertionContext context, LookupElement item)
{
_textField.setText(item.getLookupString());
}
};
}
};


Expand All @@ -103,9 +118,10 @@ protected String getLookupString(@NotNull Article item)
@Override
public void beforeDocumentChange(DocumentEvent event)
{
System.out.println("asdsa");

}


@Override
public void documentChanged(DocumentEvent event)
{
Expand Down
2 changes: 2 additions & 0 deletions src/com/mwplugin/mediawiki.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,8 @@ html-opening-tag ::=
implements="com.mwplugin.psi.IMediaWikiNamedElement"
}



reference-opening-tag-complete ::=
refopencomplete

Expand Down

0 comments on commit ed16914

Please sign in to comment.