r86216 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86215‎ | r86216 | r86217 >
Date:16:30, 16 April 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
Changed the handling of sortkeys in the API: now properly represented as values of a special property instead of being semi-attached to wiki page value objects
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Compatibility_Helpers.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_OrderedListPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_TypePage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Category.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php
@@ -307,9 +307,9 @@
308308 }
309309
310310 /**
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.
314314 */
315315 static public function onParserAfterTidy( &$parser, &$text ) {
316316 global $smwgUseCategoryHierarchy, $smwgCategoriesAsInstances;
@@ -333,9 +333,11 @@
334334 }
335335 }
336336
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 );
340342
341343 return true;
342344 }
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_WikiPage.php
@@ -11,15 +11,6 @@
1212 * The class can support general wiki pages, or pages of a fixed
1313 * namespace, Whether a namespace is fixed is decided based on the
1414 * 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)
2415 *
2516 * @author Nikolas Iwan
2617 * @author Markus Krötzsch
@@ -28,21 +19,13 @@
2920 class SMWWikiPageValue extends SMWDataValue {
3021
3122 /**
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 - /**
4023 * The isolated title as text. Always set when this object is valid.
4124 * @var string
4225 */
4326 protected $m_textform;
4427
4528 /**
46 - * Fragement text for user-specified title. Not stored, but kept for
 29+ * Fragment text for user-specified title. Not stored, but kept for
4730 * printout on page.
4831 * @var string
4932 */
@@ -78,38 +61,6 @@
7962 */
8063 protected $m_fixNamespace = NS_MAIN;
8164
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 -
11465 public function __construct( $typeid ) {
11566 parent::__construct( $typeid );
11667 switch ( $typeid ) {
@@ -137,7 +88,6 @@
13889 $this->m_caption = $value;
13990 }
14091 $this->m_dataitem = null;
141 - $this->m_sortkey = '';
14292 if ( $value != '' ) {
14393 $this->m_title = Title::newFromText( $value, $this->m_fixNamespace );
14494 ///TODO: Escape the text so users can see any punctuation problems (bug 11666).
@@ -186,7 +136,7 @@
187137 $this->m_textform = str_replace( '_', ' ', $dataItem->getDBkey() );
188138 $this->m_id = -1;
189139 $this->m_title = null;
190 - $this->m_sortkey = $this->m_fragment = $this->m_prefixedtext = '';
 140+ $this->m_fragment = $this->m_prefixedtext = '';
191141 $this->m_caption = false;
192142 if ( ( $this->m_fixNamespace != NS_MAIN ) && ( $this->m_fixNamespace != $dataItem->getNamespace() ) ) {
193143 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
@@ -256,7 +206,7 @@
257207
258208 public function getDBkeys() {
259209 $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() );
261211 }
262212
263213 public function getSignature() {
@@ -399,20 +349,23 @@
400350 }
401351
402352 /**
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.
405355 */
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() );
409359 }
410360
411361 /**
412 - * Set sortkey
 362+ * Find the sortkey for this object.
 363+ *
 364+ * @deprecated Use SMWStore::getWikiPageSortKey().
 365+ *
 366+ * @return string sortkey
413367 */
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 );
417370 }
418371
419372 /**
@@ -426,20 +379,47 @@
427380 }
428381
429382 /**
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()
432384 */
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 ) );
436387 }
437388
438389 /**
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
440401 */
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;
443407 }
444408
 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+
445425 }
446426
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Category.php
@@ -67,7 +67,7 @@
6868 $nextrow = $res->getNext(); // look ahead
6969
7070 $content = $row[0]->getContent();
71 - $sortkey = $content[0]->getSortkey();
 71+ $sortkey = $res->getStore()->getWikiPageSortKey( $content[0] );
7272 $cur_first_char = $wgContLang->firstChar( $sortkey );
7373 if ( $rowindex % $rows_per_column == 0 ) {
7474 $result .= "\n <div style=\"float: left; width: $column_width%;\">\n";
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_OrderedListPage.php
@@ -39,11 +39,12 @@
4040 protected $until;
4141
4242 /**
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).
4445 *
45 - * @var array
 46+ * @var array of SMWDIWikiPage
4647 */
47 - protected $articles;
 48+ protected $diWikiPages;
4849
4950 /**
5051 * Cache for the current skin, obtained from $wgUser.
@@ -119,11 +120,11 @@
120121 * Initialise internal data structures.
121122 */
122123 protected function clearPageState() {
123 - $this->articles = array();
 124+ $this->diWikiPages = array();
124125 }
125126
126127 /**
127 - * Execute the DB query and fill the articles array.
 128+ * Execute the DB query and fill the diWikiPages array.
128129 * Implemented by subclasses.
129130 */
130131 protected abstract function doQuery();
@@ -143,21 +144,21 @@
144145 $sk = $this->getSkin();
145146 $limitText = $wgLang->formatNum( $this->limit );
146147
147 - $ac = count( $this->articles );
 148+ $ac = count( $this->diWikiPages );
148149
149150 if ( $this->until != '' ) {
150151 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] );
152153 } else {
153154 $first = '';
154155 }
155 -
 156+
