Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php |
— | — | @@ -113,20 +113,19 @@ |
114 | 114 | $query->sort = true; |
115 | 115 | $query->sortkeys = array(); |
116 | 116 | |
117 | | - foreach ( explode( ',', trim( $params['sort'] ) ) as $sort ) { |
118 | | - $sort = smwfNormalTitleDBKey( trim( $sort ) ); // slight normalisation |
119 | | - $order = current( $orders ); |
120 | | - if ( $order === false ) { // default |
121 | | - $order = 'ASC'; |
122 | | - } |
123 | | - |
124 | | - if ( array_key_exists( $sort, $query->sortkeys ) ) { |
125 | | - // maybe throw an error here? |
| 117 | + foreach ( explode( ',', $params['sort'] ) as $sort ) { |
| 118 | + $propertyValue = SMWPropertyValue::makeUserProperty( trim( $sort ) ); |
| 119 | + if ( $propertyValue->isValid() ) { |
| 120 | + $sortkey = $propertyValue->getDataItem()->getKey(); |
| 121 | + $order = current( $orders ); |
| 122 | + if ( $order === false ) { // default |
| 123 | + $order = 'ASC'; |
| 124 | + } |
| 125 | + $query->sortkeys[$sortkey] = $order; // should we check for duplicate sort keys? |
| 126 | + next( $orders ); |
126 | 127 | } else { |
127 | | - $query->sortkeys[$sort] = $order; |
| 128 | + $query->addErrors( $propertyValue->getErrors() ); |
128 | 129 | } |
129 | | - |
130 | | - next( $orders ); |
131 | 130 | } |
132 | 131 | |
133 | 132 | if ( current( $orders ) !== false ) { // sort key remaining, apply to page name |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php |
— | — | @@ -115,18 +115,19 @@ |
116 | 116 | if ( $this->m_caption === false ) { // always use this as caption |
117 | 117 | $this->m_caption = $value; |
118 | 118 | } |
119 | | - $value = smwfNormalTitleText( ltrim( rtrim( $value, ' ]' ), ' [' ) ); // slightly normalise label |
| 119 | + $propertyName = smwfNormalTitleText( ltrim( rtrim( $value, ' ]' ), ' [' ) ); // slightly normalise label |
120 | 120 | $inverse = false; |
121 | | - if ( ( $value !== '' ) && ( $value { 0 } == '-' ) ) { // check if this property refers to an inverse |
122 | | - $value = substr( $value, 1 ); |
| 121 | + if ( ( $propertyName !== '' ) && ( $propertyName{ 0 } == '-' ) ) { // property refers to an inverse |
| 122 | + $propertyName = (string)substr( $value, 1 ); |
| 123 | + /// NOTE The cast is necessary at least in PHP 5.3.3 to get string '' instead of boolean false. |
123 | 124 | $inverse = true; |
124 | 125 | } |
125 | 126 | |
126 | 127 | try { |
127 | | - $this->m_dataitem = SMWDIProperty::newFromUserLabel( $value, $inverse, $this->m_typeid ); |
128 | | - } catch ( SMWDataItemException $e ) { |
| 128 | + $this->m_dataitem = SMWDIProperty::newFromUserLabel( $propertyName, $inverse, $this->m_typeid ); |
| 129 | + } catch ( SMWDataItemException $e ) { // happens, e.g., when trying to sort queries by property "-" |
129 | 130 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
130 | | - $this->addError( wfMsgForContent( 'smw_parseerror' ) ); // very rare to get an error here, don't bother with detailed reporting |
| 131 | + $this->addError( wfMsgForContent( 'smw_noproperty', $value ) ); |
131 | 132 | $this->m_dataitem = new SMWDIProperty( 'ERROR', false, $this->m_typeid ); // just to have something |
132 | 133 | } |
133 | 134 | } |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php |
— | — | @@ -101,6 +101,7 @@ |
102 | 102 | 'smw_decseparator' => '.', |
103 | 103 | 'smw_kiloseparator' => ',', |
104 | 104 | 'smw_notitle' => '"$1" cannot be used as a page name in this wiki.', |
| 105 | + 'smw_noproperty' => '"$1" cannot be used as a property name in this wiki.', |
105 | 106 | 'smw_wrong_namespace' => 'Only pages in namespace "$1" are allowed here.', |
106 | 107 | 'smw_unknowntype' => 'Unsupported type "$1" defined for property.', |
107 | 108 | 'smw_manytypes' => 'More than one type defined for property.', |