Robert Vogel has uploaded a new change for review.

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


Change subject: Latest version from 'Hallo  Welt! Medienwerkstatt GmbH'. There 
may be newer versions on the webplatform.org webserver
......................................................................

Latest version from 'Hallo  Welt! Medienwerkstatt GmbH'. There may be newer 
versions on the webplatform.org webserver

Change-Id: I542c681d4824b307c7b13b850c1ab2e90b9282d0
---
A WebPlatformSearchAutocomplete.i18n.php
A WebPlatformSearchAutocomplete.php
A includes/WebPlatformSearchAutocompleteHooks.php
A includes/api/ApiWebplatformSearch.php
A resources/ext.webPlatformSearchAutocomplete.core.css
A resources/ext.webPlatformSearchAutocomplete.core.js
6 files changed, 377 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WebPlatformSearchAutocomplete
 refs/changes/01/76101/1

diff --git a/WebPlatformSearchAutocomplete.i18n.php 
b/WebPlatformSearchAutocomplete.i18n.php
new file mode 100644
index 0000000..59e2030
--- /dev/null
+++ b/WebPlatformSearchAutocomplete.i18n.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Internationalization file for the WebPlatformSearchAutocomplete extension.
+ *
+ * @file
+ * @ingroup Extensions
+ */
+
+$messages = array();
+
+/** English
+ * @author Robert Vogel
+ */
+$messages['en'] = array(
+       'webplatformsearchautocomplete-desc' => 'Provides customized 
autocomplete functionality for webplatform.org search',
+);
+
+/** Message documentation (Message documentation)
+ * @author Robert Vogel
+ */
+$messages['qqq'] = array(
+       'webplatformsearchautocomplete-desc' => 'The extensions description'
+);
+
+/** German (Deutsch)
+ * @author Robert Vogel
+ */
+$messages['de'] = array(
+       'webplatformsearchautocomplete-desc' => 'Stellt eine speziell 
angepasste AutoComplete Funktionalität für die Suche von webplatform.org bereit'
+);
\ No newline at end of file
diff --git a/WebPlatformSearchAutocomplete.php 
b/WebPlatformSearchAutocomplete.php
new file mode 100644
index 0000000..fb51372
--- /dev/null
+++ b/WebPlatformSearchAutocomplete.php
@@ -0,0 +1,46 @@
+<?php
+# Alert the user that this is not a valid entry point to MediaWiki if they try 
to access the special pages file directly.
+if (!defined('MEDIAWIKI')) {
+       echo <<<EOT
+To install my extension, put the following line in LocalSettings.php:
+require_once( 
"$IP/extensions/WebPlatformSearchAutocomplete/WebPlatformSearchAutocomplete.php"
 );
+EOT;
+       exit( 1 );
+}
+ 
+$wgExtensionCredits['api'][] = array(
+       'path'           => __FILE__,
+       'name'           => 'WebPlatformSearchAutocomplete',
+       'author'         => '[http://www.hallowelt.biz Hallo Welt! 
Medienwerkstatt GmbH]; Robert Vogel',
+       'url'            => 'http://www.hallowelt.biz',
+       'descriptionmsg' => 'webplatformsearchautocomplete-desc',
+       'version'        => '1.0.0; $Revision: 8194 $',
+);
+
+$dir = dirname(__FILE__) . '/';
+ 
+$wgAutoloadClasses['ApiWebPlatformSearch']   = $dir . 
'includes/api/ApiWebplatformSearch.php';
+$wgAutoloadClasses['WebPlatformSearchAutocompleteHooks']   = $dir . 
'includes/WebPlatformSearchAutocompleteHooks.php';
+$wgExtensionMessagesFiles['WebPlatformSearchAutocomplete'] = $dir . 
'WebPlatformSearchAutocomplete.i18n.php';
+
+$wgAPIModules['webplatformsearch'] = 'ApiWebPlatformSearch';
+
+$wgHooks['BeforePageDisplay'][] = 
'WebPlatformSearchAutocompleteHooks::onBeforePageDisplay';
+$wgHooks['UserGetDefaultOptions'][] = 
'WebPlatformSearchAutocompleteHooks::onUserGetDefaultOptions';
+$wgHooks['UserLoadOptions'][] = 
'WebPlatformSearchAutocompleteHooks::onUserLoadOptions';
+$wgHooks['GetPreferences'][] = 
'WebPlatformSearchAutocompleteHooks::onGetPreferences';
+
+$wgResourceModules['ext.WebPlatformSearchAutocomplete'] = array(
+       'scripts'       => array( 
'resources/ext.webPlatformSearchAutocomplete.core.js' ),
+       'styles'        => array( 
'resources/ext.webPlatformSearchAutocomplete.core.css' ),
+       'messages'      => array( 
+                       'searchsuggest-search',
+                       'searchsuggest-containing',
+       ),
+       'dependencies'  => array(
+               'jquery.ui.autocomplete',
+               'jquery.placeholder'
+       ),
+       'localBasePath' => dirname( __FILE__ ),
+       'remoteExtPath' => 'WebPlatformSearchAutocomplete'
+);
\ No newline at end of file
diff --git a/includes/WebPlatformSearchAutocompleteHooks.php 
b/includes/WebPlatformSearchAutocompleteHooks.php
new file mode 100644
index 0000000..c8fbc0a
--- /dev/null
+++ b/includes/WebPlatformSearchAutocompleteHooks.php
@@ -0,0 +1,48 @@
+<?php
+
+class WebPlatformSearchAutocompleteHooks {
+       /**
+        * 
+        * @param OutputPage $out
+        * @param SkinTemplate $skin
+        * @return bool Always true to keep hook running
+        */
+       public static function onBeforePageDisplay( &$out, &$skin ) {
+               if( $out->getUser()->getOption( 'wpddisablesuggest', false ) ) 
return true;
+               $out->addModules( 'ext.WebPlatformSearchAutocomplete' );
+               return true;
+       }
+
+       /**
+        * 
+        * @param array $defaultOptions
+        * @return boolean
+        */
+       public static function onUserGetDefaultOptions( &$defaultOptions ) {
+               $defaultOptions['disablesuggest'] = true;
+               return true;
+       }
+       
+       /**
+        * 
+        * @param type $user
+        * @param array $options
+        * @return boolean
+        */
+       public static function onUserLoadOptions( $user, &$options ) {
+               $options['disablesuggest'] = true;
+               return true;
+       }
+       
+       /**
+        * 
+        * @param type $user
+        * @param type $preferences
+        * @return boolean
+        */
+       public static function onGetPreferences( $user, &$preferences ) {
+               $preferences['wpddisablesuggest'] = 
$preferences['disablesuggest'];
+               unset($preferences['disablesuggest']);
+               return true;
+       }
+}
\ No newline at end of file
diff --git a/includes/api/ApiWebplatformSearch.php 
b/includes/api/ApiWebplatformSearch.php
new file mode 100644
index 0000000..4083d7e
--- /dev/null
+++ b/includes/api/ApiWebplatformSearch.php
@@ -0,0 +1,114 @@
+<?php
+/**
+ *
+ *
+ * Created on Sep 17, 2012
+ *
+ * API module for MediaWiki's WebPlatformSearchAutocomplete extension
+ *
+ * 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
+ *
+ * @file
+ */
+
+/**
+ * @ingroup WebPlatformSearchAutocomplete
+ */
+class ApiWebPlatformSearch extends ApiBase {
+
+       public function __construct( $main, $action ) {
+               parent::__construct( $main, $action );
+       }
+
+       public function getCustomPrinter() {
+               return $this->getMain()->createPrinterByName( 'json' );
+       }
+
+       public function execute() {
+               global $wgSearchSuggestCacheExpiry, 
$wgWebPlatformSearchAutocompleteSearchCategories;
+               $params = $this->extractRequestParams();
+
+               $search = $params['term'];
+               $hits   = array();
+
+               // Open search results may be stored for a very long time
+               $this->getMain()->setCacheMaxAge( $wgSearchSuggestCacheExpiry );
+               $this->getMain()->setCacheMode( 'public' );
+               
+               $db = $this->getDB( DB_SLAVE );
+               $res = $db->select(
+                       'page',
+                       'page_title',
+                       array(
+                               'page_namespace' => NS_MAIN,
+                               'page_title'.$db->buildLike(
+                                       $db->anyString(),
+                                       /*'/'.*/$search,
+                                       $db->anyString()
+                               ),
+                               'page_is_redirect' => 0,
+                       ),
+                       __METHOD__,
+                       array(
+                               'LIMIT' => 50,
+                               'ORDER BY' => 'page_title'
+                       )
+               );
+
+               foreach( $res as $row ) {
+                       $titleParts = explode( '/', $row->page_title );
+                       $hit = new stdClass();
+                       $hit->label = str_replace( '_', ' ', basename( 
$row->page_title ) );
+                       $hit->fullTitle = $row->page_title;
+                       $hit->category = str_replace( '_', ' ', strtoupper( 
$titleParts[0] ) );
+                       $hits[] = $hit;
+               }
+
+               // Set top level elements
+               $result = $this->getResult();
+               $result->addValue( null, 'result', $hits );
+       }
+
+       public function getAllowedParams() {
+               return array(
+                       'term' => null,
+               );
+       }
+
+       public function getParamDescription() {
+               return array(
+                       'term' => 'Search string'
+               );
+       }
+
+       public function getDescription() {
+               return 'Search the webplatform.org wiki';
+       }
+
+       public function getExamples() {
+               return array(
+                       'api.php?action=webplatformsearch&term=Te'
+               );
+       }
+
+       public function getHelpUrls() {
+               return 'https://www.webplatform.org';
+       }
+
+       public function getVersion() {
+               return __CLASS__ . ': $Id: ApiWebplatformSearch.php 8232 
2013-01-18 13:14:32Z rvogel $';
+       }
+}
diff --git a/resources/ext.webPlatformSearchAutocomplete.core.css 
b/resources/ext.webPlatformSearchAutocomplete.core.css
new file mode 100644
index 0000000..e43d4d4
--- /dev/null
+++ b/resources/ext.webPlatformSearchAutocomplete.core.css
@@ -0,0 +1,56 @@
+/*HINT: 
jquery-ui-1.8.24/development-bundle/demos/index.html#autocomplete|categories*/
+.ui-autocomplete-category {
+       font-weight: bold;
+       padding: 3px 5px;
+       margin: 5px 0 3px 0;
+       line-height: 1.5;
+       float: left;
+       width: 100%;
+       color: white;
+}
+
+.ui-autocomplete-category:first-child {
+       margin-top: 0px;
+}
+
+.ui-autocomplete {
+       max-height: 400px;
+       width: 350px;
+       overflow-y: auto;
+       /* prevent horizontal scrollbar */
+       overflow-x: hidden;
+       /* add padding to account for vertical scrollbar */
+       padding-right: 20px;
+}
+/* IE 6 doesn't support max-height
+ * we use height instead, but this forces the menu to always be this tall
+ */
+* html .ui-autocomplete {
+       height: 400px;
+}
+
+.ui-autocomplete-result-current {
+       margin-top: 10px;
+       border-top: 1px solid;
+       padding-top: 2px;
+}
+
+
+.ui-widget-content {
+       background: #fff;
+}
+
+.ui-menu {
+       padding: 0px  10px 0 0 
+}
+
+.ui-menu-item {
+       cursor: pointer;
+}
+
+.ui-state-hover {
+       background: #fcfcfc !important;
+       border: none !important;
+       font-weight: bold !important;
+       margin: 0 !important;
+}
\ No newline at end of file
diff --git a/resources/ext.webPlatformSearchAutocomplete.core.js 
b/resources/ext.webPlatformSearchAutocomplete.core.js
new file mode 100644
index 0000000..342ba09
--- /dev/null
+++ b/resources/ext.webPlatformSearchAutocomplete.core.js
@@ -0,0 +1,83 @@
+/**
+ * WebPlatformSearchAutocomplete JS
+ * @author Robert Vogel
+ */
+
+(function( $, undefined ) {
+       $.widget( "wpd.catcomplete", $.ui.autocomplete, {
+               _renderMenu: function( ul, items ) {
+                       var self = this,
+                               currentCategory = "",
+                               currentCategoryColor = 0,
+                               categoryColors = [ '#f19620', '#d24839', 
'#654d97', '#31b0bc' ];
+
+                       $.each( items, function( index, item ) {
+                               if ( item.category != currentCategory ) {
+                                       if( currentCategoryColor >= 
categoryColors.length ) {
+                                               currentCategoryColor = 0;
+                                       }
+                                       $( "<li></li>" )
+                                               
.addClass('ui-autocomplete-category')
+                                               .css( 'background-color', 
categoryColors[currentCategoryColor] )
+                                               .data( "item.autocomplete", 
item )
+                                               .text( item.category )
+                                               .appendTo( ul );
+
+                                       currentCategory = item.category;
+                                       currentCategoryColor++;
+                               }
+                               self._renderItem( ul, item );
+                       });
+
+                       $( "<li><a>"+mw.msg( 'searchsuggest-containing' 
)+"<br/><em>" + self.element.val() + "</em></a></li>" )
+                               .addClass('ui-autocomplete-result-current')
+                               .data( "item.autocomplete", { value: 
this.element.val() } )
+                               .appendTo( ul );
+               }
+       });
+}(jQuery));
+       
+( function( mw, $ ) {
+       var searchApiUrl = mw.util.wikiScript( 'api' ) + '?' + $.param({ 
format: 'json', action: 'webplatformsearch' });
+       $( "#searchInput" ).catcomplete({
+               delay: 100,
+               minLength: 3,
+               source: function( request, response ) {
+                       if ( this.xhr ) {
+                               this.xhr.abort();
+                       }
+                       this.xhr = $.ajax({
+                               url: searchApiUrl,
+                               data:{
+                                       term: request.term
+                               },
+                               dataType: "json",
+                               success: function( data, status ) {
+                                       response( data.result );
+                               },
+                               error: function() {
+                                       response( [] );
+                               }
+                       });
+               },
+               position: {
+                       my: "right top",
+                       at: "right bottom"
+               },
+               select: function(event, ui) {
+                       if( ui.item.fullTitle ) {
+                               event.preventDefault();
+                               window.location.href = mw.util.wikiGetlink( 
ui.item.fullTitle );
+                               return;
+                       }
+                       
+                       if( ui.item.value ) { //"contains..."-menu item
+                               $(this).parents('form').submit();
+                               return;
+                       }
+               }
+       })
+       .attr( 'placeholder', mw.msg( 'searchsuggest-search' ) )
+       .placeholder();
+
+}( mediaWiki, jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I542c681d4824b307c7b13b850c1ab2e90b9282d0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WebPlatformSearchAutocomplete
Gerrit-Branch: master
Gerrit-Owner: Robert Vogel <[email protected]>

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

Reply via email to