156157 $last = $this->until;
157158 } elseif ( ( $ac > $this->limit ) || ( $this->from != '' ) ) {
158159 $first = $this->from;
159160
160161 if ( $ac > $this->limit ) {
161 - $last = SMWCompatibilityHelpers::getSortKey( $this->articles[$ac - 1] );
 162+ $last = smwfGetStore()->getWikiPageSortKey( $this->diWikiPages[$ac - 1] );
162163 } else {
163164 $last = '';
164165 }
@@ -212,11 +213,11 @@
213214 *
214215 * @param $start integer
215216 * @param $end integer
216 - * @param $elements of SMWDIWikiPage
 217+ * @param $diWikiPages of SMWDIWikiPage
217218 *
218219 * @return string
219220 */
220 - protected function columnList( $start, $end, $elements ) {
 221+ protected function columnList( $start, $end, $diWikiPages ) {
221222 global $wgContLang;
222223
223224 // Divide list into three equal chunks.
@@ -234,11 +235,12 @@
235236 $r .= "<td>\n";
236237 $atColumnTop = true;
237238
238 - // output all articles
 239+ // output all diWikiPages
239240 for ( $index = $startChunk ; $index < $endChunk && $index < $end; $index++ ) {
240 - $elementDv = SMWDataValueFactory::newDataItemValue( $elements[$index] );
 241+ $dataValue = SMWDataValueFactory::newDataItemValue( $diWikiPages[$index] );
241242 // 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 ) );
243245
244246 if ( ( $index == $startChunk ) ||
245247 ( $start_char != $prev_start_char ) ) {
@@ -258,7 +260,7 @@
259261 $prev_start_char = $start_char;
260262 }
261263
262 - $r .= "<li>" . $elementDv->getLongHTMLText( $this->getSkin() ) . "</li>\n";
 264+ $r .= "<li>" . $dataValue->getLongHTMLText( $this->getSkin() ) . "</li>\n";
263265 }
264266
265267 if ( !$atColumnTop ) {
@@ -274,37 +276,39 @@
275277 }
276278
277279 /**
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.
279281 *
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
283285 *
284286 * @return string
285287 */
286 - protected function shortList( $start, $end, array $elements ) {
 288+ protected function shortList( $start, $end, array $diWikiPages ) {
287289 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+
290297 $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 -
295298 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+
299303 if ( $start_char != $prev_start_char ) {
300304 $r .= "</ul><h3>" . htmlspecialchars( $start_char ) . "</h3>\n<ul>";
301305 $prev_start_char = $start_char;
302306 }
303 -
304 - $r .= '<li>' . $elementDv->getLongHTMLText( $this->getSkin() ) . '</li>';
 307+
 308+ $r .= '<li>' . $dataValue->getLongHTMLText( $this->getSkin() ) . '</li>';
305309 }
306 -
 310+
307311 $r .= '</ul>';
308 -
 312+
309313 return $r;
310314 }
311315
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_TypePage.php
@@ -27,8 +27,8 @@
2828 }
2929
3030 /**
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).
3333 */
3434 protected function doQuery() {
3535 if ( $this->limit > 0 ) {
@@ -42,17 +42,17 @@
4343 $options->boundary = $this->from;
4444 $options->ascending = true;
4545 $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 );
4747 } elseif ( $this->until != '' ) {
4848 $options->boundary = $this->until;
4949 $options->ascending = false;
5050 $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 ) );
5252 } else {
53 - $this->articles = $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options );
 53+ $this->diWikiPages = $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options );
