Merge branch 'pr/3386'

* pr/3386:
  dwpage: output meta data as JSON
  dwpage: rename gmeta into getmeta
  dwpage.php: add an option to get metadata
This commit is contained in:
Andreas Gohr 2021-02-16 21:38:33 +01:00
commit c2bbc4b490
1 changed files with 28 additions and 0 deletions

View File

@ -118,6 +118,27 @@ class PageCLI extends CLI {
true,
'unlock'
);
/* gmeta command */
$options->registerCommand(
'getmeta',
'Prints metadata value for a page to stdout.'
);
$options->registerArgument(
'wikipage',
'The wiki page to get the metadata for',
true,
'getmeta'
);
$options->registerArgument(
'key',
'The name of the metadata item to be retrieved.' . "\n" .
'If empty, an array of all the metadata items is returned.' ."\n" .
'For retrieving items that are stored in sub-arrays, separate the ' .
'keys of the different levels by spaces, in quotes, eg "date modified".',
false,
'getmeta'
);
}
/**
@ -160,6 +181,13 @@ class PageCLI extends CLI {
$this->clearLock($wiki_id);
$this->success("$wiki_id unlocked");
break;
case 'getmeta':
$wiki_id = array_shift($args);
$key = trim(array_shift($args));
$meta = p_get_metadata($wiki_id, $key, METADATA_RENDER_UNLIMITED);
echo trim(json_encode($meta, JSON_PRETTY_PRINT));
echo "\n";
break;
default:
echo $options->help();
}