Mwjames has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/67396


Change subject: (Bug 33181) Special:Concepts to list available concepts
......................................................................

(Bug 33181) Special:Concepts to list available concepts

I got relentlessly tiered of searching for existing concepts therefore
this Special:Concepts should solve the issue.

Also fixed "Use of Linker::makeLinkObj was deprecated in MediaWiki 1.21" in
SMW_DV_WikiPage.php:287 due to the complained of PHPunit.

Test coverage: 100%
CRAP: 6

Change-Id: I4901a2814e9e9c514dbd2b5abf4be74002319f6e
---
M SemanticMediaWiki.hooks.php
M includes/Setup.php
M includes/datavalues/SMW_DV_WikiPage.php
A includes/specials/SpecialConcepts.php
M languages/SMW_Aliases.php
M languages/SMW_Messages.php
A tests/phpunit/SpecialPageTestCase.php
A tests/phpunit/includes/specials/SpecialConceptsTest.php
8 files changed, 359 insertions(+), 4 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki 
refs/changes/96/67396/1

diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index b1cc520..5a78cfd 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -293,6 +293,7 @@
 
                        'specials/Specials',
                        'specials/WantedPropertiesPage',
+                       'specials/SpecialConcepts',
 
                        // Keep store tests near the end, since they are slower 
due to database access.
                        'storage/StoreFactory',
@@ -462,7 +463,7 @@
                        $extraStats[wfMessage( 'smw-statistics-property-type' 
)->text()] = $wgLang->formatNum( $semanticStatistics['DECLPROPS'] );
                        $extraStats[wfMessage( 'smw-statistics-subobject-count' 
)->text()]  = $wgLang->formatNum( $semanticStatistics['SUBOBJECTS'] );
                        $extraStats[wfMessage( 'smw-statistics-query-inline' 
)->text()]  = $wgLang->formatNum( $semanticStatistics['QUERY'] );
-                       $extraStats[wfMessage( 'smw-statistics-concept-count' 
)->text()]  = $wgLang->formatNum( $semanticStatistics['CONCEPTS'] );
+                       $extraStats[wfMessage( 
'smw-statistics-concept-count-legacy' )->text()]  = $wgLang->formatNum( 
$semanticStatistics['CONCEPTS'] );
                } else {
                        $extraStats['smw-statistics'] = array();
                        
$extraStats['smw-statistics']['smw-statistics-property-instance'] = 
$semanticStatistics['PROPUSES'];
diff --git a/includes/Setup.php b/includes/Setup.php
index fb53ae4..6909c34 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -326,6 +326,7 @@
        // Special pages and closely related helper classes
        $specDir = $smwgIP . 'includes/specials/';
        $wgAutoloadClasses['SMW\SpecialSemanticStatistics'] = $specDir . 
'SpecialSemanticStatistics.php';
+       $wgAutoloadClasses['SMW\SpecialConcepts']           = $specDir . 
'SpecialConcepts.php';
 
        $wgAutoloadClasses['SMWAskPage']                    = $specDir . 
'SMW_SpecialAsk.php';
        $wgAutoloadClasses['SMWQueryUIHelper']              = $specDir . 
'SMW_QueryUIHelper.php';
@@ -352,6 +353,7 @@
        $wgAutoloadClasses['SMW\Test\ParserTestCase']             = $testsDir . 
'ParserTestCase.php';
        $wgAutoloadClasses['SMW\Test\ApiTestCase']                = $testsDir . 
'ApiTestCase.php';
        $wgAutoloadClasses['SMW\Test\MockSuperUser']              = $testsDir . 
'MockSuperUser.php';
+       $wgAutoloadClasses['SMW\Test\SpecialPageTestCase']        = $testsDir . 
'SpecialPageTestCase.php';
 
        // Jobs
        $wgJobClasses['SMWUpdateJob']       = 'SMWUpdateJob';
@@ -407,6 +409,10 @@
                        'page' => 'SMW\SpecialSemanticStatistics',
                        'group' => 'wiki'
                ),
+               'Concepts' => array(
+                       'page' => 'SMW\SpecialConcepts',
+                       'group' => 'pages'
+               ),
                'ExportRDF' => array(
                        'page' => 'SMWSpecialOWLExport',
                        'group' => 'smw_group'
diff --git a/includes/datavalues/SMW_DV_WikiPage.php 
b/includes/datavalues/SMW_DV_WikiPage.php
index f0e4a3b..d45a874 100644
--- a/includes/datavalues/SMW_DV_WikiPage.php
+++ b/includes/datavalues/SMW_DV_WikiPage.php
@@ -283,7 +283,7 @@
                        return $linker->makeMediaLinkObj( $this->getTitle(),
                                htmlspecialchars( $this->getLongCaptionText() ) 
);
                } else { // all others use default linking, no embedding of 
images here
-                       return $linker->makeLinkObj( $this->getTitle(),
+                       return $linker->link( $this->getTitle(),
                                htmlspecialchars( $this->getLongCaptionText() ) 
);
                }
        }
