From 14118af36f2ba65a4e5151ee33b6ad565492cbf0 Mon Sep 17 00:00:00 2001
From: Andrew Dolgov <fox@madoka.volgo-balt.ru>
Date: Mon, 15 Apr 2013 14:54:17 +0400
Subject: fix schema for favicon_avg_color

---
 schema/ttrss_schema_pgsql.sql | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

(limited to 'schema/ttrss_schema_pgsql.sql')

diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql
index ec3b778cc..3fc58555d 100644
--- a/schema/ttrss_schema_pgsql.sql
+++ b/schema/ttrss_schema_pgsql.sql
@@ -70,6 +70,7 @@ create table ttrss_feeds (id serial not null primary key,
 	purge_interval integer not null default 0,
 	last_updated timestamp default null,
 	last_error text not null default '',
+	favicon_avg_color varchar(11) default null,
 	site_url varchar(250) not null default '',
 	auth_login varchar(250) not null default '',
 	parent_feed integer default null references ttrss_feeds(id) on delete set null,
@@ -256,7 +257,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (116);
+insert into ttrss_version values (117);
 
 create table ttrss_enclosures (id serial not null primary key,
 	content_url text not null,
-- 
cgit v1.2.3-54-g00ecf


From 889a5f9f195309df5842f142986b3166212d8a58 Mon Sep 17 00:00:00 2001
From: Andrew Dolgov <fox@fakecake.org>
Date: Tue, 16 Apr 2013 19:41:31 +0400
Subject: experimental SQL-based error logger

---
 classes/logger.php            | 24 +++++++++++++++++++++
 classes/logger/sql.php        | 35 ++++++++++++++++++++++++++++++
 include/errorhandler.php      | 50 +++++++++++++++++++++++++++++++++++++++++++
 include/functions.php         | 15 ++++++++++---
 include/sessions.php          |  1 +
 schema/ttrss_schema_mysql.sql | 13 ++++++++++-
 schema/ttrss_schema_pgsql.sql | 13 ++++++++++-
 schema/versions/mysql/118.sql | 16 ++++++++++++++
 schema/versions/pgsql/118.sql | 15 +++++++++++++
 9 files changed, 177 insertions(+), 5 deletions(-)
 create mode 100644 classes/logger.php
 create mode 100644 classes/logger/sql.php
 create mode 100644 include/errorhandler.php
 create mode 100644 schema/versions/mysql/118.sql
 create mode 100644 schema/versions/pgsql/118.sql

(limited to 'schema/ttrss_schema_pgsql.sql')

diff --git a/classes/logger.php b/classes/logger.php
new file mode 100644
index 000000000..6370e1425
--- /dev/null
+++ b/classes/logger.php
@@ -0,0 +1,24 @@
+<?php
+class Logger {
+
+	protected $errornames = array(
+		2			=> 'E_WARNING',
+		8			=> 'E_NOTICE',
+		256		=> 'E_USER_ERROR',
+		512		=> 'E_USER_WARNING',
+		1024		=> 'E_USER_NOTICE',
+		2048		=> 'E_STRICT',
+		4096		=> 'E_RECOVERABLE_ERROR',
+		8192		=> 'E_DEPRECATED',
+		16384		=> 'E_USER_DEPRECATED',
+		32767		=> 'E_ALL');
+
+	function log_error($errno, $errstr, $file, $line, $context) {
+		return false;
+	}
+
+	function log($string) {
+		return false;
+	}
+}
+?>
diff --git a/classes/logger/sql.php b/classes/logger/sql.php
new file mode 100644
index 000000000..7ee22844e
--- /dev/null
+++ b/classes/logger/sql.php
@@ -0,0 +1,35 @@
+<?php
+class Logger_SQL {
+
+	private $link;
+
+	function __construct() {
+		$this->link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
+	}
+
+	function log_error($errno, $errstr, $file, $line, $context) {
+
+		if ($errno == E_NOTICE) return false;
+
+		if ($this->link) {
+			$errno = db_escape_string($this->link, $errno);
+			$errstr = db_escape_string($this->link, $errstr);
+			$file = db_escape_string($this->link, $file);
+			$line = db_escape_string($this->link, $line);
+			$context = db_escape_string($this->link, json_encode($context));
+
+			$owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : "NULL";
+
+			$result = db_query($this->link,
+				"INSERT INTO ttrss_error_log
+				(errno, errstr, filename, lineno, context, owner_uid, created_at) VALUES
+				($errno, '$errstr', '$file', '$line', '$context', $owner_uid, NOW())");
+
+			return db_affected_rows($this->link, $result) != 0;
+
+		}
+		return false;
+	}
+
+}
+?>
diff --git a/include/errorhandler.php b/include/errorhandler.php
new file mode 100644
index 000000000..13eed0e30
--- /dev/null
+++ b/include/errorhandler.php
@@ -0,0 +1,50 @@
+<?php
+// TODO: make configurable
+require_once "classes/logger.php";
+require_once "classes/logger/sql.php";
+
+function ttrss_error_handler($errno, $errstr, $file, $line, $context) {
+	global $logger;
+
+	if (!$logger) $logger = new Logger_SQL();
+
+	$errfile = str_replace(dirname(dirname(__FILE__)), "", $errfile);
+
+	if ($logger) {
+		return $logger->log_error($errno, $errstr, $file, $line, $context);
+	}
+
+	return false;
+}
+
+function ttrss_fatal_handler() {
+	global $logger;
+
+	$file		= "UNKNOWN FILE";
+	$errstr  = "UNKNOWN";
+	$errno   = E_CORE_ERROR;
+	$line		= -1;
+
+	$error = error_get_last();
+
+	if ($error !== NULL) {
+		$errno   = $error["type"];
+		$file = $error["file"];
+		$line = $error["line"];
+		$errstr  = $error["message"];
+
+		$context = debug_backtrace();
+
+		$file = str_replace(dirname(dirname(__FILE__)) . "/", "", $file);
+
+		if (!$logger) $logger = new Logger_SQL();
+
+		if ($logger) {
+			$logger->log_error($errno, $errstr, $file, $line, $context);
+		}
+	}
+}
+
+register_shutdown_function('ttrss_fatal_handler');
+set_error_handler('ttrss_error_handler');
+?>
diff --git a/include/functions.php b/include/functions.php
index 659950be0..621357ea6 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,6 +1,6 @@
 <?php
 	define('EXPECTED_CONFIG_VERSION', 26);
-	define('SCHEMA_VERSION', 117);
+	define('SCHEMA_VERSION', 118);
 
 	define('LABEL_BASE_INDEX', -1024);
 	define('PLUGIN_FEED_BASE_INDEX', -128);
@@ -3369,9 +3369,8 @@
 		return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
 	}
 
-	function init_connection($link) {
+	function init_connection_only($link) {
 		if ($link) {
-
 			if (DB_TYPE == "pgsql") {
 				pg_query($link, "set client_encoding = 'UTF-8'");
 				pg_set_client_encoding("UNICODE");
@@ -3385,6 +3384,16 @@
 				}
 			}
 
+			return true;
+		}
+
+		return false;
+	}
+
+	function init_connection($link) {
+		if ($link) {
+			init_connection_only($link);
+
 			global $pluginhost;
 
 			$pluginhost = new PluginHost($link);
diff --git a/include/sessions.php b/include/sessions.php
index 402e8b8de..bc8b7cff1 100644
--- a/include/sessions.php
+++ b/include/sessions.php
@@ -3,6 +3,7 @@
 
 	require_once "config.php";
 	require_once "db.php";
+	require_once "errorhandler.php";
 	require_once "lib/accept-to-gettext.php";
 	require_once "lib/gettext/gettext.inc";
 	require_once "version.php";
diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql
index 3773d9a45..0d0a8f460 100644
--- a/schema/ttrss_schema_mysql.sql
+++ b/schema/ttrss_schema_mysql.sql
@@ -1,6 +1,7 @@
 SET NAMES utf8;
 SET CHARACTER SET utf8;
 
+drop table if exists ttrss_error_log;
 drop table if exists ttrss_plugin_storage;
 drop table if exists ttrss_linked_feeds;
 drop table if exists ttrss_linked_instances;
@@ -299,7 +300,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
 
-insert into ttrss_version values (117);
+insert into ttrss_version values (118);
 
 create table ttrss_enclosures (id integer primary key auto_increment,
 	content_url text not null,
@@ -478,5 +479,15 @@ create table ttrss_plugin_storage (
 	content longtext not null,
   	foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
 
+create table ttrss_error_log(
+	id integer not null auto_increment primary key,
+	owner_uid integer,
+	errno integer not null,
+	errstr text not null,
+	filename text not null,
+	lineno integer not null,	
+	context text not null,
+	created_at datetime not null,
+	foreign key (owner_uid) references ttrss_users(id) ON DELETE SET NULL) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
 
 commit;
diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql
index 3fc58555d..d81f65f2b 100644
--- a/schema/ttrss_schema_pgsql.sql
+++ b/schema/ttrss_schema_pgsql.sql
@@ -1,3 +1,4 @@
+drop table if exists ttrss_error_log;
 drop table if exists ttrss_plugin_storage;
 drop table if exists ttrss_linked_feeds;
 drop table if exists ttrss_linked_instances;
@@ -257,7 +258,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (117);
+insert into ttrss_version values (118);
 
 create table ttrss_enclosures (id serial not null primary key,
 	content_url text not null,
@@ -421,4 +422,14 @@ create table ttrss_plugin_storage (
 	owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
 	content text not null);
 
+create table ttrss_error_log(
+	id serial not null primary key,
+	owner_uid integer references ttrss_users(id) ON DELETE SET NULL,
+	errno integer not null,
+	errstr text not null,
+	filename text not null,
+	lineno integer not null,	
+	context text not null,
+	created_at timestamp not null);
+
 commit;
diff --git a/schema/versions/mysql/118.sql b/schema/versions/mysql/118.sql
new file mode 100644
index 000000000..add2b0c1f
--- /dev/null
+++ b/schema/versions/mysql/118.sql
@@ -0,0 +1,16 @@
+begin;
+
+create table ttrss_error_log(
+	id integer not null auto_increment primary key,
+	owner_uid integer,
+	errno integer not null,
+	errstr text not null,
+	filename text not null,
+	lineno integer not null,	
+	context text not null,
+	created_at datetime not null,
+	foreign key (owner_uid) references ttrss_users(id) ON DELETE SET NULL) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
+
+update ttrss_version set schema_version = 118;
+
+commit;
diff --git a/schema/versions/pgsql/118.sql b/schema/versions/pgsql/118.sql
new file mode 100644
index 000000000..161cf4e3c
--- /dev/null
+++ b/schema/versions/pgsql/118.sql
@@ -0,0 +1,15 @@
+begin;
+
+create table ttrss_error_log(
+	id serial not null primary key,
+	owner_uid integer references ttrss_users(id) ON DELETE SET NULL,
+	errno integer not null,
+	errstr text not null,
+	filename text not null,
+	lineno integer not null,	
+	context text not null,
+	created_at timestamp not null);
+
+update ttrss_version set schema_version = 118;
+
+commit;
-- 
cgit v1.2.3-54-g00ecf


From 3fbb4d183d6b0cb4b6d9d2d8d62d635eb70ebf13 Mon Sep 17 00:00:00 2001
From: Andrew Dolgov <fox@madoka.volgo-balt.ru>
Date: Fri, 26 Apr 2013 14:15:57 +0400
Subject: set default timezone to automatic (bump schema)

---
 include/functions.php         | 2 +-
 schema/ttrss_schema_mysql.sql | 6 +++---
 schema/ttrss_schema_pgsql.sql | 6 +++---
 schema/versions/mysql/119.sql | 7 +++++++
 schema/versions/pgsql/119.sql | 7 +++++++
 5 files changed, 21 insertions(+), 7 deletions(-)
 create mode 100644 schema/versions/mysql/119.sql
 create mode 100644 schema/versions/pgsql/119.sql

(limited to 'schema/ttrss_schema_pgsql.sql')

diff --git a/include/functions.php b/include/functions.php
index 1ab92475d..f1e78dfb7 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,6 +1,6 @@
 <?php
 	define('EXPECTED_CONFIG_VERSION', 26);
-	define('SCHEMA_VERSION', 118);
+	define('SCHEMA_VERSION', 119);
 
 	define('LABEL_BASE_INDEX', -1024);
 	define('PLUGIN_FEED_BASE_INDEX', -128);
diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql
index 0d0a8f460..efa7be7cf 100644
--- a/schema/ttrss_schema_mysql.sql
+++ b/schema/ttrss_schema_mysql.sql
@@ -300,7 +300,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
 
-insert into ttrss_version values (118);
+insert into ttrss_version values (119);
 
 create table ttrss_enclosures (id integer primary key auto_increment,
 	content_url text not null,
@@ -385,7 +385,7 @@ insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_HIDE_READ', 1, 'false', 1);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_SORT_FEEDS_UNREAD', 1, 'false', 1);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_THEME_ID', 2, '0', 1);
-insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_TIMEZONE', 2, 'UTC', 1);
+insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_TIMEZONE', 2, 'Automatic', 1);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_STYLESHEET', 2, '', 2);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('SORT_HEADLINES_BY_FEED_DATE', 1, 'false', 2);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_BROWSE_CATS', 1, 'true', 1);
@@ -485,7 +485,7 @@ create table ttrss_error_log(
 	errno integer not null,
 	errstr text not null,
 	filename text not null,
-	lineno integer not null,	
+	lineno integer not null,
 	context text not null,
 	created_at datetime not null,
 	foreign key (owner_uid) references ttrss_users(id) ON DELETE SET NULL) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql
index d81f65f2b..c04e5224b 100644
--- a/schema/ttrss_schema_pgsql.sql
+++ b/schema/ttrss_schema_pgsql.sql
@@ -258,7 +258,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (118);
+insert into ttrss_version values (119);
 
 create table ttrss_enclosures (id serial not null primary key,
 	content_url text not null,
@@ -336,7 +336,7 @@ insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_HIDE_READ', 1, 'false', 1);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_SORT_FEEDS_UNREAD', 1, 'false', 1);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_THEME_ID', 2, '0', 1);
-insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_TIMEZONE', 2, 'UTC', 1);
+insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_TIMEZONE', 2, 'Automatic', 1);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_STYLESHEET', 2, '', 2);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('SORT_HEADLINES_BY_FEED_DATE', 1, 'false', 2);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_BROWSE_CATS', 1, 'true', 1);
@@ -428,7 +428,7 @@ create table ttrss_error_log(
 	errno integer not null,
 	errstr text not null,
 	filename text not null,
-	lineno integer not null,	
+	lineno integer not null,
 	context text not null,
 	created_at timestamp not null);
 
diff --git a/schema/versions/mysql/119.sql b/schema/versions/mysql/119.sql
new file mode 100644
index 000000000..ddb7d64de
--- /dev/null
+++ b/schema/versions/mysql/119.sql
@@ -0,0 +1,7 @@
+begin;
+
+update ttrss_prefs set def_value = 'Automatic' where pref_name = 'USER_TIMEZONE';
+
+update ttrss_version set schema_version = 119;
+
+commit;
diff --git a/schema/versions/pgsql/119.sql b/schema/versions/pgsql/119.sql
new file mode 100644
index 000000000..ddb7d64de
--- /dev/null
+++ b/schema/versions/pgsql/119.sql
@@ -0,0 +1,7 @@
+begin;
+
+update ttrss_prefs set def_value = 'Automatic' where pref_name = 'USER_TIMEZONE';
+
+update ttrss_version set schema_version = 119;
+
+commit;
-- 
cgit v1.2.3-54-g00ecf


From 7b149552cb99a44f1fbeef642ffc60e91b1f61a0 Mon Sep 17 00:00:00 2001
From: Andrew Dolgov <fox@madoka.volgo-balt.ru>
Date: Mon, 29 Apr 2013 15:54:23 +0400
Subject: remove language selector from the login form, store language in the
 database per-user

---
 classes/handler/public.php    | 10 +---------
 classes/pref/prefs.php        | 32 ++++++++------------------------
 include/functions.php         | 19 +++++++------------
 include/login_form.php        |  8 --------
 schema/ttrss_schema_mysql.sql |  3 ++-
 schema/ttrss_schema_pgsql.sql |  3 ++-
 schema/versions/mysql/120.sql |  7 +++++++
 schema/versions/pgsql/120.sql |  7 +++++++
 8 files changed, 34 insertions(+), 55 deletions(-)
 create mode 100644 schema/versions/mysql/120.sql
 create mode 100644 schema/versions/pgsql/120.sql

(limited to 'schema/ttrss_schema_pgsql.sql')

diff --git a/classes/handler/public.php b/classes/handler/public.php
index 0d9b04686..2b5169ca7 100644
--- a/classes/handler/public.php
+++ b/classes/handler/public.php
@@ -478,14 +478,6 @@ class Handler_Public extends Handler {
 				<tr><td align="right"><?php echo __("Password:") ?></td>
 				<td align="right"><input type="password" name="password"
 				value="<?php echo $_SESSION["fake_password"] ?>"></td></tr>
-			<tr><td align="right"><?php echo __("Language:") ?></td>
-			<td align="right">
-			<?php
-				print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
-					"style='width : 100%''");
-
-			?>
-			</td></tr>
 			<tr><td colspan='2'>
 				<button type="submit">
 					<?php echo __('Log in') ?></button>
@@ -518,7 +510,7 @@ class Handler_Public extends Handler {
 			if (authenticate_user($login, $password)) {
 				$_POST["password"] = "";
 
-				$_SESSION["language"] = $_POST["language"];
+				$_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"], false);
 				$_SESSION["ref_schema_version"] = get_schema_version(true);
 				$_SESSION["bw_limit"] = !!$_POST["bw_limit"];
 
diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php
index 35065ea7b..157abb8bc 100644
--- a/classes/pref/prefs.php
+++ b/classes/pref/prefs.php
@@ -54,6 +54,7 @@ class Pref_Prefs extends Handler_Protected {
 			"USER_STYLESHEET" => array(__("Customize stylesheet"), __("Customize CSS stylesheet to your liking")),
 			"USER_TIMEZONE" => array(__("User timezone"), ""),
 			"VFEED_GROUP_BY_FEED" => array(__("Group headlines in virtual feeds"), __("Special feeds, labels, and categories are grouped by originating feeds")),
+			"USER_LANGUAGE" => array(__("Language")),
 			"USER_CSS_THEME" => array(__("Select theme"), __("Select one of the available CSS themes"))
 		);
 	}
@@ -111,18 +112,13 @@ class Pref_Prefs extends Handler_Protected {
 				}
 			}
 
-			if ($pref_name == "language") {
+			if ($pref_name == "USER_LANGUAGE") {
 				if ($_SESSION["language"] != $value) {
-					setcookie("ttrss_lang", $value,
-						time() + COOKIE_LIFETIME_LONG);
-					$_SESSION["language"] = $value;
-
 					$need_reload = true;
 				}
-			} else {
-				set_pref($pref_name, $value);
 			}
 
+			set_pref($pref_name, $value);
 		}
 
 		if ($need_reload) {
@@ -543,22 +539,6 @@ class Pref_Prefs extends Handler_Protected {
 				print "<tr><td colspan=\"3\"><h3>".$section_name."</h3></td></tr>";
 
 				$lnum = 0;
-
-				if ($active_section == 2) {
-					print "<tr>";
-
-					print "<td width=\"40%\" class=\"prefName\">";
-					print "<label>";
-					print __("Language:");
-					print "</label>";
-
-					print "<td>";
-					print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
-						"style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
-					print "</td>";
-					print "</tr>";
-				}
-
 			}
 
 			print "<tr>";
@@ -574,7 +554,11 @@ class Pref_Prefs extends Handler_Protected {
 
 			print "<td class=\"prefValue\">";
 
-			if ($pref_name == "USER_TIMEZONE") {
+			if ($pref_name == "USER_LANGUAGE") {
+				print_select_hash($pref_name, $value, get_translations(),
+					"style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
+
+			} else if ($pref_name == "USER_TIMEZONE") {
 
 				$timezones = explode("\n", file_get_contents("lib/timezones.txt"));
 
diff --git a/include/functions.php b/include/functions.php
index 38c3eac32..b3130104b 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,6 +1,6 @@
 <?php
 	define('EXPECTED_CONFIG_VERSION', 26);
-	define('SCHEMA_VERSION', 119);
+	define('SCHEMA_VERSION', 120);
 
 	define('LABEL_BASE_INDEX', -1024);
 	define('PLUGIN_FEED_BASE_INDEX', -128);
@@ -97,11 +97,12 @@
 			$lang = _TRANSLATION_OVERRIDE_DEFAULT;
 		}
 
-		// startup_gettext() is called before session_start() so we can't rely
-		// on $_SESSION['language'] here.
+		if ($_SESSION["uid"]) {
+			$pref_lang = get_pref("USER_LANGUAGE", $_SESSION["uid"], false);
 
-		if ($_COOKIE["ttrss_lang"] && $_COOKIE["ttrss_lang"] != "auto") {
-			$lang = $_COOKIE["ttrss_lang"];
+			if ($pref_lang) {
+				$lang = $pref_lang;
+			}
 		}
 
 		if ($lang) {
@@ -118,8 +119,6 @@
 		}
 	}
 
-	startup_gettext();
-
 	require_once 'db-prefs.php';
 	require_once 'version.php';
 	require_once 'ccache.php';
@@ -798,12 +797,8 @@
 				$_SESSION["last_login_update"] = time();
 			}
 
-			if ($_SESSION["uid"] && $_SESSION["language"]) {
-				setcookie("ttrss_lang", $_SESSION["language"],
-					time() + COOKIE_LIFETIME_LONG);
-			}
-
 			if ($_SESSION["uid"]) {
+				startup_gettext();
 				load_user_plugins($_SESSION["uid"]);
 
 				/* cleanup ccache */
diff --git a/include/login_form.php b/include/login_form.php
index 9a20e9be9..b7dae1016 100644
--- a/include/login_form.php
+++ b/include/login_form.php
@@ -201,14 +201,6 @@ function bwLimitChange(elem) {
 
 		<?php } ?>
 
-		<div class="row">
-			<label><?php echo __("Language:") ?></label>
-			<?php
-				print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
-					"style='width : 220px; margin : 0px' dojoType='dijit.form.Select'");
-			?>
-		</div>
-
 		<div class="row">
 			<label><?php echo __("Profile:") ?></label>
 
diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql
index efa7be7cf..aa1197091 100644
--- a/schema/ttrss_schema_mysql.sql
+++ b/schema/ttrss_schema_mysql.sql
@@ -300,7 +300,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
 
-insert into ttrss_version values (119);
+insert into ttrss_version values (120);
 
 create table ttrss_enclosures (id integer primary key auto_increment,
 	content_url text not null,
@@ -397,6 +397,7 @@ insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('AUTO_AS
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_ENABLED_PLUGINS', 2, '', 1);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_REVERSE_HEADLINES', 1, 'false', 1);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_CSS_THEME', 2, '', 2);
+insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_LANGUAGE', 2, '', 2);
 
 update ttrss_prefs set access_level = 1 where pref_name in ('ON_CATCHUP_SHOW_NEXT_FEED',
 	'SORT_HEADLINES_BY_FEED_DATE',
diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql
index c04e5224b..79634678d 100644
--- a/schema/ttrss_schema_pgsql.sql
+++ b/schema/ttrss_schema_pgsql.sql
@@ -258,7 +258,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (119);
+insert into ttrss_version values (120);
 
 create table ttrss_enclosures (id serial not null primary key,
 	content_url text not null,
@@ -348,6 +348,7 @@ insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('AUTO_AS
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_ENABLED_PLUGINS', 2, '', 1);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_REVERSE_HEADLINES', 1, 'false', 1);
 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_CSS_THEME', 2, '', 2);
+insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_LANGUAGE', 2, '', 2);
 
 update ttrss_prefs set access_level = 1 where pref_name in ('ON_CATCHUP_SHOW_NEXT_FEED',
 	'SORT_HEADLINES_BY_FEED_DATE',
diff --git a/schema/versions/mysql/120.sql b/schema/versions/mysql/120.sql
new file mode 100644
index 000000000..34971146e
--- /dev/null
+++ b/schema/versions/mysql/120.sql
@@ -0,0 +1,7 @@
+begin;
+
+insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_LANGUAGE', 2, '', 2);
+
+update ttrss_version set schema_version = 120;
+
+commit;
diff --git a/schema/versions/pgsql/120.sql b/schema/versions/pgsql/120.sql
new file mode 100644
index 000000000..34971146e
--- /dev/null
+++ b/schema/versions/pgsql/120.sql
@@ -0,0 +1,7 @@
+begin;
+
+insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_LANGUAGE', 2, '', 2);
+
+update ttrss_version set schema_version = 120;
+
+commit;
-- 
cgit v1.2.3-54-g00ecf

