Revision history for CompatibilityCode


Revision [23194]

Last edited on 2016-05-20 07:38:47 by JavaWoman [Replaces old-style internal links with new pipe-split links.]
Additions:
//Installed to support a [[WikkaBetaFeatures | beta feature]] on this server as of 2005-06-12.//
The function ##html_entity_decode()## is available in PHP as of version 4.3. The [[AdvancedFormatter | "advanced" formatter]] makes use of it when generating ids for headings. The following code provides a //near// equivalent. Insert in ##wikka.php## immediately after the **##mysql_real_escape_string()##** compatibility code shown above:
//Installed to support a [[WikkaBetaFeatures | beta feature]] on this server as of 2005-06-12 (including the **efficiency** change).//
The current (version 1.1.6.0) [[Docs:CategoryActionInfo | category action]] uses the following bit of code to gather the the members of a category:
So for the [[AdvancedCategoryAction | advanced category action]] this code was spirited away in a new core function **##getCatMembers()##** - insert this right after ##""FullCategoryTextSearch()""## in ##wikka.php## at line 438:
Deletions:
//Installed to support a [[WikkaBetaFeatures beta feature]] on this server as of 2005-06-12.//
The function ##html_entity_decode()## is available in PHP as of version 4.3. The [[AdvancedFormatter "advanced" formatter]] makes use of it when generating ids for headings. The following code provides a //near// equivalent. Insert in ##wikka.php## immediately after the **##mysql_real_escape_string()##** compatibility code shown above:
//Installed to support a [[WikkaBetaFeatures beta feature]] on this server as of 2005-06-12 (including the **efficiency** change).//
The current (version 1.1.6.0) [[Docs:CategoryActionInfo category action]] uses the following bit of code to gather the the members of a category:
So for the [[AdvancedCategoryAction advanced category action]] this code was spirited away in a new core function **##getCatMembers()##** - insert this right after ##""FullCategoryTextSearch()""## in ##wikka.php## at line 438:


Revision [19136]

Edited on 2008-01-28 00:14:03 by JavaWoman [Modified links pointing to docs server]
Additions:
The current (version 1.1.6.0) [[Docs:CategoryActionInfo category action]] uses the following bit of code to gather the the members of a category:
Deletions:
The current (version 1.1.6.0) [[CategoryActionInfo category action]] uses the following bit of code to gather the the members of a category:


Revision [16875]

