Manual:page_props テーブル

From mediawiki.org
This page is a translated version of the page Manual:Page props table and the translation is 89% complete.
Manual:コンテンツ MediaWiki のデータベース レイアウト page_props テーブル
MediaWiki バージョン:
1.13

page_props テーブルは、パーサーが ParserOutput::setPageProperty() によって設定したページの属性として、例えば表示するページ名やカテゴリの既定のソート キーなどを含みます。 特に2本ずつの下線で挟んだ形式のマジックワードである挙動スイッチはすべて、こちらで自動的に記録します。さらに拡張機能の多くはこのテーブルを用いて固有のデータを保存しています。 特定のページを再解析すると、その属性はすべてこのテーブルからパージされ、新しいものに置き換えられます。そのため、再解析中に再生成できないデータを格納するには、このテーブルが不適切であることにご注意ください。

フィールド

pp_page

page_id により、属性の名前および設定値のペアをインデックス化

pp_propname

ページのプロパティ名

pp_value

ページのプロパティ値

pp_sortkey

MediaWiki バージョン:
1.24

これにより属性値に基づいて複数ページのクエリやソートを効率的に行います(詳細はタスク T60032をご参照)。

スキーマの要約

MediaWiki バージョン:
1.38

DESCRIBE page_props;

+-------------+------------------+------+-----+---------+-------+
| Field       | Type             | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+-------+
| pp_page     | int(10) unsigned | NO   | PRI | NULL    |       |
| pp_propname | varbinary(60)    | NO   | PRI | NULL    |       |
| pp_value    | blob             | NO   |     | NULL    |       |
| pp_sortkey  | float            | YES  |     | NULL    |       |
+-------------+------------------+------+-----+---------+-------+
MediaWiki バージョン:
1.24 – 1.37

DESCRIBE page_props;

+-------------+---------------+------+-----+---------+-------+
| Field       | Type          | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| pp_page     | int(11)       | NO   | PRI | NULL    |       |
| pp_propname | varbinary(60) | NO   | PRI | NULL    |       |
| pp_value    | blob          | NO   |     | NULL    |       |
| pp_sortkey  | float         | YES  |     | NULL    |       |
+-------------+---------------+------+-----+---------+-------+
MediaWiki バージョン:
1.19 – 1.23

DESCRIBE page_props;

+-------------+---------------+------+-----+---------+-------+
| Field       | Type          | Null | Key | Default | Extra |
+-------------+---------------+------+-----+---------+-------+
| pp_page     | int(11)       | NO   | PRI | NULL    |       |
| pp_propname | varbinary(60) | NO   | PRI | NULL    |       |
| pp_value    | blob          | NO   |     | NULL    |       |
+-------------+---------------+------+-----+---------+-------+

インデックス

MediaWiki バージョン:
1.32

SHOW INDEX IN page_props;

+------------+------------+--------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table      | Non_unique | Key_name                 | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+------------+------------+--------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| page_props |          0 | PRIMARY                  |            1 | pp_page     | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| page_props |          0 | PRIMARY                  |            2 | pp_propname | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| page_props |          0 | pp_propname_page         |            1 | pp_propname | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| page_props |          0 | pp_propname_page         |            2 | pp_page     | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| page_props |          0 | pp_propname_sortkey_page |            1 | pp_propname | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
| page_props |          0 | pp_propname_sortkey_page |            2 | pp_sortkey  | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |               |
| page_props |          0 | pp_propname_sortkey_page |            3 | pp_page     | A         |           0 |     NULL | NULL   |      | BTREE      |         |               |
+------------+------------+--------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+

Sample query

使用しているページ属性を調べるには、このサンプルを使います(API:Pagepropnames も参照)。

MariaDB [enwiki_p]> SELECT DISTINCT pp_propname FROM page_props;
+------------------------------+
| pp_propname                  |
+------------------------------+
| defaultsort                  |
| disambiguation               |
| displaytitle                 |
| forcetoc                     |
| graph_specs                  |
| hiddencat                    |
| index                        |
| jsonconfig_getdata           |
| kartographer                 |
| kartographer_frames          |
| kartographer_links           |
| newsectionlink               |
| nocontentconvert             |
| noeditsection                |
| noexternallanglinks          |
| nogallery                    |
| noindex                      |
| nonewsectionlink             |
| notitleconvert               |
| notoc                        |
| page_image                   |
| page_image_free              |
| page_top_level_section_count |
| score                        |
| staticredirect               |
| templatedata                 |
| wikibase-badge-Q17437796     |
| wikibase-badge-Q17437798     |
| wikibase-badge-Q17506997     |
| wikibase-badge-Q17559452     |
| wikibase-badge-Q17580674     |
| wikibase-badge-Q20748091     |
| wikibase-badge-Q20748092     |
| wikibase-badge-Q20748093     |
| wikibase-badge-Q20748094     |
| wikibase-badge-Q51759403     |
| wikibase-shortdesc           |
| wikibase_item                |
+------------------------------+

