Smuggli has uploaded a new change for review.

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

Change subject: Fixed some facet issues
......................................................................

Fixed some facet issues

- In some rare cases facetting could faild because of an defective check
- Removed onchange attr because it is not needed
- Code improvements
- Added documentation

Change-Id: Ib71b3650aed8ed5d76fd01ecf49ca4a63315f230
---
M ExtendedSearch/ExtendedSearch.class.php
M ExtendedSearch/includes/ExtendedSearchBase.class.php
M ExtendedSearch/includes/SearchIndex/SearchOptions.class.php
M ExtendedSearch/includes/SearchIndex/SearchRequest.class.php
M ExtendedSearch/includes/SearchIndex/SearchResult.class.php
M ExtendedSearch/resources/bluespice.extendedSearch.specialpage.js
M ExtendedSearch/views/view.ExtendedSearchFacetBox.php
7 files changed, 78 insertions(+), 67 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/BlueSpiceExtensions 
refs/changes/79/158379/1

diff --git a/ExtendedSearch/ExtendedSearch.class.php 
b/ExtendedSearch/ExtendedSearch.class.php
index 182bbbc..887fe9e 100644
--- a/ExtendedSearch/ExtendedSearch.class.php
+++ b/ExtendedSearch/ExtendedSearch.class.php
@@ -52,16 +52,6 @@
 class ExtendedSearch extends BsExtensionMW {
 
        /**
-        * Instance of BsExtendedSearchBase
-        * @var Object
-        */
-       protected $oExtendedSearchBase = null;
-       /**
-        * Instance of BuildIndexMainControl
-        * @var Object
-        */
-       protected $oBuildIndexMainControl = null;
-       /**
         * Unique wiki id
         */
        private $sWikiID = '';
@@ -148,9 +138,6 @@
                $this->setHook( 'BSDashboardsAdminDashboardPortalPortlets' );
                $this->setHook( 'SkinTemplateOutputPageBeforeExec' );
 
-               $this->oExtendedSearchBase = ExtendedSearchBase::getInstance( 
$this );
-               $this->oBuildIndexMainControl = 
BuildIndexMainControl::getInstance();
-
                $this->mCore->registerPermission( 'searchfiles', array( 'user' 
) );
 
                wfProfileOut( 'BS::'.__METHOD__ );
@@ -205,7 +192,7 @@
                $oWidgetView
                        ->setId( 'bs-extendedsearch-mlt' )
                        ->setTitle( wfMessage( 'bs-extendedsearch-morelikethis' 
)->plain() )
-                       ->setBody( 
$this->oExtendedSearchBase->getViewMoreLikeThis( $oTitle )->execute() )
+                       ->setBody( ExtendedSearchBase::getInstance( $this 
)->getViewMoreLikeThis( $oTitle )->execute() )
                        ->setTooltip( wfMessage( 
'bs-extendedsearch-morelikethis' )->plain() )
                        ->setAdditionalBodyClasses( array( 'bs-nav-links', 
'bs-extendedsearch-portlet' ) ); //For correct margin and fontsize
 
@@ -235,7 +222,7 @@
                $oMltListView = new ViewStateBarBodyElement();
                $oMltListView->setKey( 'MoreLikeThis' );
                $oMltListView->setHeading( wfMessage( 
'bs-extendedsearch-morelikethis' )->plain() );
-               $oMltListView->setBodyText( 
$this->oExtendedSearchBase->getViewMoreLikeThis( $oTitle )->execute() );
+               $oMltListView->setBodyText( ExtendedSearchBase::getInstance( 
$this )->getViewMoreLikeThis( $oTitle )->execute() );
 
                $aBodyViews['statebarbodymorelikethis'] = $oMltListView;
                return true;
@@ -366,7 +353,7 @@
         */
        public function onArticleDeleteComplete( &$oArticle, &$oUser, $sReason, 
$iID ) {
                try {
-                       $this->oBuildIndexMainControl->deleteFromIndexWiki( 
$iID );
+                       
BuildIndexMainControl::getInstance()->deleteFromIndexWiki( $iID );
                } catch ( BsException $e ) {
                        wfDebugLog( 'ExtendedSearch', 'onArticleDeleteComplete: 
'.$e->getMessage() );
                }
@@ -382,7 +369,7 @@
         */
        public function onArticleSaveComplete( &$oArticle, &$oUser ) {
                try {
-                       $this->oBuildIndexMainControl->updateIndexWiki( 
$oArticle );
+                       BuildIndexMainControl::getInstance()->updateIndexWiki( 
$oArticle );
                } catch ( BsException $e ) {
                        wfDebugLog( 'ExtendedSearch', 'onArticleSaveComplete: 
'.$e->getMessage() );
                }
@@ -397,7 +384,7 @@
         */
        public function onArticleUndelete( $oTitle, $bCreate ) {
                try {
-                       
$this->oBuildIndexMainControl->updateIndexWikiByTitleObject( $oTitle );
+                       
BuildIndexMainControl::getInstance()->updateIndexWikiByTitleObject( $oTitle );
                } catch ( BsException $e ) {
                        wfDebugLog( 'ExtendedSearch', 'onArticleUndelete: 
'.$e->getMessage() );
                }
@@ -416,18 +403,18 @@
        public function onTitleMoveComplete( &$oTitle, &$oNewtitle, &$oUser, 
$iOldID, $iNewID ) {
                try {
                        // Moving article
-                       
$this->oBuildIndexMainControl->updateIndexWikiByTitleObject( $oNewtitle );
+                       
BuildIndexMainControl::getInstance()->updateIndexWikiByTitleObject( $oNewtitle 
);
                        // Check if redirect is created; 0 is no redirect
                        if ( $iNewID !== 0 ) {
-                               
$this->oBuildIndexMainControl->updateIndexWikiByTitleObject( $oTitle );
+                               
BuildIndexMainControl::getInstance()->updateIndexWikiByTitleObject( $oTitle );
                        }
                        // Moving file if namespace of title is the file 
namespace
                        if ( $oTitle->getNamespace() == NS_FILE ) {
                                $oOldFile = LocalFile::newFromTitle( $oTitle, 
RepoGroup::singleton()->getLocalRepo() );
                                $oNewFile = RepoGroup::singleton()->findFile( 
$oNewtitle );
 
-                               $this->oBuildIndexMainControl->deleteIndexFile( 
$oOldFile->getPath(), 'repo' );
-                               $this->oBuildIndexMainControl->updateIndexFile( 
$oNewFile );
+                               
BuildIndexMainControl::getInstance()->deleteIndexFile( $oOldFile->getPath(), 
'repo' );
+                               
BuildIndexMainControl::getInstance()->updateIndexFile( $oNewFile );
                        }
                } catch ( BsException $e ) {
                        wfDebugLog( 'ExtendedSearch', 'onTitleMoveComplete: 
'.$e->getMessage() );
@@ -444,7 +431,7 @@
         */
        public function onFileUpload( $oFile, $bReupload = false, 
$bHasDescription = false ) {
                try {
-                       $this->oBuildIndexMainControl->updateIndexFile( $oFile 
);
+                       BuildIndexMainControl::getInstance()->updateIndexFile( 
$oFile );
                } catch ( BsException $e ) {
                        wfDebugLog( 'ExtendedSearch', 'onFileUpload: 
'.$e->getMessage() );
                }
@@ -462,7 +449,7 @@
         */
        public function onFileDeleteComplete( $oFile, $oOldimage, $oArticle, 
$oUser, $sReason ) {
                try {
-                       $this->oBuildIndexMainControl->deleteIndexFile( 
$oFile->getPath(), 'repo' );
+                       BuildIndexMainControl::getInstance()->deleteIndexFile( 
$oFile->getPath(), 'repo' );
                } catch ( BsException $e ) {
                        wfDebugLog( 'ExtendedSearch', 'onFileDeleteComplete: 
'.$e->getMessage() );
                }
@@ -480,7 +467,7 @@
        public function onFileUndeleteComplete( $oTitle, $aFileVersions, 
$oUser, $sReason ) {
                try {
                        $oFile = wfFindFile( $oTitle );
-                       $this->oBuildIndexMainControl->updateIndexFile( $oFile 
);
+                       BuildIndexMainControl::getInstance()->updateIndexFile( 
$oFile );
                } catch ( BsException $e ) {
                        wfDebugLog( 'ExtendedSearch', 'onFileUndeleteComplete: 
'.$e->getMessage() );
                }
diff --git a/ExtendedSearch/includes/ExtendedSearchBase.class.php 
b/ExtendedSearch/includes/ExtendedSearchBase.class.php
index 096e79d..2177a0b 100644
--- a/ExtendedSearch/includes/ExtendedSearchBase.class.php
+++ b/ExtendedSearch/includes/ExtendedSearchBase.class.php
@@ -116,6 +116,7 @@
         * @return ViewBaseElement View with inner content of search result 
page.
         */
        public function renderSpecialpage() {
+               $this->oSearchRequest->init();
                $this->oSearchOptions->readInSearchRequest();
                $this->oSearchUriBuilder->init();
 
@@ -148,6 +149,7 @@
 
        public function getResults( $bAjax ) {
                if ( $bAjax === true ) {
+                       $this->oSearchRequest->init();
                        $this->oSearchOptions->readInSearchRequest();
                        $this->oSearchUriBuilder->init();
                }
@@ -355,6 +357,7 @@
 
                $oSerachService = SearchService::getInstance();
                $oSearchRequest = new SearchRequest();
+               $oSearchRequest->init();
                $oSearchOptions = new SearchOptions( $oSearchRequest, 
RequestContext::getMain() );
                $oSearchOptions->readInSearchRequest();
 
diff --git a/ExtendedSearch/includes/SearchIndex/SearchOptions.class.php 
b/ExtendedSearch/includes/SearchIndex/SearchOptions.class.php
index c5afe1e..3b03bb9 100644
--- a/ExtendedSearch/includes/SearchIndex/SearchOptions.class.php
+++ b/ExtendedSearch/includes/SearchIndex/SearchOptions.class.php
@@ -239,7 +239,7 @@
        }
 
        /**
-        * Creates an array that can be used as a autocomplete search query to 
Solr.
+        * Creates an array that can be used as a more like this search query 
to Solr.
         * @return array List of url parameters.
         */
        public function getSolrMltQuery( $oTitle ) {
@@ -287,7 +287,7 @@
        }
 
        /**
-        * Retrieves parameters from defaults and search options.
+        * Processes incoming search request
         */
        public function readInSearchRequest() {
                $this->aOptions['searchStringRaw'] = 
$this->oSearchRequest->sInput;
@@ -393,18 +393,14 @@
                                        $aTmp = array();
                                        foreach ( $aNamespaces as $iNs ) {
                                                if ( 
BsNamespaceHelper::checkNamespacePermission( $iNs, 'read' ) === true ) {
-                                                       $aTmp[] = $iNs;
+                                                       
$this->aOptions['namespaces'][] = $iNs;
                                                }
-                                       }
-
-                                       if ( !empty( $aTmp ) ) {
-                                               $this->aOptions['namespaces'] = 
array_diff( $this->aOptions['namespaces'], $aTmp );
                                        }
                                } else {
                                        $bTagNamespace = true;
                                        $aTmp = array();
                                        foreach ( $this->aOptions['namespaces'] 
as $iNs ) {
-                                               if ( 
BsNamespaceHelper::checkNamespacePermission( $iNs, 'read' ) === true ) {
+                                               if ( 
!BsNamespaceHelper::checkNamespacePermission( $iNs, 'read' ) ) {
                                                        $aTmp[] = $iNs;
                                                }
                                        }
diff --git a/ExtendedSearch/includes/SearchIndex/SearchRequest.class.php 
b/ExtendedSearch/includes/SearchIndex/SearchRequest.class.php
index 52ede6a..dc1bba8 100644
--- a/ExtendedSearch/includes/SearchIndex/SearchRequest.class.php
+++ b/ExtendedSearch/includes/SearchIndex/SearchRequest.class.php
@@ -42,9 +42,6 @@
        public function __construct() {
                wfProfileIn( 'BS::'.__METHOD__ );
                $this->oRequest = RequestContext::getMain()->getRequest();
-               $this->setDefaults();
-               $this->processSettings();
-               $this->processInputs();
                wfProfileOut( 'BS::'.__METHOD__ );
        }
 
@@ -62,6 +59,12 @@
                return self::$oInstance;
        }
 
+       public function init() {
+               $this->setDefaults();
+               $this->processSettings();
+               $this->processInputs();
+       }
+
        /**
         * Sets the defaults for a search request.
         */
diff --git a/ExtendedSearch/includes/SearchIndex/SearchResult.class.php 
b/ExtendedSearch/includes/SearchIndex/SearchResult.class.php
index a4a49a6..2ab2499 100644
--- a/ExtendedSearch/includes/SearchIndex/SearchResult.class.php
+++ b/ExtendedSearch/includes/SearchIndex/SearchResult.class.php
@@ -76,9 +76,16 @@
                return $this->aData[$sKey];
        }
 
+       /**
+        * Creates a search result view
+        * @param array $aMonitor reference of Monitor array from special page
+        * @param int $iResults number of results
+        * @param bool $bFuzzy whether it is a fuzzy query or not
+        * @param bool $bFacet whether facets should be added or not
+        * @return object search result view
+        */
        public function createSearchResult( &$aMonitor, $iResults, $bFuzzy, 
$bFacet ) {
                $this->vSearchResult = new ViewSearchResult();
-               $this->vSearchResult->setOption( 'siteUri', 
$this->oSearchUriBuilder->buildUri( SearchUriBuilder::ALL, 
SearchUriBuilder::MLT ) );
 
                if ( $bFuzzy && isset( $this->aData['spell'] ) ) {
                        $this->vSearchResult->addSpell( $this->aData['spell'] );
@@ -98,19 +105,23 @@
 
                if ( $iResults == 0 ) return $this->vSearchResult;
 
-               $this->prepareNavigation( $iResults );
+               $this->createNavigation( $iResults );
 
                if ( $bFacet ) {
                        $this->vSearchResult->setOption( 'showfacets' , $bFacet 
);
-                       $this->prepareFacets();
+                       $this->createFacets();
                }
 
-               $this->prepareResults();
+               $this->createResults();
 
                return $this->vSearchResult;
        }
 
-       private function prepareNavigation( $iResults ) {
+       /**
+        * Creates the navigation
+        * @param int $iResults number of results found
+        */
+       private function createNavigation( $iResults ) {
                $aPaging = array();
                $sSearchLimit = $this->oSearchOptions->getOption( 'searchLimit' 
);
 
@@ -153,7 +164,12 @@
                $this->vSearchResult->setOption( 'sorting', $aSorting );
        }
 
-       private function prepareFacets() {
+       /**
+        * Creates the facets
+        */
+       private function createFacets() {
+               $sSiteUri = $this->oSearchUriBuilder->buildUri( 
SearchUriBuilder::ALL, SearchUriBuilder::MLT );
+
                // possible orders: count, name, checked
                // possible directions: 1 = desc, -1 = asc
                $aOrder = ( BsConfig::get( 'MW::SortAlph' ) )
@@ -206,7 +222,13 @@
                        if ( !is_null( 
$this->oResponse->facet_counts->facet_fields->{$sFacet} ) ) {
                                $oFacet->setOption( 'title', $aConfig['i18n'] );
 
-                               $aFacets = array(); // alters to: array( 0 => 
array( 'checked' => true ), 1 => array( 'count' => 15 ), 999 => array( 
'checked' => true, 'count' => 2 ) )
+                               /* alters to:
+                                * array(
+                                *     0 => array( 'checked' => true ),
+                                *     1 => array( 'count' => 15 ),
+                                *     999 => array( 'checked' => true, 'count' 
=> 2 )
+                                * )*/
+                               $aFacets = array();
                                $aData = $this->oSearchOptions->getOption( 
$aConfig['option'] );
 
                                if ( !empty( $aData ) ) {
@@ -216,6 +238,7 @@
                                        unset( $aData );
                                }
 
+                               // Get all available facets
                                $aFacetsInRespsonse = 
$this->oResponse->facet_counts->facet_fields->{$sFacet};
                                foreach ( $aFacetsInRespsonse as $key => $count 
) {
                                        if ( $key == '_empty_' ) continue;
@@ -233,6 +256,7 @@
                                        $aFacets[$key]['count'] = $count;
                                }
 
+                               // Prepare availabel facets. Add some 
information for each facet
                                foreach ( $aFacets as $key => $attributes ) {
                                        if ( !isset( $aFacets[$key]['count'] ) 
) {
                                                unset( $aFacets[$key] );
@@ -314,25 +338,28 @@
                                if ( $sFacet === 'namespace' ) {
                                        $aReqNs = 
$this->oSearchOptions->getOption( 'namespaces' );
                                        foreach ( $aReqNs as $ikey => $value ) {
-                                               if ( !in_array( $value, 
$aFacets ) ){
+                                               if ( !array_key_exists( $value, 
$aFacets ) ){
                                                        $aFacetAll[] = 
"{$aConfig['param']}[]=".$value;
+                                                       $sSiteUri = 
str_replace( "&{$aConfig['param']}[]=$value", '', $sSiteUri );
                                                }
                                        }
                                }
 
                                $sFacetAll = implode( '&', $aFacetAll );
-                               $oFacet->setOption( 'uri-facet-delete', 
$aConfig['url'].'&nosel=1' );
-                               $oFacet->setOption(
-                                       'uri-facet-all',
-                                       $this->oSearchUriBuilder->buildUri( 
$aConfig['url'] ).'&'.$sFacetAll );
                                $oFacet->setOption( 'uri-facet-all-diff', 
$sFacetAll );
                        }
 
                        $this->vSearchResult->setFacet( $oFacet );
                }
+
+               $this->vSearchResult->setOption( 'siteUri', $sSiteUri );
        }
 
-       private function prepareResults() {
+       /**
+        * Creates the results
+        * @global type $wgScriptPath
+        */
+       private function createResults() {
                global $wgScriptPath;
                $sImgPath = $wgScriptPath . 
'/extensions/BlueSpiceExtensions/ExtendedSearch/resources/images';
 
diff --git a/ExtendedSearch/resources/bluespice.extendedSearch.specialpage.js 
b/ExtendedSearch/resources/bluespice.extendedSearch.specialpage.js
index 16d142a..7dddd64 100644
--- a/ExtendedSearch/resources/bluespice.extendedSearch.specialpage.js
+++ b/ExtendedSearch/resources/bluespice.extendedSearch.specialpage.js
@@ -203,7 +203,7 @@
                }
 
                // facets armed with attribute urldiff...
-               $( '[urldiff]' ).removeAttr( 'onchange' ).click( function() {
+               $( '[urldiff]' ).click( function() {
                        ExtendedSearchAjaxManager.changeRequestFacets( $( this 
).attr( 'urldiff' ), $( this ).attr( 'checked' ) );
                });
 
@@ -227,6 +227,7 @@
                var length = aAllParams.length;
                var urlParams = urldiff;
                var hash = document.location.hash;
+
                for ( var i = 0; i < length; i++ ) {
                        aKeyValue = aAllParams[i].split( '=' );
                        if ( i != length && document.location.hash != '' ) {
diff --git a/ExtendedSearch/views/view.ExtendedSearchFacetBox.php 
b/ExtendedSearch/views/view.ExtendedSearchFacetBox.php
index ed8357d..340e85b 100644
--- a/ExtendedSearch/views/view.ExtendedSearchFacetBox.php
+++ b/ExtendedSearch/views/view.ExtendedSearchFacetBox.php
@@ -69,7 +69,7 @@
         */
        public function setTemplate( $template ) {
                $out = '<div class="facetBarEntry" title="{title}">';
-               $out .= '<input type="checkbox"{checked} 
onchange="document.location=\'{uri}\';"{diff} class="searchcheckbox" />';
+               $out .= '<input type="checkbox"{checked} {diff} 
class="searchcheckbox" />';
                $out .= '<label>{name-and-count}</label>';
                $out .= '</div>';
                parent::setTemplate( $out );
@@ -80,23 +80,17 @@
         * @return string HTML output
         */
        public function execute( $params = false ) {
-               $this->setTemplate('');
-               $titleBar = '<div class="bs-facet-title 
bs-extendedsearch-default-textspacing">';
-               if ( $this->iEntriesChecked > 0 ) {
-                       $checked = ' checked="checked"';
-                       $uri = $this->getOption( 'uri-facet-delete' );
-               } else {
-                       $checked = '';
-                       $uri = $this->getOption( 'uri-facet-all' );
-               }
+               $this->setTemplate( '' );
 
-               $onchange = htmlspecialchars( $uri, ENT_QUOTES, 'UTF-8' );
-               $titleBar .= '<input type="checkbox"' . $checked .
-                               " onchange=\"document.location='{$onchange}'\"" 
.
-                               ' urldiff="'.$this->getOption( 
'uri-facet-all-diff' ).'"></input>';
+               $bChecked = ( $this->iEntriesChecked > 0 )
+                       ? true
+                       : false;
 
-               $titleBar .= '<label>' . wfMessage( $this->getOption( 'title' ) 
)->plain(). '</label>';
-               $titleBar .= '</div>';
+               $sFacetHead = '<div class="bs-facet-title 
bs-extendedsearch-default-textspacing">';
+               $sFacetHead .= Xml::check( '', $bChecked, array( 'urldiff' => 
$this->getOption( 'uri-facet-all-diff' ) ) );
+               $sFacetHead .= '<label>' . wfMessage( $this->getOption( 'title' 
) )->plain(). '</label>';
+               $sFacetHead .= '</div>';
+
                $this->addCompleteDataset( $this->aEntriesChecked );
                $body = parent::execute();
 
@@ -118,7 +112,7 @@
                                $body .
                                Xml::closeElement( 'div' );
 
-               return $titleBar.$body;
+               return $sFacetHead.$body;
        }
 
 }
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib71b3650aed8ed5d76fd01ecf49ca4a63315f230
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Smuggli <mug...@hallowelt.biz>

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

Reply via email to