5454 }
5555 } else {
56 - $this->articles = array();
 56+ $this->diWikiPages = array();
5757 }
5858 }
5959
@@ -78,7 +78,7 @@
7979 $r .= '<a name="SMWResults"></a>' . $nav . "<div id=\"mw-pages\">\n";
8080
8181 $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";
8383
8484 $r .= $this->formatList();
8585 $r .= "\n</div>" . $nav;
@@ -87,14 +87,14 @@
8888 }
8989
9090 /**
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
9292 * bullet list or a columnar format, depending on the length.
9393 *
94 - * @param int $cutoff
 94+ * @param $cutoff integer, use columns for more results than that
9595 * @return string
9696 */
9797 private function formatList( $cutoff = 6 ) {
98 - $end = count( $this->articles );
 98+ $end = count( $this->diWikiPages );
9999 if ( $end > $this->limit ) {
100100 if ( $this->until != '' ) {
101101 $start = 1;
@@ -106,11 +106,11 @@
107107 $start = 0;
108108 }
109109
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 );
115115 }
116116 return '';
117117 }
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php
@@ -34,8 +34,8 @@
3535 }
3636
3737 /**
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).
4040 */
4141 protected function doQuery() {
4242 $store = smwfGetStore();
@@ -57,13 +57,13 @@
5858 $reverse = true;
5959 }
6060
61 - $this->articles = $store->getAllPropertySubjects( $this->mProperty, $options );
 61+ $this->diWikiPages = $store->getAllPropertySubjects( $this->mProperty, $options );
