Skip to content

Commit 45c2614

Browse files
committed
Start of version 0.2
Addition of search on MediaWiki.org via context menus
1 parent f105082 commit 45c2614

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

META-INF/plugin.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin version="2">
22
<id>org.mediawiki</id>
33
<name>MediaWiki Support</name>
4-
<version>0.1</version>
4+
<version>0.2</version>
55
<vendor email="[email protected]" url="https://github.com/reedy/phpstorm-plugin-mediawiki">Sam Reed (reedy)</vendor>
66

77
<description><![CDATA[
@@ -13,6 +13,11 @@
1313

1414
<change-notes><![CDATA[
1515
<p>
16+
<strong>Version 0.2</strong>
17+
<ul>
18+
<li>Search on MediaWiki.org on context menu with selected text</li>
19+
</ul>
20+
1621
<strong>Version 0.1</strong>
1722
<ul>
1823
<li>Initial version</li>
@@ -30,6 +35,7 @@
3035
<idea-version since-build="131"/>
3136

3237
<depends>com.jetbrains.php</depends>
38+
<depends>com.intellij.modules.ultimate</depends>
3339

3440
<extensions defaultExtensionNs="com.intellij">
3541
<predefinedCodeStyle implementation="org.mediawiki.MediaWikiPhpPredefinedCodeStyle"/>
@@ -46,7 +52,12 @@
4652
</project-components>
4753

4854
<actions>
49-
<!-- Add your actions here -->
55+
<action id="org.mediawiki.MediaWikiSearchDocsAction" class="org.mediawiki.MediaWikiSearchDocsAction"
56+
text="Search on MediaWiki.org"
57+
description="Search on MediaWiki.org">
58+
<add-to-group group-id="EditorPopupMenu" relative-to-action="$SearchWeb" anchor="after"/>
59+
<add-to-group group-id="ConsoleEditorPopupMenu" relative-to-action="$SearchWeb" anchor="after"/>
60+
</action>
5061
</actions>
5162

5263
</idea-plugin>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This program is free software; you can redistribute it and/or
3+
* modify it under the terms of the GNU General Public License
4+
* as published by the Free Software Foundation; either version 2
5+
* of the License, or (at your option) any later version.
6+
*
7+
* This program is distributed in the hope that it will be useful,
8+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
* GNU General Public License for more details.
11+
*
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program; if not, write to the Free Software
14+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15+
*/
16+
17+
package org.mediawiki;
18+
19+
import com.intellij.ide.BrowserUtil;
20+
import com.intellij.openapi.actionSystem.AnAction;
21+
import com.intellij.openapi.actionSystem.AnActionEvent;
22+
import com.intellij.openapi.actionSystem.CommonDataKeys;
23+
import com.intellij.openapi.editor.Editor;
24+
import com.intellij.openapi.util.text.StringUtil;
25+
import org.jetbrains.annotations.NonNls;
26+
import org.jetbrains.annotations.NotNull;
27+
import org.jetbrains.annotations.Nullable;
28+
29+
import java.io.UnsupportedEncodingException;
30+
import java.net.URLEncoder;
31+
32+
/**
33+
* @author Reedy
34+
*/
35+
public class MediaWikiSearchDocsAction extends AnAction {
36+
public void update(AnActionEvent event) {
37+
boolean enabled = getSelectedText(event) != null;
38+
event.getPresentation().setEnabled(enabled);
39+
event.getPresentation().setVisible(enabled);
40+
}
41+
42+
@Nullable
43+
private static String getSelectedText(AnActionEvent e) {
44+
Editor editor = e.getData(CommonDataKeys.EDITOR);
45+
if (editor == null) {
46+
return null;
47+
}
48+
String selectedText = editor.getSelectionModel().getSelectedText();
49+
return StringUtil.nullize(selectedText, true);
50+
}
51+
52+
public void actionPerformed(AnActionEvent event) {
53+
String selectedText = getSelectedText(event);
54+
if (selectedText == null) {
55+
return;
56+
}
57+
BrowserUtil.browse(getSearchUrl(selectedText));
58+
}
59+
60+
@NonNls
61+
private static String getSearchUrl(@NotNull String textToSearch) {
62+
try {
63+
return "https://www.mediawiki.org/w/index.php?title=Special%3ASearch&profile=default&fulltext=Search&search=" + URLEncoder.encode(textToSearch, "UTF-8");
64+
} catch (UnsupportedEncodingException e) {
65+
}
66+
return "";
67+
}
68+
}

0 commit comments

Comments
 (0)