Edited on 2007-05-31 23:26:53 by JavaWoman [Reverted]
Additions:
function magicQuotesSuck(&$a)
if (is_array($a))
foreach ($a as $k => $v)
{
if (is_array($v))
magicQuotesSuck($a[$k]);
else
$a[$k] = stripslashes($v);
}
set_magic_quotes_runtime(0);
if (get_magic_quotes_gpc())
magicQuotesSuck($_POST);
magicQuotesSuck($_GET);
magicQuotesSuck($_COOKIE);
%%---
In a future version this would be better placed together with other compatibility code near the start and maybe get a more "polite" name. :)
====Proposed new compatibility code====
This is compatibility code needed for or used used by new code development presented on this site.
===##html_entity_decode()##===
//Installed to support a [[WikkaBetaFeatures beta feature]] on this server as of 2005-06-12.//
The function ##html_entity_decode()## is available in PHP as of version 4.3. The [[AdvancedFormatter "advanced" formatter]] makes use of it when generating ids for headings. The following code provides a //near// equivalent. Insert in ##wikka.php## immediately after the **##mysql_real_escape_string()##** compatibility code shown above:
%%(php;1)if (!function_exists('html_entity_decode'))
// based on http://php.net/html-entity-decode.php
// third parameter (charset) ignored: only (default) ISO-8859-1 character set supported
function html_entity_decode($string,$quote_style=ENT_COMPAT)
$trans_tbl = get_html_translation_table(HTML_ENTITIES,$quote_style);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
Note that it is not completely equivalent: ##html_entity_decode()## in PHP 4.3+ provides support for a range of character sets (including UTF-8); the character set can be specified in a third parameter. The function ##get_html_translation_table()## we use to provide compatibility only uses the default charset ISO-8859-1; when this code is used in versiosn of PHP lower than 4.3 any third parameter will be ignored.
//Note that for the case this was written (generating ids for headings) we actually **need** ISO-8859-1, so for that application lack of equivalence it is not a problem; used in another context it may be and one should be aware of the limitations.//
===##getCatMembers()##===
//Installed to support a [[WikkaBetaFeatures beta feature]] on this server as of 2005-06-12 (including the **efficiency** change).//
Hiding decision logic.
The current (version 1.1.6.0) [[CategoryActionInfo category action]] uses the following bit of code to gather the the members of a category:
**##./actions/category.php##**
%%(php;18) if ($this->CheckMySQLVersion(4,0,1))
$results = $this->FullCategoryTextSearch($page);
else
$results = $this->FullTextSearch($page);
This type of decision logic doesn't belong in an action (or a handler for that matter): if we'd decide to support a different set of versions of PHP and MySQL we'd have to trail through all of our code to find ths kind of decision logic. Instead, there should be a single method call to a method that hides the decision process about what function to use when.
So for the [[AdvancedCategoryAction advanced category action]] this code was spirited away in a new core function **##getCatMembers()##** - insert this right after ##""FullCategoryTextSearch()""## in ##wikka.php## at line 438:
%%(php;1) /**
* Find category members, hiding version-dependent implementation from caller.
*
* @uses CheckMySQLVersion()
* @uses FullCategoryTextSearch()
* @uses FullTextSearch()
*
* @todo - replace FullTextSearch() with a query that returns only tag
* - replace CheckMySQLVersion() with PHP's generiic function
*
* @param string $category required: category to find members of.
* @return array rows with page data (for pages that refer to the category name)
*/
function getCatMembers($category)
if ($this->CheckMySQLVersion(4,0,1))
{
return $this->FullCategoryTextSearch($category);
}
else
{
return $this->FullTextSearch($category); # @@@ could be more efficient by returning only 'tag'
}
%%---
This not only hides //which// function to call, but also //how// that decision is made. In fact, it's now completely hidden how category members are gathered at all: if we'd install a different system such as a categories table, the //content// of the method would change to query that table, but the category action would not need to be changed at all.
==Efficiency==
The method ##""FullCategoryTextSearch()""## is (indirectly now via ##""getCatMembers()""##) used //only// by the category action. All the action needs to work with is **page names** - but if we look at the query used by the action we see it's actually retrieving all columns (*), including the whole page body (line 438 in the release version):
%%(php) function FullCategoryTextSearch($phrase) { return $this->LoadAll("select * from ".$this->config["table_prefix"]."pages where latest = 'Y' and match(body) against('".mysql_real_escape_string($phrase)."' IN BOOLEAN MODE)"); }%%
It's only a trivial change to get only the page name ('tag'):
%%(php) function FullCategoryTextSearch($phrase) { return $this->LoadAll("SELECT tag FROM ".$this->config["table_prefix"]."pages WHERE latest = 'Y' AND MATCH(body) AGAINST('".mysql_real_escape_string($phrase)."' IN BOOLEAN MODE)"); }%%
''Looking at ##""FullTextSearch()""##, this is not only used (indirectly) by the category action but also the **textsearch** and **textsearchexpanded** actions. This method also asks for all columns (*) but only the **textsearchexpanded** action actually uses the 'body' field as well as the 'tag' field. This could be made more efficient (for the **textsearch** action at least) by adding an extra parameter to the method to tell it which field(s) to retrieve. However, that would also involve a change in at least one of those actions; that is outside the scope of this page.''
Refer to WikkaOptimization for more optimization issues.
----
CategoryDevelopmentCore
Deletions:
function magicQuotesSuck(


Revision [16673]

Edited on 2007-05-31 10:34:50 by EvtOux [Reverted]
Additions:
function magicQuotesSuck(
Deletions:
function magicQuotesSuck(&$a)
if (is_array($a))
foreach ($a as $k => $v)
{
if (is_array($v))
magicQuotesSuck($a[$k]);
else
$a[$k] = stripslashes($v);
}
set_magic_quotes_runtime(0);
if (get_magic_quotes_gpc())
magicQuotesSuck($_POST);
magicQuotesSuck($_GET);
magicQuotesSuck($_COOKIE);
%%---
In a future version this would be better placed together with other compatibility code near the start and maybe get a more "polite" name. :)
====Proposed new compatibility code====
This is compatibility code needed for or used used by new code development presented on this site.
===##html_entity_decode()##===
//Installed to support a [[WikkaBetaFeatures beta feature]] on this server as of 2005-06-12.//
The function ##html_entity_decode()## is available in PHP as of version 4.3. The [[AdvancedFormatter "advanced" formatter]] makes use of it when generating ids for headings. The following code provides a //near// equivalent. Insert in ##wikka.php## immediately after the **##mysql_real_escape_string()##** compatibility code shown above:
%%(php;1)if (!function_exists('html_entity_decode'))
// based on http://php.net/html-entity-decode.php
// third parameter (charset) ignored: only (default) ISO-8859-1 character set supported
function html_entity_decode($string,$quote_style=ENT_COMPAT)
$trans_tbl = get_html_translation_table(HTML_ENTITIES,$quote_style);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
Note that it is not completely equivalent: ##html_entity_decode()## in PHP 4.3+ provides support for a range of character sets (including UTF-8); the character set can be specified in a third parameter. The function ##get_html_translation_table()## we use to provide compatibility only uses the default charset ISO-8859-1; when this code is used in versiosn of PHP lower than 4.3 any third parameter will be ignored.
//Note that for the case this was written (generating ids for headings) we actually **need** ISO-8859-1, so for that application lack of equivalence it is not a problem; used in another context it may be and one should be aware of the limitations.//
===##getCatMembers()##===
//Installed to support a [[WikkaBetaFeatures beta feature]] on this server as of 2005-06-12 (including the **efficiency** change).//
Hiding decision logic.
The current (version 1.1.6.0) [[CategoryActionInfo category action]] uses the following bit of code to gather the the members of a category:
**##./actions/category.php##**
%%(php;18) if ($this->CheckMySQLVersion(4,0,1))
$results = $this->FullCategoryTextSearch($page);
else
$results = $this->FullTextSearch($page);
This type of decision logic doesn't belong in an action (or a handler for that matter): if we'd decide to support a different set of versions of PHP and MySQL we'd have to trail through all of our code to find ths kind of decision logic. Instead, there should be a single method call to a method that hides the decision process about what function to use when.
So for the [[AdvancedCategoryAction advanced category action]] this code was spirited away in a new core function **##getCatMembers()##** - insert this right after ##""FullCategoryTextSearch()""## in ##wikka.php## at line 438:
%%(php;1) /**
* Find category members, hiding version-dependent implementation from caller.
*
* @uses CheckMySQLVersion()
* @uses FullCategoryTextSearch()
* @uses FullTextSearch()
*
* @todo - replace FullTextSearch() with a query that returns only tag
* - replace CheckMySQLVersion() with PHP's generiic function
*
* @param string $category required: category to find members of.
* @return array rows with page data (for pages that refer to the category name)
*/
function getCatMembers($category)
if ($this->CheckMySQLVersion(4,0,1))
{
return $this->FullCategoryTextSearch($category);
}
else
{
return $this->FullTextSearch($category); # @@@ could be more efficient by returning only 'tag'
}
%%---
This not only hides //which// function to call, but also //how// that decision is made. In fact, it's now completely hidden how category members are gathered at all: if we'd install a different system such as a categories table, the //content// of the method would change to query that table, but the category action would not need to be changed at all.
==Efficiency==
The method ##""FullCategoryTextSearch()""## is (indirectly now via ##""getCatMembers()""##) used //only// by the category action. All the action needs to work with is **page names** - but if we look at the query used by the action we see it's actually retrieving all columns (*), including the whole page body (line 438 in the release version):
%%(php) function FullCategoryTextSearch($phrase) { return $this->LoadAll("select * from ".$this->config["table_prefix"]."pages where latest = 'Y' and match(body) against('".mysql_real_escape_string($phrase)."' IN BOOLEAN MODE)"); }%%
It's only a trivial change to get only the page name ('tag'):
%%(php) function FullCategoryTextSearch($phrase) { return $this->LoadAll("SELECT tag FROM ".$this->config["table_prefix"]."pages WHERE latest = 'Y' AND MATCH(body) AGAINST('".mysql_real_escape_string($phrase)."' IN BOOLEAN MODE)"); }%%
''Looking at ##""FullTextSearch()""##, this is not only used (indirectly) by the category action but also the **textsearch** and **textsearchexpanded** actions. This method also asks for all columns (*) but only the **textsearchexpanded** action actually uses the 'body' field as well as the 'tag' field. This could be made more efficient (for the **textsearch** action at least) by adding an extra parameter to the method to tell it which field(s) to retrieve. However, that would also involve a change in at least one of those actions; that is outside the scope of this page.''
Refer to WikkaOptimization for more optimization issues.
----
CategoryDevelopmentCore


Revision [9154]

Edited on 2005-06-12 17:59:43 by JavaWoman [adding link]
Additions:
~-AdvancedCategoryAction


Revision [9153]

Edited on 2005-06-12 17:58:38 by JavaWoman [refs to beta feautres]
Additions:
//Installed to support a [[WikkaBetaFeatures beta feature]] on this server as of 2005-06-12.//
//Installed to support a [[WikkaBetaFeatures beta feature]] on this server as of 2005-06-12 (including the **efficiency** change).//


Revision [9006]

Edited on 2005-06-08 19:35:28 by JavaWoman [Efficiency section]
Additions:
==Efficiency==
The method ##""FullCategoryTextSearch()""## is (indirectly now via ##""getCatMembers()""##) used //only// by the category action. All the action needs to work with is **page names** - but if we look at the query used by the action we see it's actually retrieving all columns (*), including the whole page body (line 438 in the release version):
%%(php) function FullCategoryTextSearch($phrase) { return $this->LoadAll("select * from ".$this->config["table_prefix"]."pages where latest = 'Y' and match(body) against('".mysql_real_escape_string($phrase)."' IN BOOLEAN MODE)"); }%%
It's only a trivial change to get only the page name ('tag'):
%%(php) function FullCategoryTextSearch($phrase) { return $this->LoadAll("SELECT tag FROM ".$this->config["table_prefix"]."pages WHERE latest = 'Y' AND MATCH(body) AGAINST('".mysql_real_escape_string($phrase)."' IN BOOLEAN MODE)"); }%%
''Looking at ##""FullTextSearch()""##, this is not only used (indirectly) by the category action but also the **textsearch** and **textsearchexpanded** actions. This method also asks for all columns (*) but only the **textsearchexpanded** action actually uses the 'body' field as well as the 'tag' field. This could be made more efficient (for the **textsearch** action at least) by adding an extra parameter to the method to tell it which field(s) to retrieve. However, that would also involve a change in at least one of those actions; that is outside the scope of this page.''
Refer to WikkaOptimization for more optimization issues.


Revision [8992]

Edited on 2005-06-08 11:43:09 by JavaWoman [more comment about getCatMembers()]
Additions:
This not only hides //which// function to call, but also //how// that decision is made. In fact, it's now completely hidden how category members are gathered at all: if we'd install a different system such as a categories table, the //content// of the method would change to query that table, but the category action would not need to be changed at all.
Deletions:
This not only hides //which// function to call, but also //how// that decision is made.


Revision [8991]

Edited on 2005-06-08 11:13:34 by JavaWoman [ypot]
Additions:
The function ##html_entity_decode()## is available in PHP as of version 4.3. The [[AdvancedFormatter "advanced" formatter]] makes use of it when generating ids for headings. The following code provides a //near// equivalent. Insert in ##wikka.php## immediately after the **##mysql_real_escape_string()##** compatibility code shown above:
Deletions:
The function ##html_entity_decode()## is available in PHP as of version 4.3. The [[AdvancedFormatter "advanced" formmater]] makes use of it when generating ids for headings. The following code provides a //near// equivalent. Insert in ##wikka.php## immediately after the **##mysql_real_escape_string()##** compatibility code shown above:


Revision [8942]

Edited on 2005-06-07 22:28:23 by JavaWoman [adding getCatMembers()]
Additions:
===##getCatMembers()##===
Hiding decision logic.
The current (version 1.1.6.0) [[CategoryActionInfo category action]] uses the following bit of code to gather the the members of a category:
**##./actions/category.php##**
%%(php;18) if ($this->CheckMySQLVersion(4,0,1))
$results = $this->FullCategoryTextSearch($page);
else
$results = $this->FullTextSearch($page);
This type of decision logic doesn't belong in an action (or a handler for that matter): if we'd decide to support a different set of versions of PHP and MySQL we'd have to trail through all of our code to find ths kind of decision logic. Instead, there should be a single method call to a method that hides the decision process about what function to use when.
So for the [[AdvancedCategoryAction advanced category action]] this code was spirited away in a new core function **##getCatMembers()##** - insert this right after ##""FullCategoryTextSearch()""## in ##wikka.php## at line 438:
%%(php;1) /**
* Find category members, hiding version-dependent implementation from caller.
*
* @uses CheckMySQLVersion()
* @uses FullCategoryTextSearch()
* @uses FullTextSearch()
*
* @todo - replace FullTextSearch() with a query that returns only tag
* - replace CheckMySQLVersion() with PHP's generiic function
*
* @param string $category required: category to find members of.
* @return array rows with page data (for pages that refer to the category name)
*/
function getCatMembers($category)
if ($this->CheckMySQLVersion(4,0,1))
return $this->FullCategoryTextSearch($category);
else
return $this->FullTextSearch($category); # @@@ could be more efficient by returning only 'tag'
This not only hides //which// function to call, but also //how// that decision is made.


Revision [8933]

Edited on 2005-06-07 20:04:40 by JavaWoman [reference to AdvanceFormatter]
Additions:
~-AdvancedFormatter
>>**Compatibility code** is code that serves to "hide" differences in coding to accommodate different versions, such as different PHP versions or different MySQL versions. By providing compatibility code with a public interface we can maintain a clean and simple API while dealing with version differences automatically.::c::
Deletions:
>>Compatibility code is code that serves to "hide" differences in coding to accommodate different versions, such as different PHP versions or different MySQL versions. By providing compatibility code with a public interface we can maintain a clean and simple API while dealing with version differences automatically.::c::


Revision [8932]

Edited on 2005-06-07 20:02:47 by JavaWoman [minor]
Additions:
Compatibility code can be classified into three kinds, depending on what kind of differences we are hiding; the aim is always to hide the complexity of working around differences from calling code that needs the functionality:
Deletions:
Compatibility code can be classified into three kinds, depending on what kind of differences we are hiding; the aim is always to hide complexity from calling code:


Revision [8931]

Edited on 2005-06-07 19:45:36 by JavaWoman [adding ##html_entity_decode()## and notes about equivalence of code]
Additions:
//Note that ##mysql_escape_string()## is not **exactly** equivalent with ##mysql_real_escape_string()##; possibly the code here could be extended a bit to provide better compaitibilty.//
===##html_entity_decode()##===
The function ##html_entity_decode()## is available in PHP as of version 4.3. The [[AdvancedFormatter "advanced" formmater]] makes use of it when generating ids for headings. The following code provides a //near// equivalent. Insert in ##wikka.php## immediately after the **##mysql_real_escape_string()##** compatibility code shown above:
%%(php;1)if (!function_exists('html_entity_decode'))
// based on http://php.net/html-entity-decode.php
// third parameter (charset) ignored: only (default) ISO-8859-1 character set supported
function html_entity_decode($string,$quote_style=ENT_COMPAT)
$trans_tbl = get_html_translation_table(HTML_ENTITIES,$quote_style);
$trans_tbl = array_flip($trans_tbl);
return strtr($string, $trans_tbl);
Note that it is not completely equivalent: ##html_entity_decode()## in PHP 4.3+ provides support for a range of character sets (including UTF-8); the character set can be specified in a third parameter. The function ##get_html_translation_table()## we use to provide compatibility only uses the default charset ISO-8859-1; when this code is used in versiosn of PHP lower than 4.3 any third parameter will be ignored.
//Note that for the case this was written (generating ids for headings) we actually **need** ISO-8859-1, so for that application lack of equivalence it is not a problem; used in another context it may be and one should be aware of the limitations.//


Revision [8928]

Edited on 2005-06-07 19:17:56 by JavaWoman [note about "missing function" pattern]
Additions:
This clearly shows the basic **pattern** for "missing function" compatibility code:
~-check whether a function of that name exists
~-if not, define a function with the same name and as much as possible the same interface
~-in the function body imitate as much as possible the functionality of the missing function
This ensures that the intended function can be called as normal: if the function does **not** exist in the current installation, the compatibility code will kick in.


Revision [8927]

The oldest known version of this page was created on 2005-06-07 19:01:21 by JavaWoman [note about "missing function" pattern]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki