* (bug 20131) PHP Notice: Undfined index: page_latest in includes/ChangesList.php...
[lhc/web/wiklou.git] / includes / api / ApiQueryUserContributions.php
index 469a1b3..297e5c8 100644 (file)
@@ -42,7 +42,7 @@ class ApiQueryContributions extends ApiQueryBase {
        private $params, $username;
        private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
                        $fld_comment = false, $fld_flags = false,
-                       $fld_patrolled = false;
+                       $fld_patrolled = false, $fld_tags = false;
 
        public function execute() {
 
@@ -57,6 +57,7 @@ class ApiQueryContributions extends ApiQueryBase {
                $this->fld_flags = isset($prop['flags']);
                $this->fld_timestamp = isset($prop['timestamp']);
                $this->fld_patrolled = isset($prop['patrolled']);
+               $this->fld_tags = isset($prop['tags']);
 
                // TODO: if the query is going only against the revision table, should this be done?
                $this->selectNamedDB('contributions', DB_SLAVE, 'contributions');
@@ -141,7 +142,7 @@ class ApiQueryContributions extends ApiQueryBase {
        private function prepareQuery() {
                // We're after the revision table, and the corresponding page
                // row for anything we retrieve. We may also need the
-               // recentchanges row.
+               // recentchanges row and/or tag summary row.
                global $wgUser;
                $tables = array('page', 'revision'); // Order may change
                $this->addWhere('page_id=rev_page');
@@ -162,7 +163,7 @@ class ApiQueryContributions extends ApiQueryBase {
                }
 
                if(!$wgUser->isAllowed('hideuser'))
-                       $this->addWhere('rev_deleted & ' . Revision::DELETED_USER . ' = 0');
+                       $this->addWhere($this->getDB()->bitAnd('rev_deleted',Revision::DELETED_USER) . ' = 0');
                // We only want pages by the specified users.
                if($this->prefixMode)
                        $this->addWhere("rev_user_text LIKE '" . $this->getDB()->escapeLike($this->userprefix) . "%'");
@@ -245,6 +246,16 @@ class ApiQueryContributions extends ApiQueryBase {
                $this->addFieldsIf('rev_minor_edit', $this->fld_flags);
                $this->addFieldsIf('rev_parent_id', $this->fld_flags);
                $this->addFieldsIf('rc_patrolled', $this->fld_patrolled);
+               
+               if($this->fld_tags || !is_null($this->params['tag'])) {
+                       $this->addTables('tag_summary');
+                       $this->addJoinConds(array('tag_summary' => array('LEFT JOIN', array('rev_id=ts_rev_id'))));
+                       $this->addFields('ts_tags');
+               }
+               
+               if( !is_null($this->params['tag']) ) {
+                       $this->addWhereFld('ts_tags', $this->params['tag']);
+               }
        }
 
        /**
@@ -271,7 +282,7 @@ class ApiQueryContributions extends ApiQueryBase {
                        $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->rev_timestamp);
 
                if ($this->fld_flags) {
-                       if ($row->rev_parent_id == 0)
+                       if ($row->rev_parent_id == 0 && !is_null($row->rev_parent_id))
                                $vals['new'] = '';
                        if ($row->rev_minor_edit)
                                $vals['minor'] = '';
@@ -292,6 +303,9 @@ class ApiQueryContributions extends ApiQueryBase {
                if ($this->fld_size && !is_null($row->rev_len))
                        $vals['size'] = intval($row->rev_len);
 
+               if ($this->fld_tags && $row->ts_tags)
+                       $vals['tags'] = $row->ts_tags;
+                       
                return $vals;
        }
        
@@ -343,6 +357,7 @@ class ApiQueryContributions extends ApiQueryBase {
                                        'size',
                                        'flags',
                                        'patrolled',
+                                       'tags',
                                )
                        ),
                        'show' => array (
@@ -354,6 +369,7 @@ class ApiQueryContributions extends ApiQueryBase {
                                        '!patrolled',
                                )
                        ),
+                       'tag' => null,
                );
        }
 
@@ -370,6 +386,7 @@ class ApiQueryContributions extends ApiQueryBase {
                        'prop' => 'Include additional pieces of information',
                        'show' => array('Show only items that meet this criteria, e.g. non minor edits only: show=!minor',
                                        'NOTE: if show=patrolled or show=!patrolled is set, revisions older than $wgRCMaxAge won\'t be shown',),
+                       'tag' => 'Only list contributions with this tag',
                );
        }