Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show redirects (synonyms) on property page, refs 1927 #2157

Merged
merged 1 commit into from Jan 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 38 additions & 4 deletions DefaultSettings.php
Expand Up @@ -39,6 +39,15 @@
'smwgSemanticsEnabled' => false,
##

###
# CompatibilityMode is to force SMW to work with other extensions that may impact
# performance in an unanticipated way or may contain potential incompatibilities.
#
# @since 2.4
##
'smwgEnabledCompatibilityMode' => false,
##

###
# Use another storage backend for Semantic MediaWiki. The default is suitable
# for most uses of SMW.
Expand Down Expand Up @@ -154,6 +163,8 @@
# be the smallest even namespace number that is not in use yet. However, it
# must not be smaller than 100.
##
# 'smwgNamespaceIndex' => 100,
##

###
# Overwriting the following array, you can define for which namespaces
Expand Down Expand Up @@ -277,6 +288,8 @@

###
# Whether the browse display is to be generated using an API request or not.
#
# @since 2.5
##
'smwgBrowseByApi' => true,
##
Expand All @@ -303,14 +316,35 @@
##

###
# How many values should at most be displayed for a page on the Property page?
# Property page to limit the query request for individual values
#
# How many values should at most be displayed for a page on the Property
# page and if large values are desired, consider reducing
# $smwgPropertyPagingLimit for better performance.
#
# @since 1.3
##
'smwgMaxPropertyValues' => 3,
##

###
# Property page to limit the query request on subproperties
#
# @since 2.5
##
'smwgSubPropertyListLimit' => 25,
##

###
# Property page to limit the query request on redirects
#
# @since 2.5
##
'smwgMaxPropertyValues' => 3, // if large values are desired, consider reducing $smwgPropertyPagingLimit for better performance
'smwgSubPropertyListLimit' => 25, // property page to limit the query request on subproperties
'smwgRedirectPropertyListLimit' => 25,
##