6262
6363 if ( $reverse ) {
64 - $this->articles = array_reverse( $this->articles );
 64+ $this->diWikiPages = array_reverse( $this->diWikiPages );
6565 }
6666 } else {
67 - $this->articles = array();
 67+ $this->diWikiPages = array();
6868 }
6969
7070 // retrieve all subproperties of this property
@@ -98,7 +98,7 @@
9999 $r .= "\n</div>";
100100 }
101101
102 - if ( count( $this->articles ) > 0 ) {
 102+ if ( count( $this->diWikiPages ) > 0 ) {
103103 $nav = $this->getNavigationLinks();
104104
105105 $r .= '<a name="SMWResults"></a>' . $nav . "<div id=\"mw-pages\">\n" .
@@ -108,7 +108,7 @@
109109 $r .= wfMsg( 'smw_isspecprop' ) . ' ';
110110 }
111111
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" .
113113 $this->subjectObjectList() . "\n</div>" . $nav;
114114 }
115115
@@ -118,14 +118,14 @@
119119 }
120120
121121 /**
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.
124124 */
125125 private function subjectObjectList() {
126126 global $wgContLang, $smwgMaxPropertyValues;
127127 $store = smwfGetStore();
128128
129 - $ac = count( $this->articles );
 129+ $ac = count( $this->diWikiPages );
130130
131131 if ( $ac > $this->limit ) {
132132 if ( $this->until != '' ) {
@@ -142,9 +142,10 @@
143143 $prev_start_char = 'None';
144144
145145 for ( $index = $start; $index < $ac; $index++ ) {
146 - $diWikiPage = $this->articles[$index];
 146+ $diWikiPage = $this->diWikiPages[$index];
147147 $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 ) );
149150
150151 // Header for index letters
151152 if ( $start_char != $prev_start_char ) {
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
@@ -488,15 +488,15 @@
489489 $this->m_queries[$cqid] = $cquery;
490490 }
491491 } 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' ) {
493493 if ( $description->getComparator() == SMW_CMP_EQ ) {
494494 $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() );
496496 $query->joinfield = array( $oid );
497497 } else { // Join with smw_ids needed for other comparators (apply to title string).
498498 $query->jointable = 'smw_ids';
499499 $query->joinfield = "$query->alias.smw_id";
500 - $value = $description->getDatavalue()->getSortkey();
 500+ $value = $description->getDataItem()->getSortKey();
501501
502502 switch ( $description->getComparator() ) {
503503 case SMW_CMP_LEQ: $comp = '<='; break;
@@ -746,7 +746,7 @@
747747 $where = '';
748748
749749 if ( $description instanceof SMWValueDescription ) {
750 - $dv = $description->getDatavalue();
 750+ $dv = $description->getDataItem();
751751 $keys = $dv->getDBkeys();
752752
753753 // Try comparison based on value field and comparator.
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
@@ -196,6 +196,24 @@
197197 */
198198 public abstract function getInProperties( SMWDataItem $object, $requestoptions = null );
199199
 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+
200218 ///// Writing methods /////
201219
202220 /**
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
@@ -152,7 +152,8 @@
153153 self::$in_getSemanticData++;
154154
155155 // *** 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 );
157158 if ( $sid == 0 ) { // no data, safe our time
158159 /// NOTE: we consider redirects for getting $sid, so $sid == 0 also means "no redirects"
159160 self::$in_getSemanticData--;
@@ -163,7 +164,8 @@
164165 // *** Prepare the cache ***//
165166 if ( !array_key_exists( $sid, $this->m_semdata ) ) { // new cache entry
166167 $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' );
168170 }
169171
170172 if ( ( count( $this->m_semdata ) > 20 ) && ( self::$in_getSemanticData == 1 ) ) {
@@ -745,8 +747,8 @@
746748
747749 $subject = $data->getSubject();
748750 $this->deleteSemanticData( $subject );
 751+
749752 $redirects = $data->getPropertyValues( new SMWDIProperty( '_REDI' ) );
750 -
751753 if ( count( $redirects ) > 0 ) {
752754 $redirect = end( $redirects ); // at most one redirect per page
753755 $this->updateRedirects( $subject->getDBkey(), $subject->getNamespace(), $redirect->getDBkey(), $redirect->getNameSpace() );
@@ -756,8 +758,16 @@
757759 $this->updateRedirects( $subject->getDBkey(), $subject->getNamespace() );
758760 }
759761
 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+
760770 // 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 );
762772 $updates = array(); // collect data for bulk updates; format: tableid => updatearray
763773 $this->prepareDBUpdates( $updates, $data, $sid );
764774
@@ -828,11 +838,15 @@
829839 $proptables = self::getPropertyTables();
830840
831841 foreach ( $data->getProperties() as $property ) {
 842+ if ( ( $property->getKey() == '_SKEY' ) || ( $property->getKey() == '_REDI' ) ) {
 843+ continue; // skip these here, we store them differently
 844+ }
 845+
832846 $tableid = self::findPropertyTableID( $property );
833847
834848 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() );
837851 }
838852
839853 if ( !$tableid ) { // can't store this data, sorry
@@ -842,8 +856,6 @@
843857 $proptable = $proptables[$tableid];
844858
845859 foreach ( $data->getPropertyValues( $property ) as $di ) {
846 - if ( $tableid == 'smw_redi2' ) continue;
847 -
848860 // errors are already recorded separately, no need to store them here;
849861 // redirects were treated above
850862 ///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 @@
149149 return array( false );
150150 }
151151
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 -
160152 }
\ No newline at end of file
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -221,6 +221,7 @@
222222 '__err' => 'SMWErrorValue', // Special error type
223223 '__imp' => 'SMWImportValue', // Special import vocabulary type
224224 '__pro' => 'SMWPropertyValue', // Property type (possibly predefined, no always based on a page)
 225+ '__key' => 'SMWStringValue', // Sort key of a page
225226 );
226227
227228 self::$mTypeDiClasses = array(
@@ -255,6 +256,7 @@
256257 '__err' => 'SMWDIString', // Special error type
257258 '__imp' => 'SMWDIString', // Special import vocabulary type
258259 '__pro' => 'SMWDIProperty', // Property type (possibly predefined, no always based on a page)
 260+ '__key' => 'SMWDIString', // Sort key of a page
259261 );
260262
261263 self::$mTypeDataItemIds = array(
@@ -289,6 +291,7 @@
290292 '__err' => SMWDataItem::TYPE_STRING, // Special error type
291293 '__imp' => SMWDataItem::TYPE_STRING, // Special import vocabulary type
292294 '__pro' => SMWDataItem::TYPE_PROPERTY, // Property type (possibly predefined, no always based on a page)
 295+ '__key' => SMWDataItem::TYPE_STRING, // Sort key of a page
293296 );
294297
295298 wfRunHooks( 'smwInitDatatypes' );
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_WikiPage.php
@@ -65,7 +65,8 @@
6666 /**
6767 * Get the sortkey of the wiki page data item. Note that this is not
6868 * 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' )".
7071 */
7172 public function getSortKey() {
7273 return $this->m_dbkey;
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php
@@ -305,25 +305,27 @@
306306 SMWDIProperty::$m_prop_labels = $smwgContLang->getPropertyLabels();
307307 SMWDIProperty::$m_prop_aliases = $smwgContLang->getPropertyAliases();
308308 // 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.
312313 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
328330 );
329331 wfRunHooks( 'smwInitProperties' );
330332 }
@@ -333,7 +335,12 @@
334336 * It should be called from within the hook 'smwInitProperties' only.
335337 * IDs should start with three underscores "___" to avoid current and
336338 * 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+ *
338345 * @note See SMWDIProperty::isShown() for information about $show.
339346 */
340347 static public function registerProperty( $id, $typeid, $label = false, $show = false ) {
@@ -348,6 +355,12 @@
349356 * should have a primary label, either provided by SMW or registered
350357 * with SMWDIProperty::registerProperty(). This function should be
351358 * 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.
352365 */
353366 static public function registerPropertyAlias( $id, $label ) {
354367 SMWDIProperty::$m_prop_aliases[$label] = $id;

Status & tagging log