Michal Čihař edited this page May 16, 2016 · 4 revisions
Clone this wiki locally


The properties system is based on the Composite design pattern which allows groups of objects to be treated as independent items, facilitating the group operations that need to be done (an operation on the group can reach the whole group subtree).

The files are located in libraries/properties/, they are currently used for the import and export plug-ins and are declared in the setProperties() method of each plug-in. There are 3 group classes:

  • OptionsPropertyRootGroup
  • OptionsPropertyMainGroup
  • OptionsPropertySubgroup

and 7 leaf property classes:

  • BoolPropertyItem
  • DocPropertyItem
  • HiddenPropertyItem
  • MessageOnlyPropertyItem
  • RadioPropertyItem
  • SelectPropertyItem
  • TextPropertyItem

The OptionsPropertyRootGroup class is used only once for each plug-in, the main groups are used to declare separate types of properties for a certain plug-in and can have as many leaf properties or subgroups as desired, and finally the subgroups can also contain leaf property items or other subgroups. A good example is ExportMediawiki, because it also uses a subgroup of properties, which you will notice is treated as an individual property.

/** * Sets the export MediaWiki properties * * @return void */ protected function setProperties() { $props = 'libraries/properties/'; include_once "$props/plugins/ExportPluginProperties.class.php"; include_once "$props/options/groups/OptionsPropertyRootGroup.class.php"; include_once "$props/options/groups/OptionsPropertyMainGroup.class.php"; include_once "$props/options/groups/OptionsPropertySubgroup.class.php"; include_once "$props/options/items/MessageOnlyPropertyItem.class.php"; include_once "$props/options/items/RadioPropertyItem.class.php"; include_once "$props/options/items/BoolPropertyItem.class.php"; $exportPluginProperties = new ExportPluginProperties(); $exportPluginProperties->setText('MediaWiki Table'); $exportPluginProperties->setExtension('mediawiki'); $exportPluginProperties->setMimeType('text/plain'); $exportPluginProperties->setOptionsText(__('Options')); // create the root group that will be the options field for // $exportPluginProperties // this will be shown as "Format specific options" $exportSpecificOptions = new OptionsPropertyRootGroup(); $exportSpecificOptions->setName("Format Specific Options"); // general options main group $generalOptions = new OptionsPropertyMainGroup(); $generalOptions->setName("general_opts"); $generalOptions->setText(__('Dump table')); // what to dump (structure/data/both) $subgroup = new OptionsPropertySubgroup(); $subgroup->setName("dump_table"); $subgroup->setText("Dump table"); $leaf = new RadioPropertyItem(); $leaf->setName('structure_or_data'); $leaf->setValues( array( 'structure' => __('structure'), 'data' => __('data'), 'structure_and_data' => __('structure and data') ) ); $subgroup->setSubgroupHeader($leaf); $generalOptions->addProperty($subgroup); // export table name $leaf = new BoolPropertyItem(); $leaf->setName("caption"); $leaf->setText(__('Export table names')); $generalOptions->addProperty($leaf); // export table headers $leaf = new BoolPropertyItem(); $leaf->setName("caption"); $leaf->setText(__('Export table headers')); $generalOptions->addProperty($leaf); //add the main group to the root group $exportSpecificOptions->addProperty($generalOptions); // set the options for the export plugin property item $exportPluginProperties->setOptions($exportSpecificOptions); $this->properties = $exportPluginProperties; }

If you want to see an example with more main groups, subgroups and individual properties, you can look in the setProperties() method in the ExportSql plug-in.