Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php |
— | — | @@ -351,7 +351,12 @@ |
352 | 352 | $sortkey = $parser->mDefaultSort ? $parser->mDefaultSort : |
353 | 353 | str_replace( '_', ' ', self::getSMWData( $parser )->getSubject()->getDBkey() ); |
354 | 354 | $pskey = new SMWDIProperty( '_SKEY' ); |
355 | | - $sortkeyDi = new SMWDIString( $sortkey ); |
| 355 | + try { |
| 356 | + $sortkeyDi = new SMWDIString( $sortkey ); |
| 357 | + } catch (SMWStringLengthException $e) { // cut it down to a reasonable length; no further bytes should be needed for sorting |
| 358 | + $sortkey = substr( $sortkey, 0, $e->getMaxLength() ); |
| 359 | + $sortkeyDi = new SMWDIString( $sortkey ); |
| 360 | + } |
356 | 361 | self::getSMWData( $parser )->addPropertyObjectValue( $pskey, $sortkeyDi ); |
357 | 362 | |
358 | 363 | return true; |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_String.php |
— | — | @@ -10,9 +10,20 @@ |
11 | 11 | * @since 1.6 |
12 | 12 | */ |
13 | 13 | class SMWStringLengthException extends SMWDataItemException { |
14 | | - public function __construct( $string ) { |
| 14 | + protected $m_maxlength; |
| 15 | + |
| 16 | + public function __construct( $string, $maxlength ) { |
15 | 17 | 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.' ); |
| 18 | + $this->m_maxlength = $maxlength; |
16 | 19 | } |
| 20 | + |
| 21 | + /** |
| 22 | + * Get the maximum length that the string is allowed to have. The length |
| 23 | + * is counted with str_len, i.e. multibyte (UTF-8) strings are ignored. |
| 24 | + */ |
| 25 | + public function getMaxLength() { |
| 26 | + return $this->m_maxlength; |
| 27 | + } |
17 | 28 | } |
18 | 29 | |
19 | 30 | /** |
— | — | @@ -27,9 +38,17 @@ |
28 | 39 | |
29 | 40 | const MAXLENGTH = 255; |
30 | 41 | |
| 42 | + /** |
| 43 | + * Constructor. |
| 44 | + * |
| 45 | + * @throws SMWStringLengthException if the string is longer than |
| 46 | + * SMWDIString::MAXLENGTH. The bytes are counted, not the (possibly |
| 47 | + * multibyte) glyphs of UTF-8, since we care about byte length in (any) |
| 48 | + * storage backend. |
| 49 | + */ |
31 | 50 | public function __construct( $string ) { |
32 | 51 | if ( strlen( $string ) > SMWDIString::MAXLENGTH ) { |
33 | | - throw new SMWStringLengthException( $string ); |
| 52 | + throw new SMWStringLengthException( $string, SMWDIString::MAXLENGTH ); |
34 | 53 | } |
35 | 54 | parent::__construct( $string ); |
36 | 55 | } |