Manual:Shell.php/ja: Difference between revisions
Appearance
Content deleted Content added
Created page with "これは、[http://psysh.org/ PsySH]に基づいています。これは、より堅牢でなく、より少ない機能を持つ置き換えられます。" Tag: Reverted |
Created page with "=== デバッグ出力 ===" |
||
| (14 intermediate revisions by 5 users not shown) | |||
| Line 2: | Line 2: | ||
{{MW file|shell.php|maintenance/|class1=MediaWikiShell}} |
{{MW file|shell.php|maintenance/|class1=MediaWikiShell}} |
||
$file は、<code>maintenance</code> ディレクトリにある[[Special:MyLanguage/Manual:Maintenance scripts|メンテナンス スクリプト]]であり、MediaWiki のオブジェクトや関数を試すために使用できます。 |
$file は、<code>maintenance</code> ディレクトリにある[[Special:MyLanguage/Manual:Maintenance scripts|メンテナンス スクリプト]]であり、MediaWiki のオブジェクトや関数を試すために使用できます。 |
||
<span lang="en" dir="ltr" class="mw-content-ltr">It is based on [http://psysh.org/ PsySH]; it replaces {{ll|Manual:Eval.php|eval.php}} which is less robust and has fewer features.</span> |
|||
これは、[http://psysh.org/ PsySH]に基づいています。これは、より堅牢でなく、より少ない機能を持つ置き換えられます。 |
|||
Beyond the ability to evaluate PHP statements, functionality includes handling errors and fatals in a way that does not break the shell, examining object internals, source code and documentation via reflection, external editor integration and more. |
<span lang="en" dir="ltr" class="mw-content-ltr">Beyond the ability to evaluate PHP statements, functionality includes handling errors and fatals in a way that does not break the shell, examining object internals, source code and documentation via reflection, external editor integration and more.</span> |
||
<span id="Usage"></span> |
|||
| ⚫ | |||
== 使用法 == |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">Interactively: <code>php maintenance/run.php shell</code></span><br /> |
|||
<span lang="en" dir="ltr" class="mw-content-ltr">Executing PHP commands from a file: <code>cat commands.txt | maintenance/run.php shell</code></span> |
|||
<span id="Options"></span> |
|||
=== オプション === |
|||
{| class="wikitable" |
|||
! width="20%" | <span lang="en" dir="ltr" class="mw-content-ltr">Option</span> !! <span lang="en" dir="ltr" class="mw-content-ltr">Description</span> |
|||
|- |
|||
| --log-channels || <span lang="en" dir="ltr" class="mw-content-ltr">Print logs sent to the given [[Special:MyLanguage/Manual:$wgDebugLogGroups|log channels]]. Comma-separated: <code>--log-channels authentication,cookie,session</code> Log levels can be filtered with <code>--log-channels authentication,cookie:info,session:error</code></span> |
|||
|- |
|||
| --log-all || <span lang="en" dir="ltr" class="mw-content-ltr">Print logs sent to all channels</span> |
|||
|- |
|||
| --dbo-debug || <span lang="en" dir="ltr" class="mw-content-ltr">Log more database-related information (roughly the same as setting {{wg|DebugDumpSql}})</span> |
|||
|- |
|||
| --no-session || <span lang="en" dir="ltr" class="mw-content-ltr">Pretend <code>MW_NO_SESSION</code> has been set (useful for debugging code that's invoked from no-session endpoints such as <code>load.php</code></span>) |
|||
|} |
|||
<span id="Examples"></span> |
|||
| ⚫ | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
=== Command execution and error handling === |
=== Command execution and error handling === |
||
</div> |
|||
<pre style="overflow:auto;"> |
<pre style="overflow:auto;"> |
||
$ php maintenance/ |
$ php maintenance/run.php shell |
||
Psy Shell v0. |
Psy Shell v0.12.2 (PHP 7.4.33 — cli) by Justin Hileman |
||
> MW::user('Admin') |
|||
= |
= MediaWiki\User\User {#5704 |
||
+mId: 1, |
|||
+mName: "Admin", |
|||
+mActorId: 1, |
|||
+mRealName: "", |
|||
+mEmail: "admin@local.wmftest.net", |
|||
+mTouched: "20240114073920", |
|||
+mEmailAuthenticated: "20010101000000", |
|||
+mOptionsLoaded: false, |
|||
+mFrom: "id", |
|||
mId: 1, |
|||
mName: "Admin", |
|||
mActorId: 1, |
|||
mRealName: "", |
|||
mEmail: "admin@local.wmftest.net", |
|||
+mBlock: null, |
|||
mTouched: "20240114073920", |
|||
| ⚫ | |||
mEmailAuthenticated: "20010101000000", |
|||
mFrom: "id", |
|||
| ⚫ | |||
> // use $_ for previous return value |
|||
> $_->mQuickTouched |
|||
PHP Error: Cannot access protected property User::$mQuickTouched in Psy Shell code on line 2 |
PHP Error: Cannot access protected property User::$mQuickTouched in Psy Shell code on line 2 |
||
> sudo $_->mQuickTouched |
|||
= |
= null |
||
> User::newFromIdentity(0) |
|||
TypeError Argument 1 passed to MediaWiki\User\User::newFromIdentity() must implement interface MediaWiki\User\UserIdentity, int given, called on line 2. |
|||
InvalidArgumentException with message '$text must be a string.' |
|||
> wtf |
|||
TypeError Argument 1 passed to MediaWiki\User\User::newFromIdentity() must implement interface MediaWiki\User\UserIdentity, int given, called on line 2. |
|||
InvalidArgumentException with message '$text must be a string.' |
|||
-- |
-- |
||
0: () at includes/ |
0: () at includes/user/User.php:652 |
||
1: MediaWiki\User\User::newFromIdentity() at eval()'d code:2 |
|||
1: Title::newFromText() at includes/user/User.php:1255 |
|||
2: |
2: eval() at vendor/psy/psysh/src/ExecutionLoopClosure.php:52 |
||
Use wtf -a to see |
Use wtf -a to see 8 more lines |
||
</pre> |
</pre> |
||
= |
<span id="Reflection"></span> |
||
=== リフレクション === |
|||
<pre style="overflow:auto;"> |
<pre style="overflow:auto;"> |
||
> ls Message |
|||
Class Constants: FORMAT_BLOCK_PARSE, FORMAT_ESCAPED, FORMAT_PARSE, FORMAT_PLAIN, FORMAT_TEXT |
Class Constants: FORMAT_BLOCK_PARSE, FORMAT_ESCAPED, FORMAT_PARSE, FORMAT_PLAIN, FORMAT_TEXT |
||
Class Methods: __construct, __toString, bitrateParam, bitrateParams, content, durationParam, durationParams, escaped, exists, expiryParam, expiryParams, getFormat, getKey, getKeysToTry, getLanguage, getParams, getTitle, inContentLanguage, inLanguage, isBlank, isDisabled, isMultiKey, listParam, newFallbackSequence, newFromKey, newFromSpecifier, numParam, numParams, params, parse, parseAsBlock, plain, plaintextParam, plaintextParams, rawParam, rawParams, serialize, setContext, setInterfaceMessageFlag, sizeParam, sizeParams, text, timeperiodParam, timeperiodParams, title, toString, unserialize, useDatabase |
Class Methods: __construct, __toString, bitrateParam, bitrateParams, content, durationParam, durationParams, escaped, exists, expiryParam, expiryParams, getFormat, getKey, getKeysToTry, getLanguage, getParams, getTitle, inContentLanguage, inLanguage, isBlank, isDisabled, isMultiKey, listParam, newFallbackSequence, newFromKey, newFromSpecifier, numParam, numParams, params, parse, parseAsBlock, plain, plaintextParam, plaintextParams, rawParam, rawParams, serialize, setContext, setInterfaceMessageFlag, sizeParam, sizeParams, text, timeperiodParam, timeperiodParams, title, toString, unserialize, useDatabase |
||
> doc Message::setContext |
|||
public function setContext(IContextSource $context) |
public function setContext(IContextSource $context) |
||
| Line 79: | Line 106: | ||
</pre> |
</pre> |
||
<span id="Debug_output"></span> |
|||
=== Debug output === |
|||
=== デバッグ出力 === |
|||
<pre style="overflow:auto;"> |
<pre style="overflow:auto;"> |
||
$ php maintenance/ |
$ php maintenance/run.php shell --log-all --dbo-debug |
||
[debug] [DBReplication] Wikimedia\Rdbms\LBFactory::getChronologyProtector: using request info { |
[debug] [DBReplication] Wikimedia\Rdbms\LBFactory::getChronologyProtector: using request info { |
||
"IPAddress": "", |
"IPAddress": "", |
||
| Line 93: | Line 121: | ||
Psy Shell v0.8.5 (PHP 5.6.30-0+deb8u1 — cli) by Justin Hileman |
Psy Shell v0.8.5 (PHP 5.6.30-0+deb8u1 — cli) by Justin Hileman |
||
>>> |
>>> MW::message("Recentchanges")->text() |
||
[debug] [CryptRand] mcrypt_create_iv generated 20 bytes of randomness. |
[debug] [CryptRand] mcrypt_create_iv generated 20 bytes of randomness. |
||
[debug] [CryptRand] 0 bytes of randomness leftover in the buffer. |
[debug] [CryptRand] 0 bytes of randomness leftover in the buffer. |
||
| Line 100: | Line 128: | ||
</pre> |
</pre> |
||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
== Editline integration == |
== Editline integration == |
||
</div> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
PsySH can integrate with [[w:GNU_Readline|readline]] / editline (PHP usually comes pre-built with the latter). |
PsySH can integrate with [[w:GNU_Readline|readline]] / editline (PHP usually comes pre-built with the latter). |
||
</div> |
|||
<div lang="en" dir="ltr" class="mw-content-ltr"> |
|||
A sample <code>.editrc</code> for history search: |
A sample <code>.editrc</code> for history search: |
||
</div> |
|||
<syntaxhighlight lang="text"> |
<syntaxhighlight lang="text"> |
||
# make PgUp/PgDown work, sort of |
# make PgUp/PgDown work, sort of |
||
| Line 111: | Line 147: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
<span id="See_also"></span> |
|||
==関連項目== |
==関連項目== |
||
* {{ll|Manual:How to debug}} |
* {{ll|Manual:How to debug}} |
||
Latest revision as of 20:13, 30 October 2025
| MediaWiki ファイル: shell.php | |
|---|---|
| 場所: | maintenance/ |
| ソース コード: | master • 1.46.0 • 1.45.4 • 1.43.9 |
| クラス: | MediaWikiShell |
$file は、maintenance ディレクトリにあるメンテナンス スクリプトであり、MediaWiki のオブジェクトや関数を試すために使用できます。
It is based on PsySH; it replaces eval.php which is less robust and has fewer features.
Beyond the ability to evaluate PHP statements, functionality includes handling errors and fatals in a way that does not break the shell, examining object internals, source code and documentation via reflection, external editor integration and more.
使用法
Interactively: php maintenance/run.php shell
Executing PHP commands from a file: cat commands.txt | maintenance/run.php shell
オプション
| Option | Description |
|---|---|
| --log-channels | Print logs sent to the given log channels. Comma-separated: --log-channels authentication,cookie,session Log levels can be filtered with --log-channels authentication,cookie:info,session:error
|
| --log-all | Print logs sent to all channels |
| --dbo-debug | Log more database-related information (roughly the same as setting $wgDebugDumpSql)
|
| --no-session | Pretend MW_NO_SESSION has been set (useful for debugging code that's invoked from no-session endpoints such as load.php)
|
例
Command execution and error handling
$ php maintenance/run.php shell
Psy Shell v0.12.2 (PHP 7.4.33 — cli) by Justin Hileman
> MW::user('Admin')
= MediaWiki\User\User {#5704
+mId: 1,
+mName: "Admin",
+mActorId: 1,
+mRealName: "",
+mEmail: "admin@local.wmftest.net",
+mTouched: "20240114073920",
+mEmailAuthenticated: "20010101000000",
+mFrom: "id",
mId: 1,
mName: "Admin",
mActorId: 1,
mRealName: "",
mEmail: "admin@local.wmftest.net",
mTouched: "20240114073920",
mEmailAuthenticated: "20010101000000",
mFrom: "id",
}
> // use $_ for previous return value
> $_->mQuickTouched
PHP Error: Cannot access protected property User::$mQuickTouched in Psy Shell code on line 2
> sudo $_->mQuickTouched
= null
> User::newFromIdentity(0)
TypeError Argument 1 passed to MediaWiki\User\User::newFromIdentity() must implement interface MediaWiki\User\UserIdentity, int given, called on line 2.
> wtf
TypeError Argument 1 passed to MediaWiki\User\User::newFromIdentity() must implement interface MediaWiki\User\UserIdentity, int given, called on line 2.
--
0: () at includes/user/User.php:652
1: MediaWiki\User\User::newFromIdentity() at eval()'d code:2
2: eval() at vendor/psy/psysh/src/ExecutionLoopClosure.php:52
Use wtf -a to see 8 more lines
リフレクション
> ls Message
Class Constants: FORMAT_BLOCK_PARSE, FORMAT_ESCAPED, FORMAT_PARSE, FORMAT_PLAIN, FORMAT_TEXT
Class Methods: __construct, __toString, bitrateParam, bitrateParams, content, durationParam, durationParams, escaped, exists, expiryParam, expiryParams, getFormat, getKey, getKeysToTry, getLanguage, getParams, getTitle, inContentLanguage, inLanguage, isBlank, isDisabled, isMultiKey, listParam, newFallbackSequence, newFromKey, newFromSpecifier, numParam, numParams, params, parse, parseAsBlock, plain, plaintextParam, plaintextParams, rawParam, rawParams, serialize, setContext, setInterfaceMessageFlag, sizeParam, sizeParams, text, timeperiodParam, timeperiodParams, title, toString, unserialize, useDatabase
> doc Message::setContext
public function setContext(IContextSource $context)
Description:
Set the language and the title from a context object
Param:
IContextSource $context
Return:
Message $this
Since: 1.19
>>> show Message::setContext
> 724| public function setContext( IContextSource $context ) {
725| $this->inLanguage( $context->getLanguage() );
726| $this->title( $context->getTitle() );
727| $this->interface = true;
728|
729| return $this;
730| }
デバッグ出力
$ php maintenance/run.php shell --log-all --dbo-debug
[debug] [DBReplication] Wikimedia\Rdbms\LBFactory::getChronologyProtector: using request info {
"IPAddress": "",
"UserAgent": "",
"ChronologyProtection": "true"
}
[debug] [DBConnection] Wikimedia\Rdbms\LoadBalancer::openConnection: calling initLB() before first connection.
[debug] [DBConnection] Connected to database 0 at '127.0.0.1'.
[debug] [DBQuery] wiki SHOW /* Wikimedia\Rdbms\DatabaseMysqlBase::serverIsReadOnly */ GLOBAL VARIABLES LIKE 'read_only'
[debug] [DBQuery] SHOW GLOBAL VARIABLES LIKE 'read_only'
Psy Shell v0.8.5 (PHP 5.6.30-0+deb8u1 — cli) by Justin Hileman
>>> MW::message("Recentchanges")->text()
[debug] [CryptRand] mcrypt_create_iv generated 20 bytes of randomness.
[debug] [CryptRand] 0 bytes of randomness leftover in the buffer.
[info] [MessageCache] MessageCache::load: Loading en... local cache is empty, got from global cache
=> "Recent changes"
Editline integration
PsySH can integrate with readline / editline (PHP usually comes pre-built with the latter).
A sample .editrc for history search:
# make PgUp/PgDown work, sort of
# editline has no prefix search so use fulltext search
bind "\e[5~" ed-search-prev-history
bind "\e[6~" ed-search-next-history