diff --git a/includes/specials/SpecialConcepts.php 
b/includes/specials/SpecialConcepts.php
new file mode 100644
index 0000000..79eaa71
--- /dev/null
+++ b/includes/specials/SpecialConcepts.php
@@ -0,0 +1,119 @@
+<?php
+
+namespace SMW;
+
+use SMWThingDescription;
+use SMWSomeProperty;
+use SMWDIProperty;
+use SMWPageLister;
+
+use SpecialPage;
+use Html;
+
+/**
+ * Special page that lists available concepts
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 1.9
+ *
+ * @file
+ * @ingroup SpecialPage
+ *
+ * @license GNU GPL v2+
+ * @author: mwjames
+ */
+
+/**
+ * Special page that lists available concepts
+ *
+ * @ingroup SpecialPage
+ */
+class SpecialConcepts extends SpecialPage {
+
+       /**
+        * @see SpecialPage::__construct
+        */
+       public function __construct() {
+               parent::__construct( 'Concepts' );
+       }
+
+       /**
+        * Returns concept pages
+        *
+        * @since 1.9
+        *
+        * @param integer $limit,
+        * @param integer $from
+        * @param integer $until
+        *
+        * @return DIWikiPage
+        */
+       public function getResults( $limit, $from, $until ) {
+               $description = new SMWSomeProperty( new SMWDIProperty( '_CONC' 
), new SMWThingDescription() );
+               $query = SMWPageLister::getQuery( $description, $limit, $from, 
$until );
+               return StoreFactory::getStore()->getQueryResult( $query 
)->getResults();
+       }
+
+       /**
+        * Returns html
+        *
+        * @since 1.9
+        *
+        * @param DIWikiPage $diWikiPages
+        * @param integer $limit,
+        * @param integer $from
+        * @param integer $until
+        *
+        * @return string
+        */
+       public function getHtml( $diWikiPages, $limit, $from , $until ) {
+               $resultNumber = min( $limit, count( $diWikiPages ) );
+               $pageLister = new SMWPageLister( $diWikiPages, null, $limit, 
$from , $until );
+
+               return Html::rawElement( 'span', array( 'class' => 
'smw-sp-concept-docu' ), $this->msg( 'smw-sp-concept-docu' )->parse() ) .
+                       Html::rawElement( 'div', array( 'id' => 'mw-pages'),
+                               Html::rawElement( 'h2', array(), $this->msg( 
'smw-sp-concept-header' )->text() ) .
+                               Html::element( 'span', array(), $this->msg( 
$resultNumber == 0 ? 'smw-sp-concept-empty' : 'smw-sp-concept-count', 
$resultNumber )->parse() ) . ' ' .
+                               $pageLister->getNavigationLinks( 
$this->getTitle() ) .
+                               $pageLister->formatList()
+                       );
+       }
+
+       /**
+        * Executes and outputs results for available concepts
+        *
+        * @since 1.9
+        *
+        * @param array $param
+        */
+       public function execute( $param ) {
+               wfProfileIn( __METHOD__ );
+
+               $this->getOutput()->setPageTitle( $this->msg( 'concepts' 
)->text() );
+
+               $from  = $this->getRequest()->getVal( 'from' , '' );
+               $until = $this->getRequest()->getVal( 'until', '' );
+               $limit = $this->getRequest()->getVal( 'limit', 50 );
+
+               $diWikiPages = $this->getResults( $limit, $from, $until );
+               $diWikiPages = $until !== '' ? array_reverse( $diWikiPages ) : 
$diWikiPages;
+
+               $this->getOutput()->addHTML( $this->getHtml( $diWikiPages, 
$limit, $from , $until ) );
+
+               wfProfileOut( __METHOD__ );
+       }
+}
diff --git a/languages/SMW_Aliases.php b/languages/SMW_Aliases.php
index 2dac1b5..62ec1e1 100644
--- a/languages/SMW_Aliases.php
+++ b/languages/SMW_Aliases.php
@@ -16,6 +16,7 @@
        'ExportRDF' => array( 'ExportRDF' ),
        'PageProperty' => array( 'PageProperty' ),
        'Properties' => array( 'Properties' ),
+       'Concepts' => array( 'Concepts' ),
        'SMWAdmin' => array( 'SMWAdmin' ),
        'SearchByProperty' => array( 'SearchByProperty' ),
        'SemanticStatistics' => array( 'SemanticStatistics' ),
