function getQueryInfo()
 {
     global $egApprovedRevsNamespaces;
     $tables = array('ar' => 'approved_revs_files', 'im' => 'image', 'p' => 'page');
     $fields = array('im.img_name AS title', 'ar.approved_sha1 AS approved_sha1', 'ar.approved_timestamp AS approved_ts', 'im.img_sha1 AS latest_sha1', 'im.img_timestamp AS latest_ts', 'p.page_id AS id');
     $join_conds = array('im' => array('LEFT OUTER JOIN', 'ar.file_title=im.img_name'), 'p' => array('LEFT OUTER JOIN', 'im.img_name=p.page_title'));
     #
     #	ALLFILES: list all approved pages
     #   also includes $this->mMode == 'undesignated', see formatResult()
     #
     if ($this->mMode == 'allapproved') {
         $conds = "p.page_namespace=" . NS_FILE;
         // get everything from approved_revs table
         #
         #	UNAPPROVED
         #
     } elseif ($this->mMode == 'unapproved') {
         $tables['c'] = 'categorylinks';
         $join_conds['c'] = array('LEFT OUTER JOIN', 'p.page_id=c.cl_from');
         $join_conds['im'] = array('RIGHT OUTER JOIN', 'ar.file_title=im.img_name');
         $perms = ApprovedRevs::getPermissions();
         if (in_array("File", $perms['Namespaces'])) {
             // if all files approvable no additional conditions required
             // besides NS_FILE requirement below
             $conds = '';
         } else {
             list($ns, $cat, $pg) = ApprovedRevs::getPermissionsStringsForDB();
             $conds = array();
             if ($cat !== false) {
                 $conds[] = "(c.cl_to IN ({$cat}))";
             }
             if ($pg !== false) {
                 $conds[] = "(p.page_id IN ({$pg}))";
             }
             if (count($conds) > 0) {
                 $conds = ' AND (' . implode(' OR ', $conds) . ')';
             } else {
                 $conds = '';
             }
         }
         $conds = "ar.file_title IS NULL AND p.page_namespace=" . NS_FILE . $conds;
         #
         #	UNDESIGNATED
         #
     } else {
         if ($this->mMode == 'undesignated') {
             $tables['c'] = 'categorylinks';
             $join_conds['c'] = array('LEFT OUTER JOIN', 'p.page_id=c.cl_from');
             $join_conds['im'] = array('LEFT OUTER JOIN', 'ar.file_title=im.img_name');
             $perms = ApprovedRevs::getPermissions();
             if (in_array("File", $perms['Namespaces'])) {
                 // if all files approvable should break out of this...since none can be
                 // undesignated if they're all approvable
                 $conds = ' AND p.page_namespace=1 AND p.page_namespace=2';
                 // impossible condition, hack
             } else {
                 list($ns, $cat, $pg) = ApprovedRevs::getPermissionsStringsForDB();
                 $conds = array();
                 // WAS: if ($cat !== false) $conds[] = "(c.cl_to NOT IN ($cat) OR c.cl_to IS NULL)";
                 if ($cat !== false) {
                     $conds[] = "p.page_id NOT IN (SELECT DISTINCT cl_from FROM categorylinks WHERE cl_to IN ({$cat}))";
                 }
                 if ($pg !== false) {
                     $conds[] = "(p.page_id NOT IN ({$pg}))";
                 }
                 if (count($conds) > 0) {
                     $conds = ' AND (' . implode(' AND ', $conds) . ')';
                 } else {
                     $conds = '';
                 }
             }
             $conds = "p.page_namespace=" . NS_FILE . $conds;
             #
             #	NOTLATEST
             #
         } else {
             // Name/Title both exist, sha1's don't match OR timestamps don't match
             $conds = "p.page_namespace=" . NS_FILE . " AND (ar.approved_sha1!=im.img_sha1 OR ar.approved_timestamp!=im.img_timestamp)";
         }
     }
     return array('tables' => $tables, 'fields' => $fields, 'join_conds' => $join_conds, 'conds' => $conds, 'options' => array('DISTINCT'));
 }
 function getQueryInfo()
 {
     $tables = array('ar' => 'approved_revs_files', 'im' => 'image', 'p' => 'page');
     $fields = array('im.img_name AS title', 'ar.approved_sha1 AS approved_sha1', 'ar.approved_timestamp AS approved_ts', 'im.img_sha1 AS latest_sha1', 'im.img_timestamp AS latest_ts');
     $conds = array();
     $join_conds = array('im' => array('LEFT OUTER JOIN', 'ar.file_title=im.img_name'), 'p' => array('LEFT OUTER JOIN', 'im.img_name=p.page_title'));
     #
     #	ALLFILES: list all approved pages
     #   also includes $this->mMode == 'invalid', see formatResult()
     #
     if ($this->mMode == 'allapproved') {
         $conds['p.page_namespace'] = NS_FILE;
         // get everything from approved_revs table
         #
         #	UNAPPROVED
         #
     } elseif ($this->mMode == 'unapproved') {
         $tables['c'] = 'categorylinks';
         $join_conds['c'] = array('LEFT OUTER JOIN', 'p.page_id=c.cl_from');
         $join_conds['im'] = array('RIGHT OUTER JOIN', 'ar.file_title=im.img_name');
         $perms = ApprovedRevs::getPermissions();
         // if all files are not approvable then need to find files matching
         // page and category permissions
         if (!in_array(NS_FILE, array_keys($perms['Namespace Permissions']))) {
             list($ns, $cat, $pg) = ApprovedRevs::getApprovabilityStringsForDB();
             $pageCatConditions = array();
             if ($cat !== '') {
                 $pageCatConditions[] = "c.cl_to IN ({$cat})";
             }
             if ($pg !== '') {
                 $pageCatConditions[] = "p.page_id IN ({$pg})";
             }
             // if there were any page or category conditions, add to $conds
             if (count($pageCatConditions) > 0) {
                 $conds[] = '(' . implode(' OR ', $pageCatConditions) . ')';
             }
         }
         $conds['ar.file_title'] = null;
         $conds['p.page_namespace'] = NS_FILE;
         #
         #	INVALID PERMISSIONS
         #
     } elseif ($this->mMode == 'invalid') {
         $tables['c'] = 'categorylinks';
         $join_conds['c'] = array('LEFT OUTER JOIN', 'p.page_id=c.cl_from');
         $join_conds['im'] = array('LEFT OUTER JOIN', 'ar.file_title=im.img_name');
         $perms = ApprovedRevs::getPermissions();
         if (in_array(NS_FILE, array_keys($perms['Namespace Permissions']))) {
             // if all files approvable should break out of this...since none can be
             // invalid if they're all approvable
             $conds[] = 'p.page_namespace=1 AND p.page_namespace=2';
             // impossible condition, hack
         } else {
             list($ns, $cat, $pg) = ApprovedRevs::getApprovabilityStringsForDB();
             if ($cat !== '') {
                 $conds[] = "p.page_id NOT IN (SELECT DISTINCT cl_from FROM categorylinks WHERE cl_to IN ({$cat}))";
             }
             if ($pg !== '') {
                 $conds[] = "p.page_id NOT IN ({$pg})";
             }
         }
         $conds['p.page_namespace'] = NS_FILE;
         #
         #	NOTLATEST
         #
     } else {
         // Name/Title both exist, sha1's don't match OR timestamps don't match
         $conds['p.page_namespace'] = NS_FILE;
         $conds[] = "(ar.approved_sha1!=im.img_sha1 OR ar.approved_timestamp!=im.img_timestamp)";
     }
     return array('tables' => $tables, 'fields' => $fields, 'join_conds' => $join_conds, 'conds' => $conds, 'options' => array('DISTINCT'));
 }