jenkins-bot has submitted this change and it was merged.

Change subject: SMWQueryPage::getSearchForm() add search form
......................................................................


SMWQueryPage::getSearchForm() add search form

* Add search form similar to that found in Special:Categories used in [1]
* Add QueryPageTest

[1] https://gerrit.wikimedia.org/r/#/c/70041/

Change-Id: Ic008776070bae9e4d2c16223545ae4256546308f
---
M includes/SMW_QueryPage.php
M languages/SMW_Messages.php
A tests/phpunit/includes/QueryPageTest.php
3 files changed, 166 insertions(+), 3 deletions(-)

Approvals:
  Mwjames: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/SMW_QueryPage.php b/includes/SMW_QueryPage.php
index dbc8d09..81ca50c 100644
--- a/includes/SMW_QueryPage.php
+++ b/includes/SMW_QueryPage.php
@@ -41,6 +41,23 @@
        }
 
        /**
+        * @see QueryPage::linkParameters
+        *
+        * @since 1.9
+        *
+        * @return array
+        */
+       public function linkParameters() {
+               $parameters = array();
+
+               if ( $this->getRequest()->getCheck( 'property' ) ) {
+                       $parameters['property'] = $this->getRequest()->getVal( 
'property' );
+               }
+
+               return $parameters;
+       }
+
+       /**
         * Returns a MessageFormatter object
         *
         * @since  1.9
@@ -55,6 +72,23 @@
        }
 
        /**
+        * Generates a search form
+        *
+        * @since 1.9
+        *
+        * @param string $property
+        *
+        * @return string
+        */
+       public function getSearchForm( $property = '' ) {
+               return  Xml::tags( 'form', array( 'method' => 'get', 'action' 
=> htmlspecialchars( $GLOBALS['wgScript'] ) ),
+                               Html::hidden( 'title', 
$this->getContext()->getTitle()->getPrefixedText() ) .
+                               Xml::fieldset( $this->msg( 'properties' 
)->text(),
+                                       Xml::inputLabel( $this->msg( 
'smw-sp-property-searchform' )->text(), 'property', 'property', 20, $property ) 
. ' ' .
+                                       Xml::submitButton( $this->msg( 
'allpagessubmit' )->text() ) ) );
+       }
+
+       /**
         * This is the actual workhorse. It does everything needed to make a
         * real, honest-to-gosh query page.
         * Alas, we need to overwrite the whole beast since we do not assume
@@ -62,15 +96,21 @@
         *
         * @param $offset database query offset
         * @param $limit database query limit
+        * @param $property database string query
         */
-       function doQuery( $offset = false, $limit = false ) {
-               $out = $this->getOutput();
-               $sk  = $this->getSkin();
+       function doQuery( $offset = false, $limit = false, $property = false ) {
+               $out  = $this->getOutput();
+               $sk   = $this->getSkin();
 
                $options = new SMWRequestOptions();
                $options->limit = $limit;
                $options->offset = $offset;
                $options->sort = true;
+
+               if ( $property ) {
+                       $options->addStringCondition( str_replace( ' ', '_', 
$property ), SMWStringCondition::STRCOND_MID );
+               }
+
                $res = $this->getResults( $options );
                $num = count( $res );
 
diff --git a/languages/SMW_Messages.php b/languages/SMW_Messages.php
index 8f6821b..043d667 100644
--- a/languages/SMW_Messages.php
+++ b/languages/SMW_Messages.php
@@ -189,6 +189,8 @@
        'smw_propertyhardlyused' => 'This property is hardly used within the 
wiki!',
        'smw-property-name-invalid' => 'Property $1 can not be used (invalid 
property name).',
 
+       'smw-sp-property-searchform' => 'Display properties that contain:',
+
        // 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.',
@@ -1016,6 +1018,7 @@
 * $1 - Name of the invoked predefined property',
        'smw-pa-property-predefined_ask' => 'Describes a predefined property.',
        'smw-pa-property-predefined_asksi' => 'Describes a predefined 
property.',
+       'smw-sp-property-searchform' => 'Introductory text for the property 
search form',
 );
 
 /** Afrikaans (Afrikaans)
diff --git a/tests/phpunit/includes/QueryPageTest.php 
b/tests/phpunit/includes/QueryPageTest.php
new file mode 100644
index 0000000..55347df
--- /dev/null
+++ b/tests/phpunit/includes/QueryPageTest.php
@@ -0,0 +1,120 @@
+<?php
+
+namespace SMW\Test;
+
+use RequestContext;
+use FauxRequest;
+
+/**
+ * Tests for the QueryPage 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
+ *
+ * @license GNU GPL v2+
+ * @author mwjames
+ */
+
+/**
+ * @covers \SMWQueryPage
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ */
+class QueryPageTest extends SemanticMediaWikiTestCase {
+
+       /**
+        * Returns the name of the class to be tested
+        *
+        * @return string|false
+        */
+       public function getClass() {
+               return '\SMWQueryPage';
+       }
+
+       /**
+        * Helper method that returns a SMWQueryPage object
+        *
+        * @since 1.9
+        *
+        * @param $result
+        *
+        * @return SMWQueryPage
+        */
+       private function getInstance( $search = '' ) {
+
+               $queryPage = $this->getMockBuilder( $this->getClass() )
+                       ->setMethods( array( 'getResults', 'formatResult' ) )
+                       ->getMock();
+
+               $request = new FauxRequest( array( 'property' => $search ) );
+               $context = new RequestContext();
+               $context->setTitle( $this->getTitle() );
+               $context->setRequest( $request );
+
+               $queryPage->setContext( $context );
+
+               return $queryPage;
+       }
+
+       /**
+        * @test SMWQueryPage::__construct
+        *
+        * @since 1.9
+        */
+       public function testConstructor() {
+               $instance = $this->getInstance();
+               $this->assertInstanceOf( $this->getClass(), $instance );
+       }
+
+       /**
+        * @test SMWQueryPage::linkParameters
+        *
+        * @since 1.9
+        */
+       public function testLinkParameters() {
+
+               $search = $this->getRandomString();
+               $result = $this->getInstance( $search )->linkParameters();
+
+               $this->assertInternalType( 'array', $result );
+               $this->assertEquals( array( 'property' => $search ) , $result );
+       }
+
+       /**
+        * @test SMWQueryPage::getSearchForm
+        *
+        * @since 1.9
+        */
+       public function testGetSearchForm() {
+
+               $search = $this->getRandomString();
+               $result = $this->getInstance()->getSearchForm( $search );
+
+               $matcher = array(
+                       'tag' => 'form',
+                       'descendant' => array( 'tag' => 'input', 'attributes' 
=> array( 'name' => 'property', 'value' => $search ) )
+               );
+
+               $this->assertInternalType( 'string', $result );
+               $this->assertTag( $matcher, $result );
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic008776070bae9e4d2c16223545ae4256546308f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <jamesin.hongkon...@gmail.com>
Gerrit-Reviewer: Mwjames <jamesin.hongkon...@gmail.com>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to