Manual:page props table

From MediaWiki.org
Jump to: navigation, search
Manual:Contents MediaWiki database layout page props table



MediaWiki version: 1.13

Contains properties about pages set by the parser via ParserOutput::setProperty(), 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.

Fields[edit | edit source]

pp_page[edit | edit source]

page_id by which the name/value pair is indexed

pp_propname[edit | edit source]

Page property name

pp_value[edit | edit source]

Page property value

pp_sortkey[edit | edit source]

MediaWiki version: 1.24

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

Schema[edit | edit source]

MediaWiki versions: 1.19 – 1.20
mysql> 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    |       | 
+-------------+---------------+------+-----+---------+-------+
mysql> SELECT DISTINCT pp_propname FROM page_props;
+------------------+
| pp_propname      |
+------------------+
| defaultsort      |
| notoc            |
| displaytitle     |
| nonewsectionlink |
| noindex          |
| forcetoc         |
| noeditsection    |
| newsectionlink   |
| notitleconvert   |
| nogallery        |
| index            |
| hiddencat        |
| staticredirect   |
+------------------+
13 rows in set (1.97 sec)

Example of a simple extension that uses this table[edit | edit source]

Here is an example of an extension that uses the page_props table. It defines two parser tags (hooks) - <getprop> and <setprop>. A prop can be set by <setprop>Property to set</setprop>, and retrieved via <getprop/> (for the current page) or <getprop page="some page"/> to get it for 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()->setProperty( 'SimpleSetPropExtension', $serialized );
 
        // Note if other pages change based on a property, you should see $wgPagePropLinkInvalidations
        // to automatically invalidate dependant 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.
              $dbr = wfGetDB( DB_SLAVE );
              $propValue = $dbr->selectField( 'page_props', // table to use
                          'pp_value', // Field to select
                          array( '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()->getProperty( '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 );
              }
        }
}

See also[edit | edit source]

Databases Engines: MySQLOraclePostgreSQLSQLite
Technical documentation: Schema (tables) – API property associationsField prefixesPrimary key storage in other fieldsWikimedia extension tables
Configuration: SettingsSharing
Development: AccessOptimizationPolicyUpdaterExtension schema updatesPatch file
Core tables: archivecategorycategorylinkschange_tagconfigexternallinksfilearchivehitcounterimageimagelinksinterwikiiwlinksipblocksjobl10n_cachelanglinkslogginglog_searchmsg_resourcemsg_resource_linksmodule_depsobjectcacheoldimagepagepagelinkspage_propspage_restrictionsprotected_titlesquerycachequerycachetwoquerycache_inforecentchangesredirectrevisionsearchindexsitessite_statstag_summarytemplatelinkstexttranscacheupdateloguploadstashuseruser_former_groupsuser_groupsuser_newtalkuser_propertiesvalid_tagwatchlist
Language: English  • 日本語 • polski