Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php |
— | — | @@ -307,9 +307,9 @@ |
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
311 | | - * Hook function fetches category information and other final settings from parser output, |
312 | | - * so that they are also replicated in SMW for more efficient querying. |
313 | | - * @bug Sortkey currently not stored. Needs to be done differently now. |
| 311 | + * Hook function fetches category information and other final settings |
| 312 | + * from parser output, so that they are also replicated in SMW for more |
| 313 | + * efficient querying. |
314 | 314 | */ |
315 | 315 | static public function onParserAfterTidy( &$parser, &$text ) { |
316 | 316 | global $smwgUseCategoryHierarchy, $smwgCategoriesAsInstances; |
— | — | @@ -333,9 +333,11 @@ |
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
337 | | -// $sortkey = ( $parser->mDefaultSort ? $parser->mDefaultSort : |
338 | | -// str_replace( '_', ' ', self::getSMWData( $parser )->getSubject()->getDBkey() ) ); |
339 | | -// self::getSMWData( $parser )->getSubject()->setSortkey( $sortkey ); |
| 337 | + $sortkey = $parser->mDefaultSort ? $parser->mDefaultSort : |
| 338 | + str_replace( '_', ' ', self::getSMWData( $parser )->getSubject()->getDBkey() ); |
| 339 | + $pskey = new SMWDIProperty( '_SKEY' ); |
| 340 | + $sortkeyDi = new SMWDIString( $sortkey ); |
| 341 | + self::getSMWData( $parser )->addPropertyObjectValue( $pskey, $sortkeyDi ); |
340 | 342 | |
341 | 343 | return true; |
342 | 344 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_WikiPage.php |
— | — | @@ -11,15 +11,6 @@ |
12 | 12 | * The class can support general wiki pages, or pages of a fixed |
13 | 13 | * namespace, Whether a namespace is fixed is decided based on the |
14 | 14 | * type ID when the object is constructed. |
15 | | - * |
16 | | - * In contrast to most other types |
17 | | - * of values, wiki pages are determined by multiple components, as |
18 | | - * retruned by their getDBkeys() method: DBkey, namespace, interwiki |
19 | | - * prefix and sortkey. The last of those has a somewhat nonstandard |
20 | | - * behaviour, since it is not attached to every wiki page value, but |
21 | | - * only to those that represent page subjects, which define the sortkey |
22 | | - * globally for all places where this page value occurs. |
23 | | - * @todo The treatment of sortkeys will be changed (30-03-2010) |
24 | 15 | * |
25 | 16 | * @author Nikolas Iwan |
26 | 17 | * @author Markus Krötzsch |
— | — | @@ -28,21 +19,13 @@ |
29 | 20 | class SMWWikiPageValue extends SMWDataValue { |
30 | 21 | |
31 | 22 | /** |
32 | | - * Cache for the sortkey that is used with this page, or |
33 | | - * empty string if unset. |
34 | | - * @note The management of sortkeys of SMW is likely to change. |
35 | | - * @var string |
36 | | - */ |
37 | | - protected $m_sortkey; |
38 | | - |
39 | | - /** |
40 | 23 | * The isolated title as text. Always set when this object is valid. |
41 | 24 | * @var string |
42 | 25 | */ |
43 | 26 | protected $m_textform; |
44 | 27 | |
45 | 28 | /** |
46 | | - * Fragement text for user-specified title. Not stored, but kept for |
| 29 | + * Fragment text for user-specified title. Not stored, but kept for |
47 | 30 | * printout on page. |
48 | 31 | * @var string |
49 | 32 | */ |
— | — | @@ -78,38 +61,6 @@ |
79 | 62 | */ |
80 | 63 | protected $m_fixNamespace = NS_MAIN; |
81 | 64 | |
82 | | - /** |
83 | | - * Static function for creating a new wikipage object from |
84 | | - * data as it is typically stored internally. In particular, |
85 | | - * the title string is supposed to be in DB key form. |
86 | | - * @note The resulting wikipage object might be invalid if |
87 | | - * the provided title is not allowed. An object is returned |
88 | | - * in any case. |
89 | | - * |
90 | | - * @return SMWWikiPageValue |
91 | | - */ |
92 | | - static public function makePage( $dbkey, $namespace, $sortkey = '', $interwiki = '' ) { |
93 | | - $diWikiPage = new SMWDIWikiPage( $dbkey, $namespace, $interwiki ); |
94 | | - $dvWikiPage = new SMWWikiPageValue( '_wpg' ); |
95 | | - $dvWikiPage->setDataItem( $diWikiPage ); |
96 | | - return $dvWikiPage; |
97 | | - } |
98 | | - |
99 | | - /** |
100 | | - * Static function for creating a new wikipage object from a |
101 | | - * MediaWiki Title object. |
102 | | - * @todo Evaluate whether we really want this function. It might be obsolete due to recent changes. |
103 | | - * |
104 | | - * @return SMWWikiPageValue |
105 | | - */ |
106 | | - static public function makePageFromTitle( Title $title ) { |
107 | | - $dvWikiPage = new SMWWikiPageValue( '_wpg' ); |
108 | | - $diWikiPage = new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ); |
109 | | - $dvWikiPage->setDataItem( $diWikiPage ); |
110 | | - $dvWikiPage->m_title = $title; |
111 | | - return $dvWikiPage; |
112 | | - } |
113 | | - |
114 | 65 | public function __construct( $typeid ) { |
115 | 66 | parent::__construct( $typeid ); |
116 | 67 | switch ( $typeid ) { |
— | — | @@ -137,7 +88,6 @@ |
138 | 89 | $this->m_caption = $value; |
139 | 90 | } |
140 | 91 | $this->m_dataitem = null; |
141 | | - $this->m_sortkey = ''; |
142 | 92 | if ( $value != '' ) { |
143 | 93 | $this->m_title = Title::newFromText( $value, $this->m_fixNamespace ); |
144 | 94 | ///TODO: Escape the text so users can see any punctuation problems (bug 11666). |
— | — | @@ -186,7 +136,7 @@ |
187 | 137 | $this->m_textform = str_replace( '_', ' ', $dataItem->getDBkey() ); |
188 | 138 | $this->m_id = -1; |
189 | 139 | $this->m_title = null; |
190 | | - $this->m_sortkey = $this->m_fragment = $this->m_prefixedtext = ''; |
| 140 | + $this->m_fragment = $this->m_prefixedtext = ''; |
191 | 141 | $this->m_caption = false; |
192 | 142 | if ( ( $this->m_fixNamespace != NS_MAIN ) && ( $this->m_fixNamespace != $dataItem->getNamespace() ) ) { |
193 | 143 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
— | — | @@ -256,7 +206,7 @@ |
257 | 207 | |
258 | 208 | public function getDBkeys() { |
259 | 209 | $this->unstub(); |
260 | | - return array( $this->m_dataitem->getDBkey(), $this->m_dataitem->getNamespace(), $this->m_dataitem->getInterwiki(), $this->getSortkey() ); |
| 210 | + return array( $this->m_dataitem->getDBkey(), $this->m_dataitem->getNamespace(), $this->m_dataitem->getInterwiki(), $this->m_dataitem->getDBkey() ); |
261 | 211 | } |
262 | 212 | |
263 | 213 | public function getSignature() { |
— | — | @@ -399,20 +349,23 @@ |
400 | 350 | } |
401 | 351 | |
402 | 352 | /** |
403 | | - * Get sortkey or make one as default. |
404 | | - * @bug Sortkeys will need to be treated differently, namely as properties of a page, not as part of their identity. This method then needs to find the real sortkey instead of making a default. |
| 353 | + * Get the (default) caption for this value. |
| 354 | + * If a fixed namespace is set, we do not return the namespace prefix explicitly. |
405 | 355 | */ |
406 | | - public function getSortkey() { |
407 | | - $this->unstub(); |
408 | | - return $this->m_sortkey ? $this->m_sortkey : ( str_replace( '_', ' ', $this->m_dataitem->getDBkey() ) ); |
| 356 | + protected function getCaption() { |
| 357 | + return $this->m_caption !== false ? $this->m_caption: |
| 358 | + ( $this->m_fixNamespace == NS_MAIN ? $this->getPrefixedText():$this->getText() ); |
409 | 359 | } |
410 | 360 | |
411 | 361 | /** |
412 | | - * Set sortkey |
| 362 | + * Find the sortkey for this object. |
| 363 | + * |
| 364 | + * @deprecated Use SMWStore::getWikiPageSortKey(). |
| 365 | + * |
| 366 | + * @return string sortkey |
413 | 367 | */ |
414 | | - public function setSortkey( $sortkey ) { |
415 | | - $this->unstub(); // unstub first, since the stubarray also may hold a sortkey |
416 | | - $this->m_sortkey = $sortkey; |
| 368 | + public function getSortKey() { |
| 369 | + return smwfGetStore()->getWikiPageSortKey( $this->m_dataitem ); |
417 | 370 | } |
418 | 371 | |
419 | 372 | /** |
— | — | @@ -426,20 +379,47 @@ |
427 | 380 | } |
428 | 381 | |
429 | 382 | /** |
430 | | - * Get the (default) caption for this value. |
431 | | - * If a fixed namespace is set, we do not return the namespace prefix explicitly. |
| 383 | + * @deprecated Use setDBkeys() |
432 | 384 | */ |
433 | | - protected function getCaption() { |
434 | | - return $this->m_caption !== false ? $this->m_caption: |
435 | | - ( $this->m_fixNamespace == NS_MAIN ? $this->getPrefixedText():$this->getText() ); |
| 385 | + public function setValues( $dbkey, $namespace, $id = false, $interwiki = '' ) { |
| 386 | + $this->setDBkeys( array( $dbkey, $namespace, $interwiki, $dbkey ) ); |
436 | 387 | } |
437 | 388 | |
438 | 389 | /** |
439 | | - * @deprecated Use setDBkeys() |
| 390 | + * Static function for creating a new wikipage object from |
| 391 | + * data as it is typically stored internally. In particular, |
| 392 | + * the title string is supposed to be in DB key form. |
| 393 | + * |
| 394 | + * @note The resulting wikipage object might be invalid if |
| 395 | + * the provided title is not allowed. An object is returned |
| 396 | + * in any case. |
| 397 | + * |
| 398 | + * @deprecated This method will vanish before SMW 1.7. If you really need this, simply copy its code. |
| 399 | + * |
| 400 | + * @return SMWWikiPageValue |
440 | 401 | */ |
441 | | - public function setValues( $dbkey, $namespace, $id = false, $interwiki = '', $sortkey = '' ) { |
442 | | - $this->setDBkeys( array( $dbkey, $namespace, $interwiki, $sortkey ) ); |
| 402 | + static public function makePage( $dbkey, $namespace, $ignoredParameter = '', $interwiki = '' ) { |
| 403 | + $diWikiPage = new SMWDIWikiPage( $dbkey, $namespace, $interwiki ); |
| 404 | + $dvWikiPage = new SMWWikiPageValue( '_wpg' ); |
| 405 | + $dvWikiPage->setDataItem( $diWikiPage ); |
| 406 | + return $dvWikiPage; |
443 | 407 | } |
444 | 408 | |
| 409 | + /** |
| 410 | + * Static function for creating a new wikipage object from a |
| 411 | + * MediaWiki Title object. |
| 412 | + * |
| 413 | + * @deprecated This method will vanish before SMW 1.7. If you really need this, simply copy its code. |
| 414 | + * |
| 415 | + * @return SMWWikiPageValue |
| 416 | + */ |
| 417 | + static public function makePageFromTitle( Title $title ) { |
| 418 | + $dvWikiPage = new SMWWikiPageValue( '_wpg' ); |
| 419 | + $diWikiPage = new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ); |
| 420 | + $dvWikiPage->setDataItem( $diWikiPage ); |
| 421 | + $dvWikiPage->m_title = $title; |
| 422 | + return $dvWikiPage; |
| 423 | + } |
| 424 | + |
445 | 425 | } |
446 | 426 | |
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Category.php |
— | — | @@ -67,7 +67,7 @@ |
68 | 68 | $nextrow = $res->getNext(); // look ahead |
69 | 69 | |
70 | 70 | $content = $row[0]->getContent(); |
71 | | - $sortkey = $content[0]->getSortkey(); |
| 71 | + $sortkey = $res->getStore()->getWikiPageSortKey( $content[0] ); |
72 | 72 | $cur_first_char = $wgContLang->firstChar( $sortkey ); |
73 | 73 | if ( $rowindex % $rows_per_column == 0 ) { |
74 | 74 | $result .= "\n <div style=\"float: left; width: $column_width%;\">\n"; |
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_OrderedListPage.php |
— | — | @@ -39,11 +39,12 @@ |
40 | 40 | protected $until; |
41 | 41 | |
42 | 42 | /** |
43 | | - * Array of articles for which information is printed (primary ordering method). |
| 43 | + * Array of SMWDIWikiPage objects for which information is printed |
| 44 | + * (primary ordering method). |
44 | 45 | * |
45 | | - * @var array |
| 46 | + * @var array of SMWDIWikiPage |
46 | 47 | */ |
47 | | - protected $articles; |
| 48 | + protected $diWikiPages; |
48 | 49 | |
49 | 50 | /** |
50 | 51 | * Cache for the current skin, obtained from $wgUser. |
— | — | @@ -119,11 +120,11 @@ |
120 | 121 | * Initialise internal data structures. |
121 | 122 | */ |
122 | 123 | protected function clearPageState() { |
123 | | - $this->articles = array(); |
| 124 | + $this->diWikiPages = array(); |
124 | 125 | } |
125 | 126 | |
126 | 127 | /** |
127 | | - * Execute the DB query and fill the articles array. |
| 128 | + * Execute the DB query and fill the diWikiPages array. |
128 | 129 | * Implemented by subclasses. |
129 | 130 | */ |
130 | 131 | protected abstract function doQuery(); |
— | — | @@ -143,21 +144,21 @@ |
144 | 145 | $sk = $this->getSkin(); |
145 | 146 | $limitText = $wgLang->formatNum( $this->limit ); |
146 | 147 | |
147 | | - $ac = count( $this->articles ); |
| 148 | + $ac = count( $this->diWikiPages ); |
148 | 149 | |
149 | 150 | if ( $this->until != '' ) { |
150 | 151 | if ( $ac > $this->limit ) { // (we assume that limit is at least 1) |
151 | | - $first = $this->articles[1]->getSortkey(); |
| 152 | + $first = smwfGetStore()->getWikiPageSortKey( $this->diWikiPages[1] ); |
152 | 153 | } else { |
153 | 154 | $first = ''; |
154 | 155 | } |
155 | | - |
| 156 | + |
156 | 157 | $last = $this->until; |
157 | 158 | } elseif ( ( $ac > $this->limit ) || ( $this->from != '' ) ) { |
158 | 159 | $first = $this->from; |
159 | 160 | |
160 | 161 | if ( $ac > $this->limit ) { |
161 | | - $last = SMWCompatibilityHelpers::getSortKey( $this->articles[$ac - 1] ); |
| 162 | + $last = smwfGetStore()->getWikiPageSortKey( $this->diWikiPages[$ac - 1] ); |
162 | 163 | } else { |
163 | 164 | $last = ''; |
164 | 165 | } |
— | — | @@ -212,11 +213,11 @@ |
213 | 214 | * |
214 | 215 | * @param $start integer |
215 | 216 | * @param $end integer |
216 | | - * @param $elements of SMWDIWikiPage |
| 217 | + * @param $diWikiPages of SMWDIWikiPage |
217 | 218 | * |
218 | 219 | * @return string |
219 | 220 | */ |
220 | | - protected function columnList( $start, $end, $elements ) { |
| 221 | + protected function columnList( $start, $end, $diWikiPages ) { |
221 | 222 | global $wgContLang; |
222 | 223 | |
223 | 224 | // Divide list into three equal chunks. |
— | — | @@ -234,11 +235,12 @@ |
235 | 236 | $r .= "<td>\n"; |
236 | 237 | $atColumnTop = true; |
237 | 238 | |
238 | | - // output all articles |
| 239 | + // output all diWikiPages |
239 | 240 | for ( $index = $startChunk ; $index < $endChunk && $index < $end; $index++ ) { |
240 | | - $elementDv = SMWDataValueFactory::newDataItemValue( $elements[$index] ); |
| 241 | + $dataValue = SMWDataValueFactory::newDataItemValue( $diWikiPages[$index] ); |
241 | 242 | // check for change of starting letter or begining of chunk |
242 | | - $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$index]->getSortkey() ) ); |
| 243 | + $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPages[$index] ); |
| 244 | + $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
243 | 245 | |
244 | 246 | if ( ( $index == $startChunk ) || |
245 | 247 | ( $start_char != $prev_start_char ) ) { |
— | — | @@ -258,7 +260,7 @@ |
259 | 261 | $prev_start_char = $start_char; |
260 | 262 | } |
261 | 263 | |
262 | | - $r .= "<li>" . $elementDv->getLongHTMLText( $this->getSkin() ) . "</li>\n"; |
| 264 | + $r .= "<li>" . $dataValue->getLongHTMLText( $this->getSkin() ) . "</li>\n"; |
263 | 265 | } |
264 | 266 | |
265 | 267 | if ( !$atColumnTop ) { |
— | — | @@ -274,37 +276,39 @@ |
275 | 277 | } |
276 | 278 | |
277 | 279 | /** |
278 | | - * Format a list of articles chunked by letter in a bullet list. |
| 280 | + * Format a list of diWikiPages chunked by letter in a bullet list. |
279 | 281 | * |
280 | | - * @param integer $start |
281 | | - * @param integer $end |
282 | | - * @param array $elements |
| 282 | + * @param $start integer |
| 283 | + * @param $end integer |
| 284 | + * @param $diWikiPages array of SMWDataItem |
283 | 285 | * |
284 | 286 | * @return string |
285 | 287 | */ |
286 | | - protected function shortList( $start, $end, array $elements ) { |
| 288 | + protected function shortList( $start, $end, array $diWikiPages ) { |
287 | 289 | global $wgContLang; |
288 | | - |
289 | | - $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$start]->getSortkey() ) ); |
| 290 | + |
| 291 | + $startDv = SMWDataValueFactory::newDataItemValue( $diWikiPages[$start] ); |
| 292 | + $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPages[$start] ); |
| 293 | + $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
| 294 | + $r = '<h3>' . htmlspecialchars( $start_char ) . "</h3>\n" . |
| 295 | + '<ul><li>' . $startDv->getLongHTMLText( $this->getSkin() ) . '</li>'; |
| 296 | + |
290 | 297 | $prev_start_char = $start_char; |
291 | | - $r = '<h3>' . htmlspecialchars( $start_char ) . "</h3>\n"; |
292 | | - $elementStartDv = SMWDataValueFactory::newDataItemValue( $elements[$start] ); |
293 | | - $r .= '<ul><li>' . $elementStartDv->getLongHTMLText( $this->getSkin() ) . '</li>'; |
294 | | - |
295 | 298 | for ( $index = $start + 1; $index < $end; $index++ ) { |
296 | | - $elementDv = SMWDataValueFactory::newDataItemValue( $elements[$index] ); |
297 | | - $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$index]->getSortkey() ) ); |
298 | | - |
| 299 | + $dataValue = SMWDataValueFactory::newDataItemValue( $diWikiPages[$index] ); |
| 300 | + $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPages[$index] ); |
| 301 | + $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
| 302 | + |
299 | 303 | if ( $start_char != $prev_start_char ) { |
300 | 304 | $r .= "</ul><h3>" . htmlspecialchars( $start_char ) . "</h3>\n<ul>"; |
301 | 305 | $prev_start_char = $start_char; |
302 | 306 | } |
303 | | - |
304 | | - $r .= '<li>' . $elementDv->getLongHTMLText( $this->getSkin() ) . '</li>'; |
| 307 | + |
| 308 | + $r .= '<li>' . $dataValue->getLongHTMLText( $this->getSkin() ) . '</li>'; |
305 | 309 | } |
306 | | - |
| 310 | + |
307 | 311 | $r .= '</ul>'; |
308 | | - |
| 312 | + |
309 | 313 | return $r; |
310 | 314 | } |
311 | 315 | |
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_TypePage.php |
— | — | @@ -27,8 +27,8 @@ |
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | | - * Fill the internal arrays with the set of articles to be displayed (possibly plus one additional |
32 | | - * article that indicates further results). |
| 31 | + * Fill the internal arrays with the set of data items to be displayed |
| 32 | + * (possibly plus one additional item to indicate further results). |
33 | 33 | */ |
34 | 34 | protected function doQuery() { |
35 | 35 | if ( $this->limit > 0 ) { |
— | — | @@ -42,17 +42,17 @@ |
43 | 43 | $options->boundary = $this->from; |
44 | 44 | $options->ascending = true; |
45 | 45 | $options->include_boundary = true; |
46 | | - $this->articles = $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options ); |
| 46 | + $this->diWikiPages = $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options ); |
47 | 47 | } elseif ( $this->until != '' ) { |
48 | 48 | $options->boundary = $this->until; |
49 | 49 | $options->ascending = false; |
50 | 50 | $options->include_boundary = false; |
51 | | - $this->articles = array_reverse( $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options ) ); |
| 51 | + $this->diWikiPages = array_reverse( $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options ) ); |
52 | 52 | } else { |
53 | | - $this->articles = $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options ); |
| 53 | + $this->diWikiPages = $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options ); |
54 | 54 | } |
55 | 55 | } else { |
56 | | - $this->articles = array(); |
| 56 | + $this->diWikiPages = array(); |
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
— | — | @@ -78,7 +78,7 @@ |
79 | 79 | $r .= '<a name="SMWResults"></a>' . $nav . "<div id=\"mw-pages\">\n"; |
80 | 80 | |
81 | 81 | $r .= '<h2>' . wfMsg( 'smw_type_header', $ti ) . "</h2>\n"; |
82 | | - $r .= wfMsgExt( 'smw_typearticlecount', array( 'parsemag' ), min( $this->limit, count( $this->articles ) ) ) . "\n"; |
| 82 | + $r .= wfMsgExt( 'smw_typearticlecount', array( 'parsemag' ), min( $this->limit, count( $this->diWikiPages ) ) ) . "\n"; |
83 | 83 | |
84 | 84 | $r .= $this->formatList(); |
85 | 85 | $r .= "\n</div>" . $nav; |
— | — | @@ -87,14 +87,14 @@ |
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | | - * Format a list of articles chunked by letter, either as a |
| 91 | + * Format a list of data items chunked by letter, either as a |
92 | 92 | * bullet list or a columnar format, depending on the length. |
93 | 93 | * |
94 | | - * @param int $cutoff |
| 94 | + * @param $cutoff integer, use columns for more results than that |
95 | 95 | * @return string |
96 | 96 | */ |
97 | 97 | private function formatList( $cutoff = 6 ) { |
98 | | - $end = count( $this->articles ); |
| 98 | + $end = count( $this->diWikiPages ); |
99 | 99 | if ( $end > $this->limit ) { |
100 | 100 | if ( $this->until != '' ) { |
101 | 101 | $start = 1; |
— | — | @@ -106,11 +106,11 @@ |
107 | 107 | $start = 0; |
108 | 108 | } |
109 | 109 | |
110 | | - if ( count ( $this->articles ) > $cutoff ) { |
111 | | - return $this->columnList( $start, $end, $this->articles ); |
112 | | - } elseif ( count( $this->articles ) > 0 ) { |
113 | | - // for short lists of articles |
114 | | - return $this->shortList( $start, $end, $this->articles ); |
| 110 | + if ( count ( $this->diWikiPages ) > $cutoff ) { |
| 111 | + return $this->columnList( $start, $end, $this->diWikiPages ); |
| 112 | + } elseif ( count( $this->diWikiPages ) > 0 ) { |
| 113 | + // for short lists of diWikiPages |
| 114 | + return $this->shortList( $start, $end, $this->diWikiPages ); |
115 | 115 | } |
116 | 116 | return ''; |
117 | 117 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php |
— | — | @@ -34,8 +34,8 @@ |
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
38 | | - * Fill the internal arrays with the set of articles to be displayed (possibly plus one additional |
39 | | - * article that indicates further results). |
| 38 | + * Fill the internal arrays with the set of data items to be displayed |
| 39 | + * (possibly plus one additional item that indicates further results). |
40 | 40 | */ |
41 | 41 | protected function doQuery() { |
42 | 42 | $store = smwfGetStore(); |
— | — | @@ -57,13 +57,13 @@ |
58 | 58 | $reverse = true; |
59 | 59 | } |
60 | 60 | |
61 | | - $this->articles = $store->getAllPropertySubjects( $this->mProperty, $options ); |
| 61 | + $this->diWikiPages = $store->getAllPropertySubjects( $this->mProperty, $options ); |
62 | 62 | |
63 | 63 | if ( $reverse ) { |
64 | | - $this->articles = array_reverse( $this->articles ); |
| 64 | + $this->diWikiPages = array_reverse( $this->diWikiPages ); |
65 | 65 | } |
66 | 66 | } else { |
67 | | - $this->articles = array(); |
| 67 | + $this->diWikiPages = array(); |
68 | 68 | } |
69 | 69 | |
70 | 70 | // retrieve all subproperties of this property |
— | — | @@ -98,7 +98,7 @@ |
99 | 99 | $r .= "\n</div>"; |
100 | 100 | } |
101 | 101 | |
102 | | - if ( count( $this->articles ) > 0 ) { |
| 102 | + if ( count( $this->diWikiPages ) > 0 ) { |
103 | 103 | $nav = $this->getNavigationLinks(); |
104 | 104 | |
105 | 105 | $r .= '<a name="SMWResults"></a>' . $nav . "<div id=\"mw-pages\">\n" . |
— | — | @@ -108,7 +108,7 @@ |
109 | 109 | $r .= wfMsg( 'smw_isspecprop' ) . ' '; |
110 | 110 | } |
111 | 111 | |
112 | | - $r .= wfMsgExt( 'smw_attributearticlecount', array( 'parsemag' ), min( $this->limit, count( $this->articles ) ) ) . "</p>\n" . |
| 112 | + $r .= wfMsgExt( 'smw_attributearticlecount', array( 'parsemag' ), min( $this->limit, count( $this->diWikiPages ) ) ) . "</p>\n" . |
113 | 113 | $this->subjectObjectList() . "\n</div>" . $nav; |
114 | 114 | } |
115 | 115 | |
— | — | @@ -118,14 +118,14 @@ |
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
122 | | - * Format a list of articles chunked by letter in a table that shows subject articles in |
123 | | - * one column and object articles/values in the other one. |
| 122 | + * Format $diWikiPages chunked by letter in a table that shows subject |
| 123 | + * articles in one column and object articles/values in the other one. |
124 | 124 | */ |
125 | 125 | private function subjectObjectList() { |
126 | 126 | global $wgContLang, $smwgMaxPropertyValues; |
127 | 127 | $store = smwfGetStore(); |
128 | 128 | |
129 | | - $ac = count( $this->articles ); |
| 129 | + $ac = count( $this->diWikiPages ); |
130 | 130 | |
131 | 131 | if ( $ac > $this->limit ) { |
132 | 132 | if ( $this->until != '' ) { |
— | — | @@ -142,9 +142,10 @@ |
143 | 143 | $prev_start_char = 'None'; |
144 | 144 | |
145 | 145 | for ( $index = $start; $index < $ac; $index++ ) { |
146 | | - $diWikiPage = $this->articles[$index]; |
| 146 | + $diWikiPage = $this->diWikiPages[$index]; |
147 | 147 | $dvWikiPage = SMWDataValueFactory::newDataItemValue( $diWikiPage ); |
148 | | - $start_char = $wgContLang->convert( $wgContLang->firstChar( SMWCompatibilityHelpers::getSortKey( $diWikiPage ) ) ); |
| 148 | + $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPage ); |
| 149 | + $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
149 | 150 | |
150 | 151 | // Header for index letters |
151 | 152 | if ( $start_char != $prev_start_char ) { |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php |
— | — | @@ -488,15 +488,15 @@ |
489 | 489 | $this->m_queries[$cqid] = $cquery; |
490 | 490 | } |
491 | 491 | } elseif ( $description instanceof SMWValueDescription ) { // Only type '_wpg' objects can appear on query level (essentially as nominal classes). |
492 | | - if ( $description->getDatavalue()->getTypeID() == '_wpg' ) { |
| 492 | + if ( $description->getDataItem()->getTypeID() == '_wpg' ) { |
493 | 493 | if ( $description->getComparator() == SMW_CMP_EQ ) { |
494 | 494 | $query->type = SMW_SQL2_VALUE; |
495 | | - $oid = $this->m_store->getSMWPageID( $description->getDatavalue()->getDBkey(), $description->getDatavalue()->getNamespace(), $description->getDatavalue()->getInterwiki() ); |
| 495 | + $oid = $this->m_store->getSMWPageID( $description->getDataItem()->getDBkey(), $description->getDataItem()->getNamespace(), $description->getDataItem()->getInterwiki() ); |
496 | 496 | $query->joinfield = array( $oid ); |
497 | 497 | } else { // Join with smw_ids needed for other comparators (apply to title string). |
498 | 498 | $query->jointable = 'smw_ids'; |
499 | 499 | $query->joinfield = "$query->alias.smw_id"; |
500 | | - $value = $description->getDatavalue()->getSortkey(); |
| 500 | + $value = $description->getDataItem()->getSortKey(); |
501 | 501 | |
502 | 502 | switch ( $description->getComparator() ) { |
503 | 503 | case SMW_CMP_LEQ: $comp = '<='; break; |
— | — | @@ -746,7 +746,7 @@ |
747 | 747 | $where = ''; |
748 | 748 | |
749 | 749 | if ( $description instanceof SMWValueDescription ) { |
750 | | - $dv = $description->getDatavalue(); |
| 750 | + $dv = $description->getDataItem(); |
751 | 751 | $keys = $dv->getDBkeys(); |
752 | 752 | |
753 | 753 | // Try comparison based on value field and comparator. |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php |
— | — | @@ -196,6 +196,24 @@ |
197 | 197 | */ |
198 | 198 | public abstract function getInProperties( SMWDataItem $object, $requestoptions = null ); |
199 | 199 | |
| 200 | + /** |
| 201 | + * Convenience method to find the sortkey of an SMWDIWikiPage. The |
| 202 | + * result is based on the contents of this store, and may differ from |
| 203 | + * the MediaWiki database entry about a Title objects sortkey. If no |
| 204 | + * sortkey is stored, the default sortkey (title string) is returned. |
| 205 | + * |
| 206 | + * @param $wikiPage SMWDIWikiPage to find the sortkey for |
| 207 | + * @return string sortkey |
| 208 | + */ |
| 209 | + public function getWikiPageSortKey( SMWDIWikiPage $wikiPage ) { |
| 210 | + $sortkeyDataItems = $this->getPropertyValues( $wikiPage, new SMWDIProperty( '_SKEY' ) ); |
| 211 | + if ( count( $sortkeyDataItems ) > 0 ) { |
| 212 | + return end( $sortkeyDataItems )->getString(); |
| 213 | + } else { |
| 214 | + return str_replace( '_', ' ', $wikiPage->getDBkey() ); |
| 215 | + } |
| 216 | + } |
| 217 | + |
200 | 218 | ///// Writing methods ///// |
201 | 219 | |
202 | 220 | /** |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php |
— | — | @@ -152,7 +152,8 @@ |
153 | 153 | self::$in_getSemanticData++; |
154 | 154 | |
155 | 155 | // *** Find out if this subject exists ***// |
156 | | - $sid = $this->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki() ); |
| 156 | + $sortkey = ''; |
| 157 | + $sid = $this->getSMWPageIDandSort( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $sortkey, true ); |
157 | 158 | if ( $sid == 0 ) { // no data, safe our time |
158 | 159 | /// NOTE: we consider redirects for getting $sid, so $sid == 0 also means "no redirects" |
159 | 160 | self::$in_getSemanticData--; |
— | — | @@ -163,7 +164,8 @@ |
164 | 165 | // *** Prepare the cache ***// |
165 | 166 | if ( !array_key_exists( $sid, $this->m_semdata ) ) { // new cache entry |
166 | 167 | $this->m_semdata[$sid] = new SMWSemanticData( $subject, false ); |
167 | | - $this->m_sdstate[$sid] = array(); |
| 168 | + $this->m_semdata[$sid]->addPropertyStubValue( '_SKEY', array( $sortkey ) ); |
| 169 | + $this->m_sdstate[$sid] = array( '__key' ); |
168 | 170 | } |
169 | 171 | |
170 | 172 | if ( ( count( $this->m_semdata ) > 20 ) && ( self::$in_getSemanticData == 1 ) ) { |
— | — | @@ -745,8 +747,8 @@ |
746 | 748 | |
747 | 749 | $subject = $data->getSubject(); |
748 | 750 | $this->deleteSemanticData( $subject ); |
| 751 | + |
749 | 752 | $redirects = $data->getPropertyValues( new SMWDIProperty( '_REDI' ) ); |
750 | | - |
751 | 753 | if ( count( $redirects ) > 0 ) { |
752 | 754 | $redirect = end( $redirects ); // at most one redirect per page |
753 | 755 | $this->updateRedirects( $subject->getDBkey(), $subject->getNamespace(), $redirect->getDBkey(), $redirect->getNameSpace() ); |
— | — | @@ -756,8 +758,16 @@ |
757 | 759 | $this->updateRedirects( $subject->getDBkey(), $subject->getNamespace() ); |
758 | 760 | } |
759 | 761 | |
| 762 | + $sortkeyDataItems = $data->getPropertyValues( new SMWDIProperty( '_SKEY' ) ); |
| 763 | + $sortkeyDataItem = end( $sortkeyDataItems ); |
| 764 | + if ( $sortkeyDataItem instanceof SMWDIString ) { |
| 765 | + $sortkey = $sortkeyDataItem->getString(); |
| 766 | + } else { // default sortkey |
| 767 | + $sortkey = str_replace( '_', ' ', $subject->getDBkey() ); |
| 768 | + } |
| 769 | + |
760 | 770 | // Always make an ID (pages without ID cannot be in query results, not even in fixed value queries!): |
761 | | - $sid = $this->makeSMWPageID( $subject->getDBkey(), $subject->getNamespace(), '', true, $subject->getSortkey() ); |
| 771 | + $sid = $this->makeSMWPageID( $subject->getDBkey(), $subject->getNamespace(), '', true, $sortkey ); |
762 | 772 | $updates = array(); // collect data for bulk updates; format: tableid => updatearray |
763 | 773 | $this->prepareDBUpdates( $updates, $data, $sid ); |
764 | 774 | |
— | — | @@ -828,11 +838,15 @@ |
829 | 839 | $proptables = self::getPropertyTables(); |
830 | 840 | |
831 | 841 | foreach ( $data->getProperties() as $property ) { |
| 842 | + if ( ( $property->getKey() == '_SKEY' ) || ( $property->getKey() == '_REDI' ) ) { |
| 843 | + continue; // skip these here, we store them differently |
| 844 | + } |
| 845 | + |
832 | 846 | $tableid = self::findPropertyTableID( $property ); |
833 | 847 | |
834 | 848 | if ( !$tableid ) { // happens when table is not determined by property; use values to find type |
835 | | - $dv = reset( $data->getPropertyValues( $property ) ); |
836 | | - $tableid = self::findTypeTableID( $dv->getTypeID() ); |
| 849 | + $di = reset( $data->getPropertyValues( $property ) ); |
| 850 | + $tableid = self::findTypeTableID( $di->getTypeID() ); |
837 | 851 | } |
838 | 852 | |
839 | 853 | if ( !$tableid ) { // can't store this data, sorry |
— | — | @@ -842,8 +856,6 @@ |
843 | 857 | $proptable = $proptables[$tableid]; |
844 | 858 | |
845 | 859 | foreach ( $data->getPropertyValues( $property ) as $di ) { |
846 | | - if ( $tableid == 'smw_redi2' ) continue; |
847 | | - |
848 | 860 | // errors are already recorded separately, no need to store them here; |
849 | 861 | // redirects were treated above |
850 | 862 | ///TODO check needed if subject is null (would happen if a user defined proptable with !idsubject was used on an internal object -- currently this is not possible |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Compatibility_Helpers.php |
— | — | @@ -148,12 +148,4 @@ |
149 | 149 | return array( false ); |
150 | 150 | } |
151 | 151 | |
152 | | - /** |
153 | | - * Find the sortkey for a SMWDIWikiPage. |
154 | | - * @bug Not correct. Only an intermediate solution. |
155 | | - */ |
156 | | - public static function getSortKey( SMWDIWikiPage $wikiPage ) { |
157 | | - return str_replace( '_', ' ', $wikiPage->getDBkey() ); |
158 | | - } |
159 | | - |
160 | 152 | } |
\ No newline at end of file |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php |
— | — | @@ -221,6 +221,7 @@ |
222 | 222 | '__err' => 'SMWErrorValue', // Special error type |
223 | 223 | '__imp' => 'SMWImportValue', // Special import vocabulary type |
224 | 224 | '__pro' => 'SMWPropertyValue', // Property type (possibly predefined, no always based on a page) |
| 225 | + '__key' => 'SMWStringValue', // Sort key of a page |
225 | 226 | ); |
226 | 227 | |
227 | 228 | self::$mTypeDiClasses = array( |
— | — | @@ -255,6 +256,7 @@ |
256 | 257 | '__err' => 'SMWDIString', // Special error type |
257 | 258 | '__imp' => 'SMWDIString', // Special import vocabulary type |
258 | 259 | '__pro' => 'SMWDIProperty', // Property type (possibly predefined, no always based on a page) |
| 260 | + '__key' => 'SMWDIString', // Sort key of a page |
259 | 261 | ); |
260 | 262 | |
261 | 263 | self::$mTypeDataItemIds = array( |
— | — | @@ -289,6 +291,7 @@ |
290 | 292 | '__err' => SMWDataItem::TYPE_STRING, // Special error type |
291 | 293 | '__imp' => SMWDataItem::TYPE_STRING, // Special import vocabulary type |
292 | 294 | '__pro' => SMWDataItem::TYPE_PROPERTY, // Property type (possibly predefined, no always based on a page) |
| 295 | + '__key' => SMWDataItem::TYPE_STRING, // Sort key of a page |
293 | 296 | ); |
294 | 297 | |
295 | 298 | wfRunHooks( 'smwInitDatatypes' ); |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_WikiPage.php |
— | — | @@ -65,7 +65,8 @@ |
66 | 66 | /** |
67 | 67 | * Get the sortkey of the wiki page data item. Note that this is not |
68 | 68 | * the sortkey that might have been set for the corresponding wiki |
69 | | - * page. |
| 69 | + * page. To obtain the latter, query for the values of the property |
| 70 | + * "new SMWDIProperty( '_SKEY' )". |
70 | 71 | */ |
71 | 72 | public function getSortKey() { |
72 | 73 | return $this->m_dbkey; |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php |
— | — | @@ -305,25 +305,27 @@ |
306 | 306 | SMWDIProperty::$m_prop_labels = $smwgContLang->getPropertyLabels(); |
307 | 307 | SMWDIProperty::$m_prop_aliases = $smwgContLang->getPropertyAliases(); |
308 | 308 | // Setup built-in predefined properties. |
309 | | - // NOTE: all ids must start with underscores, where two underscores informally indicate |
310 | | - // truly internal (non user-accessible properties). All others should also get a |
311 | | - // translation in the language files, or they won't be available for users. |
| 309 | + // NOTE: all ids must start with underscores. The translation |
| 310 | + // for each ID, if any, is defined in the language files. |
| 311 | + // Properties without translation cannot be entered by or |
| 312 | + // displayed to users, whatever their "show" value below. |
312 | 313 | SMWDIProperty::$m_prop_types = array( |
313 | | - '_TYPE' => array( '__typ', true ), |
314 | | - '_URI' => array( '__spu', true ), |
315 | | - '_INST' => array( '__sin', false ), |
316 | | - '_UNIT' => array( '__sps', true ), |
317 | | - '_IMPO' => array( '__imp', true ), |
318 | | - '_CONV' => array( '__sps', true ), |
319 | | - '_SERV' => array( '__sps', true ), |
320 | | - '_PVAL' => array( '__sps', true ), |
321 | | - '_REDI' => array( '__red', true ), |
322 | | - '_SUBP' => array( '__sup', true ), |
323 | | - '_SUBC' => array( '__suc', !$smwgUseCategoryHierarchy ), |
324 | | - '_CONC' => array( '__con', false ), |
325 | | - '_MDAT' => array( '_dat', false ), |
326 | | - '_ERRP' => array( '_wpp', false ), |
327 | | - '_LIST' => array( '__tls', true ), |
| 314 | + '_TYPE' => array( '__typ', true ), // "has type" |
| 315 | + '_URI' => array( '__spu', true ), // "equivalent URI" |
| 316 | + '_INST' => array( '__sin', false ), // instance of a category |
| 317 | + '_UNIT' => array( '__sps', true ), // "displays unit" |
| 318 | + '_IMPO' => array( '__imp', true ), // "imported from" |
| 319 | + '_CONV' => array( '__sps', true ), // "corresponds to" |
| 320 | + '_SERV' => array( '__sps', true ), // "provides service" |
| 321 | + '_PVAL' => array( '__sps', true ), // "allows value" |
| 322 | + '_REDI' => array( '__red', true ), // redirects to some page |
| 323 | + '_SUBP' => array( '__sup', true ), // "subproperty of" |
| 324 | + '_SUBC' => array( '__suc', !$smwgUseCategoryHierarchy ), // "subcategory of" |
| 325 | + '_CONC' => array( '__con', false ), // associated concept |
| 326 | + '_MDAT' => array( '_dat', false ), // "modification date" |
| 327 | + '_ERRP' => array( '_wpp', false ), // "has improper value for" |
| 328 | + '_LIST' => array( '__tls', true ), // "has fields" |
| 329 | + '_SKEY' => array( '__key', true ), // sort key of a page |
328 | 330 | ); |
329 | 331 | wfRunHooks( 'smwInitProperties' ); |
330 | 332 | } |
— | — | @@ -333,7 +335,12 @@ |
334 | 336 | * It should be called from within the hook 'smwInitProperties' only. |
335 | 337 | * IDs should start with three underscores "___" to avoid current and |
336 | 338 | * future confusion with SMW built-ins. |
337 | | - * |
| 339 | + * |
| 340 | + * @param $id string id |
| 341 | + * @param $typeid SMW type id |
| 342 | + * @param $label mixed string user label or false (internal property) |
| 343 | + * @param $show boolean only used if label is given, see isShown() |
| 344 | + * |
338 | 345 | * @note See SMWDIProperty::isShown() for information about $show. |
339 | 346 | */ |
340 | 347 | static public function registerProperty( $id, $typeid, $label = false, $show = false ) { |
— | — | @@ -348,6 +355,12 @@ |
349 | 356 | * should have a primary label, either provided by SMW or registered |
350 | 357 | * with SMWDIProperty::registerProperty(). This function should be |
351 | 358 | * called from within the hook 'smwInitDatatypes' only. |
| 359 | + * |
| 360 | + * @param $id string id of a property |
| 361 | + * @param $label string alias label for the property |
| 362 | + * @note Always use registerProperty() for the first label. No property |
| 363 | + * that has used "false" for a label on registration should have an |
| 364 | + * alias. |
352 | 365 | */ |
353 | 366 | static public function registerPropertyAlias( $id, $label ) { |
354 | 367 | SMWDIProperty::$m_prop_aliases[$label] = $id; |