diff --git a/languages/SMW_Messages.php b/languages/SMW_Messages.php
index 2a6e08a..b36509b 100644
--- a/languages/SMW_Messages.php
+++ b/languages/SMW_Messages.php
@@ -188,6 +188,13 @@
        'smw_propertyhardlyused' => 'This property is hardly used within the 
wiki!',
        'smw-property-name-invalid' => 'Property $1 can not be used (invalid 
property name).',
 
+       // Messages for Concepts Special
+       'concepts'              => 'Concepts',
+       'smw-sp-concept-docu'   => 'A 
[https://www.semantic-mediawiki.org/wiki/Help:Concepts concept] can be viewed 
as "dynamic category", i.e. as a collection of pages that are not created 
manually, but that are computed by Semantic MediaWiki from a description of a 
given query.',
+       'smw-sp-concept-header' => 'List of concepts',
+       'smw-sp-concept-count'  => 'The following $1 
{{PLURAL:$1|concept|concepts}} {{PLURAL:$1|is|are}} being listed.',
+       'smw-sp-concept-empty'  => 'No concept was found.',
+
        // Messages for Unused Properties Special
        'unusedproperties' => 'Unused properties',
        'smw_unusedproperties_docu' => 'The following properties exist although 
no other page makes use of them.',
@@ -221,7 +228,8 @@
        'smw-statistics-property-type'  => '{{PLURAL:$1|Property|Properties}} 
(assigned to a datatype)',
        'smw-statistics-query-inline'   => '{{PLURAL:$1|Query|Queries}}',
        'smw-statistics-query-size'     => 'Query size',
-       'smw-statistics-concept-count'  => '{{PLURAL:$1|Concept|Concepts}}',
+       'smw-statistics-concept-count-legacy'  => 
'{{PLURAL:$1|Concept|Concepts}}',
+       'smw-statistics-concept-count'  => 
'[[Special:Concepts|{{PLURAL:$1|Concept|Concepts}}]]',
        'smw-statistics-subobject-count'  => 
'{{PLURAL:$1|Subobject|Subobjects}}',
        'smw-statistics-datatype-count' => 
'[[Special:Types|{{PLURAL:$1|Datatype|Datatypes}}]]',
 
@@ -418,7 +426,7 @@
        // User preference
        'prefs-smw' => 'Semantic MediaWiki',
        'prefs-ask-options' => 'Semantic search options',
-       'smw-prefs-intro-text' => 'Options below are provided by 
[http://semantic-mediawiki.org/ Semantic MediaWiki] (or related extensions) to 
enable individual customization on selected functions. For more information, 
please have a look at this 
[http://semantic-mediawiki.org/wiki/Help:User_preferences help section].',
+       'smw-prefs-intro-text' => 'Options below are provided by 
[https://semantic-mediawiki.org/ Semantic MediaWiki] (or related extensions) to 
enable individual customization on selected functions. For more information, 
please have a look at this 
[http://semantic-mediawiki.org/wiki/Help:User_preferences help section].',
        'smw-prefs-ask-options-tooltip-display' => 'Display parameter text as 
an info tooltip',
        'smw-prefs-ask-options-collapsed-default' => 'Enable option box to be 
collapsed by default',
 
@@ -692,6 +700,7 @@
        'smw-statistics-property-type' => 'Is a label that is displayed on the 
[[Special:Statistics|Statistics]] page',
        'smw-statistics-query-inline' => 'Is a label that is displayed on the 
[[Special:Statistics|Statistics]] page',
        'smw-statistics-query-size' => 'Is a label that is displayed on the 
[[Special:Statistics|Statistics]] page',
+       'smw-statistics-concept-count-legacy' => 'Is a label that is displayed 
on the [[Special:Statistics|Statistics]] page.',
        'smw-statistics-concept-count' => 'Is a label that is displayed on the 
[[Special:Statistics|Statistics]] page.
 {{Identical|Concept}}',
        'smw-statistics-subobject-count' => 'Is a label that is displayed on 
the [[Special:Statistics|Statistics]] page',
@@ -970,6 +979,12 @@
        'smw_conceptarticlecount' => 'This is the introductory message below 
the header on pages in namespace "Concept". Parameters:
 * $1 holds the number of pages displayed in the current view.',
        'smw-qp-aggregatable-empty-data' => 'An error message shown for 
insufficient data.',
+
+       'concepts'              => '{{doc-special|Concepts}}',
+       'smw-sp-concept-docu'   => 'This is an introductory message at the top 
of [[Special:Concepts]].',
+       'smw-sp-concept-header' => 'This is a header used on 
[[Special:Concepts]].',
+       'smw-sp-concept-count'  => 'This is used on [[Special:Concepts]] and to 
display available concepts',
+       'smw-sp-concept-empty'  => 'This is used on [[Special:Concepts]] and to 
display that no concept is available.',
 );
 
 /** Afrikaans (Afrikaans)
diff --git a/tests/phpunit/SpecialPageTestCase.php 
b/tests/phpunit/SpecialPageTestCase.php
new file mode 100644
index 0000000..308cf50
--- /dev/null
+++ b/tests/phpunit/SpecialPageTestCase.php
@@ -0,0 +1,118 @@
+<?php
+
+namespace SMW\Test;
+
+use DerivativeContext;
+use RequestContext;
+use FauxRequest;
+use WebRequest;
+use OutputPage;
+
+/**
+ * Class contains methods to access SpecialPages
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 1.9
+ *
+ * @file
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ *
+ * @licence GNU GPL v2+
+ * @author mwjames
+ */
+
+/**
+ * Class contains methods to access SpecialPages
+ *
+ * @ingroup Test
+ */
+abstract class SpecialPageTestCase extends SemanticMediaWikiTestCase {
+
+       /**
+        * Returns a new instance of the special page under test.
+        *
+        * @return \SpecialPage
+        */
+       protected abstract function getInstance();
+
+       /**
+        * This is borrowed from \Wikibase\Test\SpecialPageTestBase
+        *
+        * @param string      $sub The subpage parameter to call the page with
+        * @param \WebRequest $request Web request that may contain URL 
parameters, etc
+        */
+       protected function execute( $sub = '', WebRequest $request = null ) {
+
+               $request = $request === null ? new FauxRequest() : $request;
+               $response = $request->response();
+
+               $context = new DerivativeContext( RequestContext::getMain() );
+               $context->setRequest( $request );
+
+               $out = new OutputPage( $context );
+               $context->setOutput( $out );
+
+               $page = $this->getInstance();
+               $page->setContext( $context );
+
+               $out->setTitle( $page->getTitle() );
+
+               ob_start();
+               $page->execute( $sub );
+
+               if ( $out->getRedirect() !== '' ) {
+                       $out->output();
+                       $text = ob_get_contents();
+               } elseif ( $out->isDisabled() ) {
+                       $text = ob_get_contents();
+               } else {
+                       $text = $out->getHTML();
+               }
+
+               ob_end_clean();
+
+               $code = $response->getStatusCode();
+
+               if ( $code > 0 ) {
+                       $response->header( "Status: " . $code . ' ' . 
\HttpStatus::getMessage( $code ) );
+               }
+
+               $this->text = $text;
+               $this->response = $response;
+       }
+
+       /**
+        * Returns output text
+        *
+        * @return string
+        */
+       protected function getOutput() {
+               return $this->text;
+       }
+
+       /**
+        * Returns response object
+        *
+        * @return FauxResponse
+        */
+       protected function getResponse() {
+               return $this->response;
+       }
+}
diff --git a/tests/phpunit/includes/specials/SpecialConceptsTest.php 
b/tests/phpunit/includes/specials/SpecialConceptsTest.php
new file mode 100644
index 0000000..210fe7e
--- /dev/null
+++ b/tests/phpunit/includes/specials/SpecialConceptsTest.php
@@ -0,0 +1,95 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\SpecialConcepts;
+use SMWDIWikiPage;
+
+/**
+ * Tests for the SpecialConcepts class
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 1.9
+ *
+ * @file
+ * @ingroup Test
+ *
+ * @licence GNU GPL v2+
+ * @author mwjames
+ */
+
+/**
+ * Tests for the SpecialConcepts class
+ * @covers SMW\SpecialConcepts
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ */
+class SpecialConceptsTest extends SpecialPageTestCase {
+
+       /**
+        * Returns the name of the class to be tested
+        *
+        * @return string|false
+        */
+       public function getClass() {
+               return '\SMW\SpecialConcepts';
+       }
+
+       /**
+        * Helper method that returns a SpecialConcepts object
+        *
+        * @since 1.9
+        *
+        * @param $result
+        *
+        * @return SpecialConcepts
+        */
+       protected function getInstance() {
+               return new SpecialConcepts();
+       }
+
+       /**
+        * @test SpecialConcepts::__construct
+        *
+        * @since 1.9
+        */
+       public function testConstructor() {
+               $instance = $this->getInstance();
+               $this->assertInstanceOf( $this->getClass(), $instance );
+       }
+
+       /**
+        * @test SpecialConcepts::execute
+        *
+        * @since 1.9
+        */
+       public function testExecute() {
+
+               $this->getInstance();
+               $this->execute();
+
+               $matches = array(
+                       'tag' => 'span',
+                       'attributes' => array( 'class' => 'smw-sp-concept-docu' 
)
+               );
+
+               $this->assertTag( $matches, $this->getOutput() );
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/67396
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4901a2814e9e9c514dbd2b5abf4be74002319f6e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to