Manuel:table page_props

From mediawiki.org
This page is a translated version of the page Manual:Page props table and the translation is 100% complete.
Manuel:Contenu Schéma de base de données MédiaWiki table page_props
Version de MediaWiki :
1.13

La table page_props contient les propriétés concernant les pages. Elles sont initialisées par l'analyseur syntaxique via ParserOutput::setPageProperty(), telles que le titre affiché ou la clé de tri par défaut des catégories. En particulier, tous les mots magiques avec un double caractère souligné '_' sont automatiquement enregistrés ici. Egalement, beaucoup d'extensions utilisent cette table pour enregistrer leurs propres données. Notez que le fait de refaire passer l'analyseur syntaxique sur une même page va purger toutes ses propriétés enregistrées dans cette table et les remplacer par les nouvelles, donc cette table n'est pas adaptée pour y ranger des données qui ne peuvent pas être rafraîchies par une nouvelle analyse.

Champs

pp_page

page_id servant à indexer la paire nom/valeur

pp_propname

Nom de propriété de page

pp_value

Valeur de propriété de page

pp_sortkey

Version de MediaWiki :
1.24

Manière dont les pages peuvent être demandées et triées sur la valeur de propriété (voir tâche T60032).

Résumé du schéma

Version de 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    |       |
+-------------+------------------+------+-----+---------+-------+
Versions de 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    |       |
+-------------+---------------+------+-----+---------+-------+
Versions de 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    |       |
+-------------+---------------+------+-----+---------+-------+

Les index

Version de 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      |         |               |
+------------+------------+--------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+

Exemple de requête

Voici un exemple de requête pour trouver les propriétés de page utilisées (voir aussi API:Pagepropnames/fr ).

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

Exemple d'une extension simple qui utilise cette table

Voici l'exemple d'une extension qui enregistre sa propre propriété de page dans la table page_props . Définit deux balises d'analyseur (accroches) <getprop> et <setprop> qui accèdent à sa propriété appelée SimpleSetPropExtension. Ils permettent à un éditeur wiki d'initialiser la valeur de la propriété en code wiki avec <setprop>Un texte aléatoire</setprop>, et d'afficher sa valeur avec <getprop/> (pour la page actuelle) ou avec <getprop page="some page"/> (pour sa valeur sur d'autres pages).

<?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 );
              }
        }
}

Voir aussi