http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89769
Revision: 89769
Author: mkroetzsch
Date: 2011-06-09 11:54:36 +0000 (Thu, 09 Jun 2011)
Log Message:
-----------
ensure that very long DEFAULTSORTKEYs do not cause errors
Modified Paths:
--------------
trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php
trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_String.php
Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php
2011-06-09 10:59:23 UTC (rev 89768)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php
2011-06-09 11:54:36 UTC (rev 89769)
@@ -351,7 +351,12 @@
$sortkey = $parser->mDefaultSort ? $parser->mDefaultSort :
str_replace( '_', ' ', self::getSMWData( $parser
)->getSubject()->getDBkey() );
$pskey = new SMWDIProperty( '_SKEY' );
- $sortkeyDi = new SMWDIString( $sortkey );
+ try {
+ $sortkeyDi = new SMWDIString( $sortkey );
+ } catch (SMWStringLengthException $e) { // cut it down to a
reasonable length; no further bytes should be needed for sorting
+ $sortkey = substr( $sortkey, 0, $e->getMaxLength() );
+ $sortkeyDi = new SMWDIString( $sortkey );
+ }
self::getSMWData( $parser )->addPropertyObjectValue( $pskey,
$sortkeyDi );
return true;
Modified:
trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_String.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_String.php
2011-06-09 10:59:23 UTC (rev 89768)
+++ trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_String.php
2011-06-09 11:54:36 UTC (rev 89769)
@@ -10,9 +10,20 @@
* @since 1.6
*/
class SMWStringLengthException extends SMWDataItemException {
- public function __construct( $string ) {
+ protected $m_maxlength;
+
+ public function __construct( $string, $maxlength ) {
parent::__construct( 'String "' . mb_substr( $string, 0, 10 ) .
'...' . mb_substr( $string, mb_strlen( $string ) - 10 ) . ' exceeds length
limit for strings. Use SMWDIBlob for long strings.' );
+ $this->m_maxlength = $maxlength;
}
+
+ /**
+ * Get the maximum length that the string is allowed to have. The length
+ * is counted with str_len, i.e. multibyte (UTF-8) strings are ignored.
+ */
+ public function getMaxLength() {
+ return $this->m_maxlength;
+ }
}
/**
@@ -27,9 +38,17 @@
const MAXLENGTH = 255;
+ /**
+ * Constructor.
+ *
+ * @throws SMWStringLengthException if the string is longer than
+ * SMWDIString::MAXLENGTH. The bytes are counted, not the (possibly
+ * multibyte) glyphs of UTF-8, since we care about byte length in (any)
+ * storage backend.
+ */
public function __construct( $string ) {
if ( strlen( $string ) > SMWDIString::MAXLENGTH ) {
- throw new SMWStringLengthException( $string );
+ throw new SMWStringLengthException( $string,
SMWDIString::MAXLENGTH );
}
parent::__construct( $string );
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs