Jump to content

Manual:page_props table

From mediawiki.org
This page is a translated version of the page Manual:Page props table and the translation is 22% complete.
Podręcznik:Spis treści Opis i struktura bazy danych MediaWiki Tabela page_props
Wersja MediaWiki:
1.13

The page_props table contains properties about pages set by the parser via ParserOutput::setPageProperty(), such as the display title and the default category sortkey. In particular, all double underscore magic words are automatically recorded here. Also, many extensions use this table to store their own data. Note that reparsing a page causes all of its properties to be purged from this table and replaced with the new ones, so this table is not suitable for storing data that can't be regenerated during a reparse.

Pola

pp_page

page_id by which the name/value pair is indexed

pp_propname

Page property name

pp_value

Page property value

pp_sortkey

Wersja MediaWiki:
1.24

This is so pages can be efficiently queried and sorted by property value (see zadanie T60032).

Podsumowanie struktury

Wersja 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    |       |
+-------------+------------------+------+-----+---------+-------+
Wersje 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    |       |
+-------------+---------------+------+-----+---------+-------+
Wersje 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    |       |
+-------------+---------------+------+-----+---------+-------+

Indexes

Wersja 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

Here's a sample query to find the page properties in use (see also 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                |
+------------------------------+

Example of a simple extension that uses this table

This example code is very old. It only works on pre-MW1.35 wikis.

Here is an example of an extension that stores its own page property in the page_props table. It defines two parser tags (hooks) <getprop> and <setprop> that manipulate its property named SimpleSetPropExtension. They allow a wiki editor to set the property's value in wikitext with <setprop>Some random text</setprop>, and display its value with <getprop/> (for the current page) or with <getprop page="some page"/> (for its value on some other 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 );
              }
        }
}


Zobacz też