X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryBase.php;h=b9f3e8ae4df7f5375fd08bc8af85720eae9087b5;hb=5b8213e9efc8807b9bf2c67ce86106a938cdf2be;hp=d3b7d8d941fd9ae64c5ba9a899ca0cf5d390fbc4;hpb=b47979916c2b8a5c39d74ff9257183f76673bbe7;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index d3b7d8d941..b9f3e8ae4d 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -36,7 +36,7 @@ if (!defined('MEDIAWIKI')) { */ abstract class ApiQueryBase extends ApiBase { - private $mQueryModule, $mDb, $tables, $where, $fields, $options; + private $mQueryModule, $mDb, $tables, $where, $fields, $options, $join_conds; public function __construct($query, $moduleName, $paramPrefix = '') { parent :: __construct($query->getMain(), $moduleName, $paramPrefix); @@ -53,6 +53,7 @@ abstract class ApiQueryBase extends ApiBase { $this->where = array (); $this->fields = array (); $this->options = array (); + $this->join_conds = array (); } /** @@ -67,10 +68,33 @@ abstract class ApiQueryBase extends ApiBase { $this->tables = array_merge($this->tables, $tables); } else { if (!is_null($alias)) - $tables = $this->getDB()->tableName($tables) . ' ' . $alias; + $tables = $this->getAliasedName($tables, $alias); $this->tables[] = $tables; } } + + /** + * Get the SQL for a table name with alias + * @param string $table Table name + * @param string $alias Alias + * @return string SQL + */ + protected function getAliasedName($table, $alias) { + return $this->getDB()->tableName($table) . ' ' . $alias; + } + + /** + * Add a set of JOIN conditions to the internal array + * + * JOIN conditions are formatted as array( tablename => array(jointype, conditions) + * e.g. array('page' => array('LEFT JOIN', 'page_id=rev_page')) + * @param array $join_conds JOIN conditions + */ + protected function addJoinConds($join_conds) { + if(!is_array($join_conds)) + ApiBase::dieDebug(__METHOD__, 'Join conditions have to be arrays'); + $this->join_conds = array_merge($this->join_conds, $join_conds); + } /** * Add a set of fields to select to the internal array @@ -187,7 +211,7 @@ abstract class ApiQueryBase extends ApiBase { $db = $this->getDB(); $this->profileDBIn(); - $res = $db->select($this->tables, $this->fields, $this->where, $method, $this->options); + $res = $db->select($this->tables, $this->fields, $this->where, $method, $this->options, $this->join_conds); $this->profileDBOut(); return $res;