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

Add property count to property pages #1313

Closed
kghbln opened this issue Dec 14, 2015 · 7 comments
Closed

Add property count to property pages #1313

kghbln opened this issue Dec 14, 2015 · 7 comments
Assignees
Labels
enhancement Alters an existing functionality or behaviour
Milestone

Comments

@kghbln
Copy link
Member

kghbln commented Dec 14, 2015

So far one has to add {{#ask: [[{{PAGENAME}}::+]] |format= count }} to property pages to see how many pages store values that are set for a specific property. If one wants to know how many values are stored for the property one has to proceed to "Special:Properties". I will perhaps be nice to have a system message not only showing the number of pages but also extending this to display the number of values set: Something like "A total of x values are set on a total of x pages for this property. This information was last recalculated on x at y.". Admittedly this is kinda gimmick.

@kghbln kghbln added the enhancement Alters an existing functionality or behaviour label Dec 14, 2015
@mwjames
Copy link
Contributor

mwjames commented Dec 28, 2015

I will perhaps be nice to have a system message not only showing the number of pages but also extending this to display the number of

@@ -1,9 +1,11 @@
 <?php

 use SMW\ApplicationFactory;
 use SMW\DataValueFactory;
+use SMW\RequestOptions;
+use SMW\StringCondition;

@@ -54,23 +56,36 @@ class SMWPropertyPage extends SMWOrderedListPage {
     *
     * @return string
     */
    protected function getTopText() {

+       $propertyName = htmlspecialchars( $this->mTitle->getText() );
+       $usageCount = '';
+
+       $requestOptions = new RequestOptions();
+       $requestOptions->limit = 1;
+       $requestOptions->addStringCondition( $propertyName, StringCondition::STRCOND_PRE );
+       $cachedLookupList = $this->store->getPropertiesSpecial( $requestOptions );
+       $usageList = $cachedLookupList->fetchList();
+
+       if ( $usageList && $usageList !== array() ) {
+           $usage = end( $usageList );
+           $usageCount = wfMessage( 'smw-pa-property-usage', $propertyName, $usage[1], $this->getContext()->getLanguage()->timeanddate( $cachedLookupList->getTimestamp() ) )->parse();
+       }
+
        if ( !$this->mProperty->isUserDefined() ) {
-           $propertyName = htmlspecialchars( $this->mTitle->getText() );
            $propertyKey  = 'smw-pa-property-predefined' . strtolower( $this->mProperty->getKey() );
            $messageKey   = wfMessage( $propertyKey )->exists() ? $propertyKey : 'smw-pa-property-predefined-default';

            return Html::rawElement(
                'div',
                array( 'class' => 'smw-pa-property-predefined-intro' ),
-               wfMessage( $messageKey, $propertyName )->parse() . ' ' . wfMessage( 'smw-pa-property-predefined-common' )->parse()
+               wfMessage( $messageKey, $propertyName )->parse() . ' ' . wfMessage( 'smw-pa-property-predefined-common' )->parse() . ' ' . $usageCount
            );
        }

-       return '';
+       return $usageCount;
+   "smw-pa-property-usage": "\"$1\" is registered with an approximate [https://www.semantic-mediawiki.org/wiki/Help:Property_usage_count usage count] of '''$2''' ($3)."

and you get

image

@mwjames mwjames added the easy label Jan 1, 2016
kghbln added a commit that referenced this issue Jan 7, 2016
References issue #1313

Code changes mainly provided by James Hong Kong. Thanks!
@kghbln kghbln added this to the SMW 2.4 milestone Jan 7, 2016
@kghbln kghbln self-assigned this Jan 7, 2016
@mwjames
Copy link
Contributor

mwjames commented Jan 7, 2016

@mwjames mwjames closed this as completed Jan 7, 2016
@kghbln
Copy link
Member Author

kghbln commented Jan 7, 2016

@kghbln
Copy link
Member Author

kghbln commented Jan 7, 2016

Not to forget: Kudos and thanks for helping on this one!

@kghbln
Copy link
Member Author

kghbln commented Aug 13, 2016

@mwjames I know that the appearance of this was change in a subsequent pull plus the enhancement to show if it is defined by the software or the user (cannot find the pull). Is this behind a configuration setting since it does not show up on smw.o which is on 2.4? sandbox is fine

@mwjames
Copy link
Contributor

mwjames commented Aug 13, 2016

Is this behind a configuration setting since it does not show up on smw.o

We rely on [0] to be available with [1] checking if it is available.

[0] https://www.mediawiki.org/wiki/Help:Page_status_indicators
[1] https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/includes/articlepages/SMW_OrderedListPage.php#L78-L81

@kghbln
Copy link
Member Author

kghbln commented Aug 13, 2016

We rely on [0] to be available with [1] checking if it is available.

Ah, got it. Thanks! I have added this information. Also found the follow up commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Alters an existing functionality or behaviour
Projects
None yet
Development

No branches or pull requests

2 participants