JetBrains 統合開発環境
For our Open Source work, the Wikimedia Foundation (and the community) received a number of licenses for the All Products Pack of JetBrains (in doing it, we're thanking JetBrains for the support of our projects). The licenses allows an attached user to use all JetBrains desktop products, as described on the JetBrains website (Get access to all desktop products including IntelliJ IDEA Ultimate, ReSharper Ultimate and other IDEs).[1] JetBrains の製品 (IntelliJ IDEA Ultimate や PhpStorm など) を使用して、MediaWiki や MediaWiki 拡張のオープン ソース コードを貢献する場合は、アカウント管理者のいずれかにライセンス キーを申請することを検討してください。
How do I get a license?
For staff, see https://office.wikimedia.org/wiki/JetBrains.
ライセンスの申請は、メールを書くか、IRC 経由でアカウント管理者の 1 人に連絡するだけです:
- Sam Reed (reedy in #wikimedia-dev 接続, sreed [AT] wikimedia [DOT] org)
- Florian Schmidt (FlorianSW in #wikimedia-dev 接続, florian.schmidt.stargatewissen [AT] gmail [DOT] com)
このリンクをクリックすると、JetBrains のアカウントにライセンスが接続されます (まだアカウントをお持ちでない場合は、作成する必要があります)。 Please note that we have a limited number of licenses only, and even if we're sure that you can get a license, we want to make sure that the people who actively contribute code to one of our projects can benefit from the license. This means that we'll check if you're an active contributor to one of our projects before sending you an invitation link. There are no big things you need to accomplish (such as a specific amount of changes per day or something else, that would be ridiculous, as we're thankful for anything you do for our projects!). However, if you've never contributed code to our projects or your last change was a reasonable time ago (e.g. over a year or so), we may ask you some questions (e.g. "Why do you want a license?"). But don't hesitate and simply ask us if you can get a license :)
What product should I use?
Like mentioned above, the MediaWiki open source project owns licenses for the All products pack of JetBrains, which includes all desktop products (like PhpStorm, IntelliJ IDEA Ultimate, Webstorm and so on). Some products share some functionality, so it can be difficult to choose the correct product. You probably heard from this page because someone suggested you to use PhpStorm. Even if this isn't false, and PhpStorm is a good product, we would like to encourage you to choose the IntelliJ IDEA Ultimate, which includes some more features and language support compared to PhpStorm. If you plan to contribute to projects other than the PHP-based ones in MediaWiki, it probably would be a benefit, that you already use the "non-plus-ultra" product. However, as all products are included anyway, you can choose the product you like the most, if you have one.
If you wish to test bleeding edge features, IntelliJ IDEA Ultimate and other standalone products have separate release rhythms. Installing PhpStorm or WebStorm separately has its benefits.
MediaWiki code style
MediaWiki has its own and specific code style for PHP, JavaScript, JSON and some other languages. The JetBrains products allow you to define all of your coding conventions in the project settings so that the IDE supports you as best as it can, e.g. by automatically format the code you write.
The following XML code is a snapshot of the settings of the coding convention for PHP, JSON, JavaScript and LESS. It may be incomplete and miss some other languages. So if you want to extend it, feel free to simply add the settings for the coding convention. If you want to import the settings, please copy the code and save it as a file on your computer. Then import the settings in the JetBrains IDE ("Import Scheme" from the gear icon next to Settings > Editor > Code Style > Scheme).
Expand to see XML |
---|
<code_scheme name="MediaWiki" version="173">
<option name="LINE_SEPARATOR" value=" " />
<PHPCodeStyleSettings>
<option name="COMMA_AFTER_LAST_ARRAY_ELEMENT" value="true" />
<option name="BLANK_LINES_BEFORE_RETURN_STATEMENT" value="1" />
<option name="KEEP_RPAREN_AND_LBRACE_ON_ONE_LINE" value="true" />
<option name="SPACE_AROUND_ASSIGNMENT_IN_DECLARE" value="true" />
</PHPCodeStyleSettings>
<codeStyleSettings language="JSON">
<indentOptions>
<option name="INDENT_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JavaScript">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
<option name="SMART_TABS" value="true" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="LESS">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="PHP">
<option name="RIGHT_MARGIN" value="100" />
<option name="KEEP_LINE_BREAKS" value="false" />
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
<option name="CLASS_BRACE_STYLE" value="1" />
<option name="METHOD_BRACE_STYLE" value="1" />
<option name="CATCH_ON_NEW_LINE" value="true" />
<option name="ALIGN_MULTILINE_FOR" value="false" />
<option name="SPACE_AROUND_UNARY_OPERATOR" value="true" />
<option name="SPACE_WITHIN_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_METHOD_CALL_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_METHOD_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_IF_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_WHILE_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_FOR_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_CATCH_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_SWITCH_PARENTHESES" value="true" />
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" />
<option name="CALL_PARAMETERS_WRAP" value="1" />
<option name="METHOD_PARAMETERS_WRAP" value="1" />
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
<option name="EXTENDS_LIST_WRAP" value="1" />
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
<option name="PARENTHESES_EXPRESSION_RPAREN_WRAP" value="true" />
<option name="BINARY_OPERATION_WRAP" value="1" />
<option name="TERNARY_OPERATION_WRAP" value="5" />
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
<option name="FOR_STATEMENT_WRAP" value="1" />
<option name="FOR_STATEMENT_RPAREN_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_WRAP" value="5" />
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
<option name="ASSIGNMENT_WRAP" value="5" />
<option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" />
<option name="WRAP_ON_TYPING" value="1" />
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
|
With this, you can auto-format your code to conform to the standards. To do this, select "Reformat Code" from the Code menu.
Code sniffer integration
You can also integrate PHP Codesniffer (PHPCS) into PhpStorm and similar products, so that phpcs errors will be shown in real-time. Assuming you're working within the root of the core MediaWiki project (from which you can also work on extensions):
- Go to Settings > PHP > Quality Tools -> Code Sniffer.
- Next to "Configuration" click on the "...", opening up the Code Sniffer panel.
- Click on "...", and browse to the vendor/bin directory and select phpcs. Click on "Validate" to ensure the binary loads properly.
- Go to Settings > Inspections and look for "PHP Code Sniffer validation" under PHP.
- Select "Custom" as the "Coding standard", then from "..." choose the ruleset.xml file that's located in vendor/mediawiki/mediawiki-codesniffer/MediaWiki.
MediaWiki-Vagrant users specific
This replaces step 3 from the section above.
- Create a code sniffer configuration by clicking on "+" in the Code Sniffer panel.
- Select the Remote PHP interpreter as setup for MediaWiki-Vagrant, check Manual:How to debug/with MediaWiki-Vagrant and PHPStorm and MediaWiki-Vagrant/Advanced usage#PhpStorm if you haven't yet.
- Select /vagrant/mediawiki/vendor/bin/phpcs as the PHP Code Sniffer path.
Using PHPStorm with a test server
-
Connect with WinScp
-
Set up port forwarding (for instance port 2224)
-
Test the connection using putty
-
The authentification requires your public key
-
Now you can connect to your new instance using the forwarded port (i.e. localhost:2224)
-
Open your PhpStorm settings
-
Search for the deployment option
-
Test
-
should return success
-
check the mappings
-
configure upload on Ctrl+S
-
Test creating a new file
-
Specificy the filename
-
... and type ...
-
... no need to add the file to git ...
-
hitting Ctrl+S uploads the instance
-
locate the created file on the instance
-
and check the content (optional)
Running unit tests
- Go to Settings > Languages & Frameworks > PHP > Test frameworks
- Set default configuration file as mediawiki/phpunit.xml (a sample phpunit.xml.dist is part of the repo — create your phpunit.xml by copying it if you haven't already).
Set up database GUI
- If you're using a Docker or Vagrant installation, ensure that your database has its port exposed to the host (not applicable if SQLite is used)
- Open the "Database" toolbar in IntelliJ.
- Create a project data source, by filling in the credentials (host, port, username and password) to connect to the database.
Now, you should be able to browse database contents using the GUI.
Gerrit plugin
There's a third-party plugin for downloading and reviewing Gerrit changes, https://plugins.jetbrains.com/plugin/7272-gerrit. To configure, go to Settings -> Version control -> Gerrit, and set:
- Web-URL: https://gerrit.wikimedia.org/r/
- Login: your Gerrit username, e.g. "awight"
- Password: your HTTPS password for Gerrit
- Be sure to check "List all Gerrit changes", otherwise you will encounter a 414 error when the plugin tries to download all available projects in one request.
Phab and gerrit linking
References to phab tickets and gerrit patches (in the code or in commit messages on IntelliJ's git GUI) can be made clickable:
- Go to Preferences > Version Control > Issue Navigation
- Add the following configurations:
(T\d+)
→https://phabricator.wikimedia.org/$1
(I[0-9a-f]{6,})
→https://gerrit.wikimedia.org/r/q/$1