summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorLynx Linden <lynx@lindenlab.com>2009-12-15 16:00:28 +0000
committerLynx Linden <lynx@lindenlab.com>2009-12-15 16:00:28 +0000
commit870d4449f5eec1c2a7e5e4627a0433846ab256aa (patch)
tree978b060155de581f627fd52c74eba63643829aad /indra/newview
parentd82f82d7965ec9360cb49ec7e6c1c2f984d4539b (diff)
EXT-3441: Support various substitutions for Search URL.
The search URL is now specified in app_settings/settings.xml (instead of in floater_search.xml), and it is now defined more flexibly with support for various substitution strings, such as [QUERY], [AUTH_KEY], [MATURITY], [GODLIKE], etc. I pulled the common substitution code out into a new static method, LLWeb::expandURLSubstitutions(). This provides support for common strings like [VERSION], [CHANNEL], [LANGUAGE], [OS], etc. The Help and Home sidetray code has been updated to use this new function, to avoid replicating this behavior 3 times. I also cleaned up the app_settings/settings.xml file and removed the old search keys of: SearchURLDefault, SearchURLQuery, and SearchURLSuffix2.
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/app_settings/settings.xml50
-rw-r--r--indra/newview/llfloatersearch.cpp38
-rw-r--r--indra/newview/llviewerhelp.cpp3
-rw-r--r--indra/newview/llviewerhelputil.cpp43
-rw-r--r--indra/newview/llviewerhelputil.h4
-rw-r--r--indra/newview/llviewerhome.cpp15
-rw-r--r--indra/newview/llweb.cpp34
-rw-r--r--indra/newview/llweb.h5
-rw-r--r--indra/newview/skins/default/xui/en/floater_search.xml4
-rw-r--r--indra/newview/tests/llviewerhelputil_test.cpp122
10 files changed, 147 insertions, 171 deletions
diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index 7ac7a09d56..f00b100217 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -3587,6 +3587,17 @@
<key>Value</key>
<string>http://www.secondlife.com/</string>
</map>
+ <key>SearchURL</key>
+ <map>
+ <key>Comment</key>
+ <string>URL for Search website, displayed in the Find floater</string>
+ <key>Persist</key>
+ <integer>0</integer>
+ <key>Type</key>
+ <string>String</string>
+ <key>Value</key>
+ <string>http://int.searchwww-phx0.damballah.lindenlab.com/viewer/[CATEGORY]?q=[QUERY]&amp;p=[AUTH_KEY]&amp;r=[MATURITY]&amp;lang=[LANGUAGE]&amp;g=[GODLIKE]</string>
+ </map>
<key>HighResSnapshot</key>
<map>
<key>Comment</key>
@@ -7539,45 +7550,6 @@
<key>Value</key>
<integer>0</integer>
</map>
- <key>SearchURLDefault</key>
- <map>
- <key>Comment</key>
- <string>URL to load for empty searches</string>
- <key>Persist</key>
- <integer>1</integer>
- <key>HideFromEditor</key>
- <integer>1</integer>
- <key>Type</key>
- <string>String</string>
- <key>Value</key>
- <string>http://search.secondlife.com/client_search.php?</string>
- </map>
- <key>SearchURLQuery</key>
- <map>
- <key>Comment</key>
- <string>URL to use for searches</string>
- <key>Persist</key>
- <integer>1</integer>
- <key>HideFromEditor</key>
- <integer>1</integer>
- <key>Type</key>
- <string>String</string>
- <key>Value</key>
- <string>http://search.secondlife.com/client_search.php?q=[QUERY]&amp;s=[COLLECTION]&amp;</string>
- </map>
- <key>SearchURLSuffix2</key>
- <map>
- <key>Comment</key>
- <string>Parameters added to end of search queries</string>
- <key>Persist</key>
- <integer>1</integer>
- <key>HideFromEditor</key>
- <integer>1</integer>
- <key>Type</key>
- <string>String</string>
- <key>Value</key>
- <string>lang=[LANG]&amp;mat=[MATURITY]&amp;t=[TEEN]&amp;region=[REGION]&amp;x=[X]&amp;y=[Y]&amp;z=[Z]&amp;session=[SESSION]</string>
- </map>
<key>SelectMovableOnly</key>
<map>
<key>Comment</key>
diff --git a/indra/newview/llfloatersearch.cpp b/indra/newview/llfloatersearch.cpp
index c658963708..b197ed0ac6 100644
--- a/indra/newview/llfloatersearch.cpp
+++ b/indra/newview/llfloatersearch.cpp
@@ -38,6 +38,8 @@
#include "lluri.h"
#include "llagent.h"
#include "llui.h"
+#include "llviewercontrol.h"
+#include "llweb.h"
LLFloaterSearch::LLFloaterSearch(const LLSD& key) :
LLFloater(key),
@@ -65,7 +67,6 @@ BOOL LLFloaterSearch::postBuild()
{
mBrowser->addObserver(this);
mBrowser->setTrusted(true);
- mBrowser->setHomePageUrl(getString("search_url"));
}
return TRUE;
@@ -113,33 +114,27 @@ void LLFloaterSearch::search(const LLSD &key)
childHide("refresh_search");
mSearchGodLevel = gAgent.getGodLevel();
- // get the URL for the search page
- std::string url = getString("search_url");
- if (! LLStringUtil::endsWith(url, "/"))
- {
- url += "/";
- }
-
// work out the subdir to use based on the requested category
+ LLSD subs;
std::string category = key.has("category") ? key["category"].asString() : "";
if (mCategoryPaths.has(category))
{
- url += mCategoryPaths[category].asString();
+ subs["CATEGORY"] = mCategoryPaths[category].asString();
}
else
{
- url += mCategoryPaths["all"].asString();
+ subs["CATEGORY"] = mCategoryPaths["all"].asString();
}
- // append the search query string
+ // add the search query string
std::string search_text = key.has("id") ? key["id"].asString() : "";
- url += std::string("?q=") + LLURI::escape(search_text);
+ subs["QUERY"] = LLURI::escape(search_text);
- // append the permissions token that login.cgi gave us
+ // add the permissions token that login.cgi gave us
LLSD search_token = LLLoginInstance::getInstance()->getResponse("search_token");
- url += "&p=" + search_token.asString();
+ subs["AUTH_KEY"] = search_token.asString();
- // also append the user's preferred maturity (can be changed via prefs)
+ // add the user's preferred maturity (can be changed via prefs)
std::string maturity;
if (gAgent.prefersAdult())
{
@@ -153,14 +148,15 @@ void LLFloaterSearch::search(const LLSD &key)
{
maturity = "13"; // PG
}
- url += "&r=" + maturity;
-
- // add the current localization information
- url += "&lang=" + LLUI::getLanguage();
+ subs["MATURITY"] = maturity;
// add the user's god status
- std::string godlike = gAgent.isGodlike() ? "1" : "0";
- url += "&g=" + godlike;
+ subs["GODLIKE"] = gAgent.isGodlike() ? "1" : "0";
+
+ // get the search URL and expand all of the substitutions
+ // (also adds things like [LANGUAGE], [VERSION], [OS], etc.)
+ std::string url = gSavedSettings.getString("SearchURL");
+ url = LLWeb::expandURLSubstitutions(url, subs);
// and load the URL in the web view
mBrowser->navigateTo(url);
diff --git a/indra/newview/llviewerhelp.cpp b/indra/newview/llviewerhelp.cpp
index b8f91697e5..5af79b4fd3 100644
--- a/indra/newview/llviewerhelp.cpp
+++ b/indra/newview/llviewerhelp.cpp
@@ -81,8 +81,7 @@ void LLViewerHelp::showTopic(const std::string &topic)
// work out the URL for this topic and display it
showHelp();
- const LLOSInfo& osinfo = LLAppViewer::instance()->getOSInfo();
- std::string helpURL = LLViewerHelpUtil::buildHelpURL( help_topic, gSavedSettings, osinfo );
+ std::string helpURL = LLViewerHelpUtil::buildHelpURL( help_topic );
setRawURL( helpURL );
}
diff --git a/indra/newview/llviewerhelputil.cpp b/indra/newview/llviewerhelputil.cpp
index df08470518..5ba4fc834c 100644
--- a/indra/newview/llviewerhelputil.cpp
+++ b/indra/newview/llviewerhelputil.cpp
@@ -34,12 +34,11 @@
#include "llviewerprecompiledheaders.h"
#include "llviewerhelputil.h"
-#include "llcontrol.h"
+#include "llsd.h"
#include "llstring.h"
-#include "llsys.h"
#include "lluri.h"
-#include "llversioninfo.h"
-
+#include "llweb.h"
+#include "llviewercontrol.h"
//////////////////////////////////////////////
// Build a help URL from a topic and formatter
@@ -59,40 +58,14 @@ std::string LLViewerHelpUtil::helpURLEncode( const std::string &component )
return escaped;
}
-static std::string buildHelpVersion( const U32 ver_int )
-{
- std::ostringstream ver_str;
- ver_str << ver_int;
- return ver_str.str(); // not encoded - numbers are rfc3986-safe
-}
-
//static
-std::string LLViewerHelpUtil::buildHelpURL( const std::string &topic,
- LLControlGroup &savedSettings,
- const LLOSInfo &osinfo )
+std::string LLViewerHelpUtil::buildHelpURL( const std::string &topic)
{
- std::string helpURL = savedSettings.getString("HelpURLFormat");
LLSD substitution;
substitution["TOPIC"] = helpURLEncode(topic);
- substitution["CHANNEL"] = helpURLEncode(savedSettings.getString("VersionChannelName"));
-
- substitution["VERSION"] = helpURLEncode(LLVersionInfo::getVersion());
- substitution["VERSION_MAJOR"] = buildHelpVersion(LLVersionInfo::getMajor());
- substitution["VERSION_MINOR"] = buildHelpVersion(LLVersionInfo::getMinor());
- substitution["VERSION_PATCH"] = buildHelpVersion(LLVersionInfo::getPatch());
- substitution["VERSION_BUILD"] = buildHelpVersion(LLVersionInfo::getBuild());
-
- substitution["OS"] = helpURLEncode(osinfo.getOSStringSimple());
-
- std::string language = savedSettings.getString("Language");
- if( language.empty() || language == "default" )
- {
- language = savedSettings.getString("SystemLanguage");
- }
- substitution["LANGUAGE"] = helpURLEncode(language);
-
- LLStringUtil::format(helpURL, substitution);
-
- return helpURL;
+ // get the help URL and expand all of the substitutions
+ // (also adds things like [LANGUAGE], [VERSION], [OS], etc.)
+ std::string helpURL = gSavedSettings.getString("HelpURLFormat");
+ return LLWeb::expandURLSubstitutions(helpURL, substitution);
}
diff --git a/indra/newview/llviewerhelputil.h b/indra/newview/llviewerhelputil.h
index 8ee0d96023..95e6744842 100644
--- a/indra/newview/llviewerhelputil.h
+++ b/indra/newview/llviewerhelputil.h
@@ -41,9 +41,7 @@ class LLViewerHelpUtil
{
public:
static std::string helpURLEncode( const std::string &component );
- static std::string buildHelpURL( const std::string &topic,
- LLControlGroup &savedSettings,
- const LLOSInfo &osinfo);
+ static std::string buildHelpURL( const std::string &topic );
};
#endif // header guard
diff --git a/indra/newview/llviewerhome.cpp b/indra/newview/llviewerhome.cpp
index 58630978c4..2bae07f665 100644
--- a/indra/newview/llviewerhome.cpp
+++ b/indra/newview/llviewerhome.cpp
@@ -35,12 +35,11 @@
#include "llviewerhome.h"
#include "lllogininstance.h"
+#include "llsd.h"
#include "llui.h"
#include "lluri.h"
-#include "llsd.h"
-#include "llversioninfo.h"
#include "llviewercontrol.h"
-#include "llviewernetwork.h"
+#include "llweb.h"
//static
std::string LLViewerHome::getHomeURL()
@@ -49,16 +48,12 @@ std::string LLViewerHome::getHomeURL()
// this value from settings.xml and support various substitutions
LLSD substitution;
- substitution["VERSION"] = LLVersionInfo::getVersion();
- substitution["CHANNEL"] = LLURI::escape(gSavedSettings.getString("VersionChannelName"));
- substitution["LANGUAGE"] = LLUI::getLanguage();
substitution["AUTH_KEY"] = LLURI::escape(getAuthKey());
- substitution["GRID"] = LLViewerLogin::getInstance()->getGridLabel();
+ // get the home URL and expand all of the substitutions
+ // (also adds things like [LANGUAGE], [VERSION], [OS], etc.)
std::string homeURL = gSavedSettings.getString("HomeSidePanelURL");
- LLStringUtil::format(homeURL, substitution);
-
- return homeURL;
+ return LLWeb::expandURLSubstitutions(homeURL, substitution);
}
//static
diff --git a/indra/newview/llweb.cpp b/indra/newview/llweb.cpp
index 72431bd22f..045bef294e 100644
--- a/indra/newview/llweb.cpp
+++ b/indra/newview/llweb.cpp
@@ -38,12 +38,19 @@
// Library includes
#include "llwindow.h" // spawnWebBrowser()
-#include "llviewerwindow.h"
-#include "llviewercontrol.h"
+#include "llalertdialog.h"
+#include "llappviewer.h"
#include "llfloatermediabrowser.h"
#include "llfloaterreg.h"
-#include "llalertdialog.h"
+#include "lllogininstance.h"
+#include "llsd.h"
#include "lltoastalertpanel.h"
+#include "llui.h"
+#include "lluri.h"
+#include "llversioninfo.h"
+#include "llviewercontrol.h"
+#include "llviewernetwork.h"
+#include "llviewerwindow.h"
class URLLoader : public LLAlertURLLoader
{
@@ -124,3 +131,24 @@ std::string LLWeb::escapeURL(const std::string& url)
}
return escaped_url;
}
+
+//static
+std::string LLWeb::expandURLSubstitutions(const std::string &url,
+ const LLSD &default_subs)
+{
+ LLSD substitution = default_subs;
+ substitution["VERSION"] = LLVersionInfo::getVersion();
+ substitution["VERSION_MAJOR"] = LLVersionInfo::getMajor();
+ substitution["VERSION_MINOR"] = LLVersionInfo::getMinor();
+ substitution["VERSION_PATCH"] = LLVersionInfo::getPatch();
+ substitution["VERSION_BUILD"] = LLVersionInfo::getBuild();
+ substitution["CHANNEL"] = LLVersionInfo::getChannel();
+ substitution["LANGUAGE"] = LLUI::getLanguage();
+ substitution["GRID"] = LLViewerLogin::getInstance()->getGridLabel();
+ substitution["OS"] = LLAppViewer::instance()->getOSInfo().getOSStringSimple();
+
+ std::string expanded_url = url;
+ LLStringUtil::format(expanded_url, substitution);
+
+ return LLWeb::escapeURL(expanded_url);
+}
diff --git a/indra/newview/llweb.h b/indra/newview/llweb.h
index 96a53db2ca..f4666c9280 100644
--- a/indra/newview/llweb.h
+++ b/indra/newview/llweb.h
@@ -57,8 +57,11 @@ public:
/// Load the given url in the operating system's web browser
static void loadURLExternal(const std::string& url);
- // Returns escaped url (eg, " " to "%20") - used by all loadURL methods
+ /// Returns escaped url (eg, " " to "%20") - used by all loadURL methods
static std::string escapeURL(const std::string& url);
+ /// Expands various strings like [LANG], [VERSION], etc. in a URL
+ static std::string expandURLSubstitutions(const std::string &url,
+ const LLSD &default_subs);
};
#endif
diff --git a/indra/newview/skins/default/xui/en/floater_search.xml b/indra/newview/skins/default/xui/en/floater_search.xml
index e6bdcdf78e..9c1a5499db 100644
--- a/indra/newview/skins/default/xui/en/floater_search.xml
+++ b/indra/newview/skins/default/xui/en/floater_search.xml
@@ -13,10 +13,6 @@
title="FIND"
width="670">
<floater.string
- name="search_url">
- http://int.searchwww-phx0.damballah.lindenlab.com/viewer
- </floater.string>
- <floater.string
name="loading_text">
Loading...
</floater.string>
diff --git a/indra/newview/tests/llviewerhelputil_test.cpp b/indra/newview/tests/llviewerhelputil_test.cpp
index 68743357a6..ec612c4606 100644
--- a/indra/newview/tests/llviewerhelputil_test.cpp
+++ b/indra/newview/tests/llviewerhelputil_test.cpp
@@ -36,54 +36,59 @@
#include "../test/lltut.h"
#include "../llviewerhelputil.h"
-#include "../llversioninfo.h"
+#include "../llweb.h"
#include "llcontrol.h"
-#include "llsys.h"
#include <iostream>
-//----------------------------------------------------------------------------
-// Implementation of enough of LLControlGroup to support the tests:
+// values for all of the supported substitutions parameters
+static std::string gHelpURL;
+static std::string gVersion;
+static std::string gChannel;
+static std::string gLanguage;
+static std::string gGrid;
+static std::string gOS;
-static std::map<std::string,std::string> test_stringvec;
+//----------------------------------------------------------------------------
+// Mock objects for the dependencies of the code we're testing
LLControlGroup::LLControlGroup(const std::string& name)
- : LLInstanceTracker<LLControlGroup, std::string>(name)
-{
-}
-
-LLControlGroup::~LLControlGroup()
-{
-}
-
-// Implementation of just the LLControlGroup methods we requre
+ : LLInstanceTracker<LLControlGroup, std::string>(name) {}
+LLControlGroup::~LLControlGroup() {}
BOOL LLControlGroup::declareString(const std::string& name,
const std::string& initial_val,
const std::string& comment,
- BOOL persist)
-{
- test_stringvec[name] = initial_val;
- return true;
-}
-
-void LLControlGroup::setString(const std::string& name, const std::string& val)
+ BOOL persist) {return TRUE;}
+void LLControlGroup::setString(const std::string& name, const std::string& val){}
+std::string LLControlGroup::getString(const std::string& name)
{
- test_stringvec[name] = val;
+ if (name == "HelpURLFormat")
+ return gHelpURL;
+ return "";
}
+LLControlGroup gSavedSettings("test");
-std::string LLControlGroup::getString(const std::string& name)
+static void substitute_string(std::string &input, const std::string &search, const std::string &replace)
{
- return test_stringvec[name];
+ size_t pos = input.find(search);
+ while (pos != std::string::npos)
+ {
+ input = input.replace(pos, search.size(), replace);
+ pos = input.find(search);
+ }
}
-S32 LLVersionInfo::getMajor() { return 2; }
-S32 LLVersionInfo::getMinor() { return 0; }
-S32 LLVersionInfo::getPatch() { return 0; }
-S32 LLVersionInfo::getBuild() { return 200099; }
-const std::string &LLVersionInfo::getVersion()
+std::string LLWeb::expandURLSubstitutions(const std::string &url,
+ const LLSD &default_subs)
{
- static std::string version = "2.0.0.200099";
- return version;
+ std::string new_url = url;
+ substitute_string(new_url, "[TOPIC]", default_subs["TOPIC"].asString());
+ substitute_string(new_url, "[VERSION]", gVersion);
+ substitute_string(new_url, "[CHANNEL]", gChannel);
+ substitute_string(new_url, "[LANGUAGE]", gLanguage);
+ substitute_string(new_url, "[GRID]", gGrid);
+ substitute_string(new_url, "[OS]", gOS);
+ return new_url;
}
//----------------------------------------------------------------------------
@@ -101,41 +106,52 @@ namespace tut
template<> template<>
void viewerhelputil_object_t::test<1>()
{
- LLOSInfo osinfo;
- LLControlGroup cgr("test");
- cgr.declareString("HelpURLFormat", "fooformat", "declared_for_test", FALSE);
- cgr.declareString("VersionChannelName", "foochannelname", "declared_for_test", FALSE);
- cgr.declareString("Language", "foolanguage", "declared_for_test", FALSE);
std::string topic("test_topic");
-
std::string subresult;
- cgr.setString("HelpURLFormat", "fooformat");
- subresult = LLViewerHelpUtil::buildHelpURL(topic, cgr, osinfo);
+ gHelpURL = "fooformat";
+ subresult = LLViewerHelpUtil::buildHelpURL(topic);
ensure_equals("no substitution tags", subresult, "fooformat");
- cgr.setString("HelpURLFormat", "");
- subresult = LLViewerHelpUtil::buildHelpURL(topic, cgr, osinfo);
+ gHelpURL = "";
+ subresult = LLViewerHelpUtil::buildHelpURL(topic);
ensure_equals("blank substitution format", subresult, "");
- cgr.setString("HelpURLFormat", "[LANGUAGE]");
- cgr.setString("Language", "");
- subresult = LLViewerHelpUtil::buildHelpURL(topic, cgr, osinfo);
+ gHelpURL = "[TOPIC]";
+ subresult = LLViewerHelpUtil::buildHelpURL(topic);
+ ensure_equals("topic name", subresult, "test_topic");
+
+ gHelpURL = "[LANGUAGE]";
+ gLanguage = "";
+ subresult = LLViewerHelpUtil::buildHelpURL(topic);
ensure_equals("simple substitution with blank", subresult, "");
- cgr.setString("HelpURLFormat", "[LANGUAGE]");
- cgr.setString("Language", "Esperanto");
- subresult = LLViewerHelpUtil::buildHelpURL(topic, cgr, osinfo);
+ gHelpURL = "[LANGUAGE]";
+ gLanguage = "Esperanto";
+ subresult = LLViewerHelpUtil::buildHelpURL(topic);
ensure_equals("simple substitution", subresult, "Esperanto");
- cgr.setString("HelpURLFormat", "[XXX]");
- subresult = LLViewerHelpUtil::buildHelpURL(topic, cgr, osinfo);
+ gHelpURL = "http://secondlife.com/[LANGUAGE]";
+ gLanguage = "Gaelic";
+ subresult = LLViewerHelpUtil::buildHelpURL(topic);
+ ensure_equals("simple substitution with url", subresult, "http://secondlife.com/Gaelic");
+
+ gHelpURL = "[XXX]";
+ subresult = LLViewerHelpUtil::buildHelpURL(topic);
ensure_equals("unknown substitution", subresult, "[XXX]");
- cgr.setString("HelpURLFormat", "[LANGUAGE]/[LANGUAGE]");
- cgr.setString("Language", "Esperanto");
- subresult = LLViewerHelpUtil::buildHelpURL(topic, cgr, osinfo);
+ gHelpURL = "[LANGUAGE]/[LANGUAGE]";
+ gLanguage = "Esperanto";
+ subresult = LLViewerHelpUtil::buildHelpURL(topic);
ensure_equals("multiple substitution", subresult, "Esperanto/Esperanto");
+
+ gHelpURL = "http://[CHANNEL]/[VERSION]/[LANGUAGE]/[OS]/[GRID]/[XXX]";
+ gChannel = "Second Life Test";
+ gVersion = "2.0";
+ gLanguage = "gaelic";
+ gOS = "AmigaOS 2.1";
+ gGrid = "mysim";
+ subresult = LLViewerHelpUtil::buildHelpURL(topic);
+ ensure_equals("complex substitution", subresult, "http://Second Life Test/2.0/gaelic/AmigaOS 2.1/mysim/[XXX]");
}
-
}