このテーブルを使用する簡単な拡張機能のサンプル

ここにあげる拡張機能の例では、それ自体のページ属性を page_props テーブルに保存しています。 It defines two parser tags (hooks) <getprop> and <setprop> that manipulate its property named SimpleSetPropExtension. ウィキエディタは属性の値をウィキテキストで設定するために<setprop>ランダムなテキスト</setprop>を使用し、その値を(現在のページに対して)<getdrop/>または(他のページからの値の場合は)<getprop page="some page"/>で表示します。

<?php
 
$wgHooks['ParserFirstCallInit'][] = 'wfSampleParserInit';

function wfSampleParserInit( Parser &$parser ) {
        // This does <setprop>Some random text</setprop>
        // And then <getprop/> to retrieve a prop
        // Or <getprop page="somepage"> to retrieve for
        // something other than the current page.

        $parser->setHook( 'getprop', 'wfSampleGetProp' );
        $parser->setHook( 'setprop', 'wfSampleSetProp' );
        // Always return true from this function. The return value does not denote
        // success or otherwise have meaning - it just must always be true.
        return true;
}

function wfSampleSetProp( $input, array $args, Parser $parser, PPFrame $frame ) {
        $parsed = $parser->recursiveTagParse( $input, $frame );
        // Since this can span different parses, we need to take account of
        // the fact recursiveTagParse only half parses the text. or strip tags
        // (UNIQ's) will be exposed. (Alternative would be to just call
        // $parser->replaceLinkHolders() and $parser->mStripState->unstripBoth()
        // right here right now.
        $serialized = serialize( $parser->serializeHalfParsedText( $parsed ) );
        $parser->getOutput()->setPageProperty( 'SimpleSetPropExtension', $serialized );

        // Note if other pages change based on a property, you should see $wgPagePropLinkInvalidations
        // to automatically invalidate dependent page. In this example that would be pages that
        // use <getprop page="something>. However that would require adding a linking table
        // (since none of the standard ones work for this example) which is a bit beyond the
        // scope of this simple example.

        return '';
}
function wfSampleGetProp( $input, array $args, Parser $parser, PPFrame $frame ) {
        $pageId = $parser->getTitle()->getArticleID();
        if ( isset( $args['page'] ) ) {
              $title = Title::newFromText( $args['page'] );
              if ( !$title || $title->getArticleID() === 0 ) {
                          // In a real extension, this would be i18n-ized.
                          return '<span class="error">Invalid page ' . htmlspecialchars( $args['page'] ) . ' specified.</span>';
              }
              
              // Do for some page other then current one.
              $dbl = MediaWikiServices::getInstance()->getDBLoadBalancer();
              $dbr = $dbl->getConnection( DB_REPLICA );
              $propValue = $dbr->selectField( 'page_props', // table to use
                          'pp_value', // Field to select
                          [ 'pp_page' => $title->getArticleID(), 'pp_propname' => "SimpleSetPropExtension" ], // where conditions
                          __METHOD__
              );
              if ( $propValue === false ) {
                          // No prop stored for this page
                          // In a real extension, this would be i18n-ized.
                          return '<span class="error">No prop set for page ' . htmlspecialchars( $args['page'] ) . ' specified.</span>';
              }
              // We found the prop. Unserialize (First level of serialization)
              $prop = unserialize( $propValue );

              if ( !$parser->isValidHalfParsedText( $prop ) ) {
                          // Probably won't ever happen.
                          return '<span class="error">Error retrieving prop</span>';
              } else {
                          // Everything should be good.
                          return $parser->unserializeHalfParsedText( $prop );
              }
        } else {
              // Second case, current page.
              // Can't query db, because could be set earlier in the page and not saved yet.
              // So have to use the parserOutput object.

              $prop = unserialize( $parser->getOutput()->getPageProperty( 'SimpleSetPropExtension' ) );

              if ( !$parser->isValidHalfParsedText( $prop ) ) {
                          // Probably won't ever happen.
                          return '<span class="error">Error retrieving prop</span>';
              } else {
                          // Everything should be good.
                          return $parser->unserializeHalfParsedText( $prop );
              }
        }
}

関連項目