- $tables = array (
- 'revision'
- );
- $fields = array (
- 'rev_id',
- 'rev_page',
- 'rev_text_id',
- 'rev_minor_edit'
- );
- $where = array (
- 'rev_deleted' => 0
- );
- $options = array ();
-
- $showTimestamp = $showUser = $showComment = $showContent = false;
- if (!is_null($prop)) {
- foreach ($prop as $p) {
- switch ($p) {
- case 'timestamp' :
- $fields[] = 'rev_timestamp';
- $showTimestamp = true;
- break;
- case 'user' :
- $fields[] = 'rev_user';
- $fields[] = 'rev_user_text';
- $showUser = true;
- break;
- case 'comment' :
- $fields[] = 'rev_comment';
- $showComment = true;
- break;
- case 'content' :
- $tables[] = 'text';
- $where[] = 'rev_text_id=old_id';
- $fields[] = 'old_id';
- $fields[] = 'old_text';
- $fields[] = 'old_flags';
- $showContent = true;
- break;
- default :
- ApiBase :: dieDebug(__METHOD__, "unknown prop $p");
- }
+ $this->addTables('revision');
+ $this->addWhere('rev_deleted=0');
+
+ $prop = array_flip($prop);
+
+ // These field are needed regardless of the client requesting them
+ $this->addFields('rev_id');
+ $this->addFields('rev_page');
+
+ // Optional fields
+ $this->fld_ids = isset ($prop['ids']);
+ // $this->addFieldsIf('rev_text_id', $this->fld_ids); // should this be exposed?
+ $this->fld_flags = $this->addFieldsIf('rev_minor_edit', isset ($prop['flags']));
+ $this->fld_timestamp = $this->addFieldsIf('rev_timestamp', isset ($prop['timestamp']));
+ $this->fld_comment = $this->addFieldsIf('rev_comment', isset ($prop['comment']));
+
+ if (isset ($prop['user'])) {
+ $this->addFields('rev_user');
+ $this->addFields('rev_user_text');
+ $this->fld_user = true;
+ }
+ if (isset ($prop['content'])) {
+
+ // For each page we will request, the user must have read rights for that page
+ foreach ($pageSet->getGoodTitles() as $title) {
+ if( !$title->userCanRead() )
+ $this->dieUsage(
+ 'The current user is not allowed to read ' . $title->getPrefixedText(),
+ 'accessdenied');