###
# Settings for inline queries ({{ #ask:...}}) and for semantic queries in
# Settings for inline queries ({{#ask:...}}) and for semantic queries in
# general. This can especially be used to prevent overly high server-load due
# to complex queries. The following settings affect all queries, wherever they
# occur.
Expand Down
7 changes: 4 additions & 3 deletions i18n/en.json
Expand Up @@ -131,9 +131,10 @@
"smw_typearticlecount": "Showing $1 {{PLURAL:$1|property|properties}} using this type.",
"smw_attribute_header": "Pages using the property \"$1\"",
"smw_attributearticlecount": "Showing $1 {{PLURAL:$1|page|pages}} using this property.",
"smw_subproperty_header": "Subproperties",
"smw-subpropertylist-count": "This property has the following $1 {{PLURAL:$1|subproperty|subproperties}}:",
"smw-subpropertylist-count-with-restricted-note": "This property has the following $1 {{PLURAL:$1|subproperty|subproperties}} (more are available but the selection is restricted to [https://www.semantic-mediawiki.org/wiki/Help:$smwgSubPropertyListLimit $2]):",
"smw-propertylist-subproperty-header": "Subproperties",
"smw-propertylist-redirect-header": "Synonyms",
"smw-propertylist-count": "Showing $1 related {{PLURAL:$1|property|properties}}.",
"smw-propertylist-count-with-restricted-note": "Showing $1 related {{PLURAL:$1|property|properties}} (more are available but the display is restricted to \"$2\").",
"specialpages-group-smw_group": "Semantic MediaWiki",
"exportrdf": "Export pages to RDF",
"smw_exportrdf_docu": "This page allows you to obtain data from a page in RDF format.\nTo export pages, enter the titles in the text box below, one title per line.",
Expand Down
20 changes: 15 additions & 5 deletions includes/SMW_PageLister.php
Expand Up @@ -277,19 +277,17 @@ public static function getColumnList( $start, $end, array $diWikiPages, $diPrope
* @return string
*/
public static function getShortList( $start, $end, array $diWikiPages, $diProperty ) {
global $wgContLang;

$startDv = \SMW\DataValueFactory::getInstance()->newDataValueByItem( $diWikiPages[$start], $diProperty );
$sortkey = \SMW\StoreFactory::getStore()->getWikiPageSortKey( $diWikiPages[$start] );
$startChar = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );
$startChar = self::getFirstChar( $diWikiPages[$start] );

$r = '<h3>' . htmlspecialchars( $startChar ) . "</h3>\n" .
'<ul><li>' . $startDv->getLongHTMLText( smwfGetLinker() ) . '</li>';

$prevStartChar = $startChar;
for ( $index = $start + 1; $index < $end; $index++ ) {
$dataValue = \SMW\DataValueFactory::getInstance()->newDataValueByItem( $diWikiPages[$index], $diProperty );
$sortkey = \SMW\StoreFactory::getStore()->getWikiPageSortKey( $diWikiPages[$index] );
$startChar = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );
$startChar = self::getFirstChar( $diWikiPages[$index] );

if ( $startChar != $prevStartChar ) {
$r .= "</ul><h3>" . htmlspecialchars( $startChar ) . "</h3>\n<ul>";
Expand All @@ -304,4 +302,16 @@ public static function getShortList( $start, $end, array $diWikiPages, $diProper
return $r;
}

private static function getFirstChar( $dataItem ) {
global $wgContLang;

$sortkey = \SMW\StoreFactory::getStore()->getWikiPageSortKey( $dataItem );

if ( $sortkey === '' ) {
$sortkey = $dataItem->getDBKey();
}

return $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );
}

}
2 changes: 2 additions & 0 deletions includes/Settings.php
Expand Up @@ -41,6 +41,7 @@ public static function newFromGlobals() {
'smwgIP' => $GLOBALS['smwgIP'],
'smwgExtraneousLanguageFileDir' => $GLOBALS['smwgExtraneousLanguageFileDir'],
'smwgSemanticsEnabled' => $GLOBALS['smwgSemanticsEnabled'],
'smwgEnabledCompatibilityMode' => $GLOBALS['smwgEnabledCompatibilityMode'],
'smwgDefaultStore' => $GLOBALS['smwgDefaultStore'],
'smwgSparqlDatabaseConnector' => $GLOBALS['smwgSparqlDatabaseConnector'],
'smwgSparqlDatabase' => $GLOBALS['smwgSparqlDatabase'],
Expand Down Expand Up @@ -69,6 +70,7 @@ public static function newFromGlobals() {
'smwgConceptPagingLimit' => $GLOBALS['smwgConceptPagingLimit'],
'smwgPropertyPagingLimit' => $GLOBALS['smwgPropertyPagingLimit'],
'smwgSubPropertyListLimit' => $GLOBALS['smwgSubPropertyListLimit'],
'smwgRedirectPropertyListLimit' => $GLOBALS['smwgRedirectPropertyListLimit'],
'smwgQEnabled' => $GLOBALS['smwgQEnabled'],
'smwgQMaxLimit' => $GLOBALS['smwgQMaxLimit'],
'smwgIgnoreQueryErrors' => $GLOBALS['smwgIgnoreQueryErrors'],
Expand Down
61 changes: 42 additions & 19 deletions includes/articlepages/SMW_PropertyPage.php
Expand Up @@ -52,7 +52,31 @@ protected function getHtml() {
$title = $dv->getFormattedLabel( DataValueFormatter::WIKI_LONG );
$this->getContext()->getOutput()->setPageTitle( $title );

$list = $this->getSubpropertyList() . $this->getPropertyValueList();
$requestOptions = new RequestOptions();
$requestOptions->sort = true;
$requestOptions->ascending = true;

// +1 look ahead
$requestOptions->setLimit( $GLOBALS['smwgRedirectPropertyListLimit'] + 1 );

$list = $this->getPropertyList(
new DIProperty( '_REDI' ),
$requestOptions,
$GLOBALS['smwgRedirectPropertyListLimit'],
'smw-propertylist-redirect'
);

$requestOptions->setLimit( $GLOBALS['smwgSubPropertyListLimit'] + 1 );

$list .= $this->getPropertyList(
new DIProperty( '_SUBP' ),
$requestOptions,
$GLOBALS['smwgSubPropertyListLimit'],
'smw-propertylist-subproperty'
);

$list .= $this->getPropertyValueList();

$result = ( $list !== '' ? Html::element( 'div', array( 'id' => 'smwfootbr' ) ) . $list : '' );

return $result;
Expand Down Expand Up @@ -140,50 +164,49 @@ protected function getTopIndicator() {
*
* @return string
*/
protected function getSubpropertyList() {
protected function getPropertyList( $property, $requestOptions, $listLimit, $header ) {

$more = false;
$requestOptions = new RequestOptions();
$requestOptions->sort = true;
$requestOptions->ascending = true;
$propertyList = $this->store->getPropertySubjects(
$property,
$this->getDataItem(),
$requestOptions
);

// +1 look-ahead
$requestOptions->setLimit( $GLOBALS['smwgSubPropertyListLimit'] + 1 );
$subproperties = $this->store->getPropertySubjects( new DIProperty( '_SUBP' ), $this->getDataItem(), $requestOptions );
$more = false;

// Pop the +1 look-ahead from the list
if ( count( $subproperties ) > $GLOBALS['smwgSubPropertyListLimit'] ) {
array_pop( $subproperties );
// Pop the +1 look ahead from the list
if ( count( $propertyList ) > $listLimit ) {
array_pop( $propertyList );
$more = true;
}

$result = '';
$resultCount = count( $subproperties );
$resultCount = count( $propertyList );

if ( $more ) {
$message = Html::rawElement(
'span',
array( 'class' => 'plainlinks' ),
wfMessage( 'smw-subpropertylist-count-with-restricted-note', $resultCount, $GLOBALS['smwgSubPropertyListLimit'] )->parse()
wfMessage( 'smw-propertylist-count-with-restricted-note', $resultCount, $listLimit )->parse()
);
} else {
$message = wfMessage( 'smw-subpropertylist-count', $resultCount )->text();
$message = wfMessage( 'smw-propertylist-count', $resultCount )->text();
}

if ( $resultCount > 0 ) {
$titleText = htmlspecialchars( $this->mTitle->getText() );
$result .= "<div id=\"mw-subcategories\">\n<h2>" . wfMessage( 'smw_subproperty_header', $titleText )->text() . "</h2>\n<p>";
$result .= "<div id=\"{$header}\">" . Html::rawElement( 'h2' , array(), wfMessage( $header . '-header', $titleText )->text() ) . "\n<p>";

if ( !$this->mProperty->isUserDefined() ) {
$result .= wfMessage( 'smw_isspecprop' )->text() . ' ';
}

$result .= $message . "</p>" ."\n";
$result .= $message . "</p>";

if ( $resultCount < 6 ) {
$result .= SMWPageLister::getShortList( 0, $resultCount, $subproperties, null );
$result .= SMWPageLister::getShortList( 0, $resultCount, $propertyList, null );
} else {
$result .= SMWPageLister::getColumnList( 0, $resultCount, $subproperties, null );
$result .= SMWPageLister::getColumnList( 0, $resultCount, $propertyList, null );
}

$result .= "\n</div>";
Expand Down