http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90038

Revision: 90038
Author:   freakolowsky
Date:     2011-06-14 07:46:21 +0000 (Tue, 14 Jun 2011)
Log Message:
-----------
* Initial commit

Added Paths:
-----------
    trunk/extensions/OracleTextSearch/OracleTextSearch.i18n.php
    trunk/extensions/OracleTextSearch/OracleTextSearch.php
    trunk/extensions/OracleTextSearch/SearchOracleText.php
    trunk/extensions/OracleTextSearch/maintainenceFixOTSLinks.php
    trunk/extensions/OracleTextSearch/patch_searchindex_si_url.sql

Added: trunk/extensions/OracleTextSearch/OracleTextSearch.i18n.php
===================================================================
--- trunk/extensions/OracleTextSearch/OracleTextSearch.i18n.php                 
        (rev 0)
+++ trunk/extensions/OracleTextSearch/OracleTextSearch.i18n.php 2011-06-14 
07:46:21 UTC (rev 90038)
@@ -0,0 +1,7 @@
+<?php
+$messages = array();
+ 
+$messages['en'] = array( 
+       'oracletextsearch' => 'OracleTextSearch',
+       'oracletextsearch-desc' => 'Search content/metadata of uploaded files 
using Oracle Text indexing.',
+);


Property changes on: trunk/extensions/OracleTextSearch/OracleTextSearch.i18n.php
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/extensions/OracleTextSearch/OracleTextSearch.php
===================================================================
--- trunk/extensions/OracleTextSearch/OracleTextSearch.php                      
        (rev 0)
+++ trunk/extensions/OracleTextSearch/OracleTextSearch.php      2011-06-14 
07:46:21 UTC (rev 90038)
@@ -0,0 +1,41 @@
+<?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 this extension put the following line in LocalSettings.php:
+require_once( "\$IP/extensions/OracleTextSearch/OracleTextSearch.php" );
+EOT;
+        exit( 1 );
+}
+$wgExtensionCredits['other'][] = array(
+       'name' => 'OracleTextSearch',
+       'author' => 'freakolowsky [Jure Kajzer]',
+       'url' => 'http://www.mediawiki.org/wiki/Extension:OracleTextSearch',
+       'description' => 'Show SQL data directly in the page contents..',
+       'descriptionmsg' => 'oracletextsearch-desc',
+       'version' => '1.0.0',
+);
+
+$dir = dirname(__FILE__) . '/';
+$wgAutoloadClasses['SearchOracleText'] = $dir . 'SearchOracleText.php';
+$wgHooks['UploadComplete'][] = 'SearchOracleText::onUploadCompleteHook';
+
+/**
+ * extension defaults
+ */
+
+/**
+ * index on http (false requires you to setup credentials wallet in oracle)
+ */
+$wgExIndexOnHTTP = true;
+/**
+ * default set of mime types Oracle Text will index (set according to DB 
version)
+ */
+$wgExIndexMIMETypes = array(   'application/pdf', 
+                                                               
'application/xml', 
+                                                               'text/xml', 
+                                                               
'application/msword' , 
+                                                               'text/plain', 
+                                                               'text/html' );
+
+


Property changes on: trunk/extensions/OracleTextSearch/OracleTextSearch.php
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/extensions/OracleTextSearch/SearchOracleText.php
===================================================================
--- trunk/extensions/OracleTextSearch/SearchOracleText.php                      
        (rev 0)
+++ trunk/extensions/OracleTextSearch/SearchOracleText.php      2011-06-14 
07:46:21 UTC (rev 90038)
@@ -0,0 +1,55 @@
+<?php
+
+class SearchOracleText extends SearchOracle {
+
+
+       public function update( $id, $title, $text ) {
+               global $wgExIndexMIMETypes;
+
+               parent::update( $id, $title, $text );
+
+               $titleObj = Title::newFromID( $id );
+               $file = wfLocalFile( $titleObj->getText() );
+               if ( in_array( $file->getMimeType(), $wgExIndexMIMETypes ) ) {
+                       $dbw = wfGetDB(DB_MASTER);
+                       //$dbw->query("CALL 
CTXSYS.CTX_OUTPUT.START_LOG('wiki_ctx.log')"); //use for INTERNAL debuging 
ONLY!!!
+                       
+                       $url = $wgExIndexOnHTTP ? preg_replace( '/^https:/i', 
'http:', $file->getFullUrl() ) : $file->getFullUrl();
+                       $dbw->update('searchindex',
+                               array( 'si_url' => $url ), 
+                               array( 'si_page' => $id ),
+                               'SearchIndexUpdate:update' );
+                       wfDebugLog( 'OracleTextSearch', 'Updated si_url for 
page ' . $id );
+                       
+                       $index = $dbw->getProperty('mTablePrefix')."si_url_idx";
+                       $dbw->query( "CALL ctx_ddl.sync_index('$index')" );
+                       wfDebugLog( 'OracleTextSearch', 'Synced index: 
'.$index);
+               }
+       }
+
+       function parseQuery( $filteredText, $fulltext ) {
+               $match = parent::parseQuery( $filteredText, $fulltext );
+               
+               if ( $fulltext ) {
+                       $field = $this->getIndexField($fulltext);
+                       $searchon = preg_replace( "/ CONTAINS\($field, ('.*'), 
1\) > 0 /", "\\1", $match);
+                       $match = "($match OR CONTAINS(si_url, $searchon, 2) > 
0) ";
+               }
+
+               wfDebugLog( 'OracleTextSearch', 'Matching: '.$match );
+               return $match;
+       }
+
+       public static function onUploadCompleteHook( &$file ) {
+               global $wgExIndexMIMETypes;
+
+               $localFile = $file->getLocalFile();
+               if ( $localFile !=  null && in_array( 
$localFile->getMimeType(), $wgExIndexMIMETypes ) ) {
+                       wfDebugLog( 'OracleTextSearch', 'Touching file page to 
force indexing');
+                       $article = new Article( $localFile->getTitle() );
+                       $article->loadContent();
+                       $article->doEdit( $article->mContent, 
$article->mComment );
+               }
+               return true;
+       }
+}


Property changes on: trunk/extensions/OracleTextSearch/SearchOracleText.php
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/extensions/OracleTextSearch/maintainenceFixOTSLinks.php
===================================================================
--- trunk/extensions/OracleTextSearch/maintainenceFixOTSLinks.php               
                (rev 0)
+++ trunk/extensions/OracleTextSearch/maintainenceFixOTSLinks.php       
2011-06-14 07:46:21 UTC (rev 90038)
@@ -0,0 +1,66 @@
+<?php
+/* run this script out of your $IP/maintenance folder */
+require_once( 'Maintenance.php' );
+
+class FixOTSLinks extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Fix oracle text index links for 
documents";
+               $this->addOption( 'all', 'Update all links (not only missing 
ones)' );
+       }
+
+       public function execute() {
+               $doAll = $this->hasOption( 'all' );
+               if ($doAll) {
+                       $this->output( "Recreate all index links to 
documents\n\n" );
+               } else {
+                       $this->output( "Recreate missing index links to 
documents\n\n" );
+               }
+               $this->doRecreate($doAll);
+       }
+
+       private function doRecreate($all) {
+               global $wgExIndexMIMETypes, $wgExIndexOnHTTP;
+               $dbw = wfGetDB( DB_MASTER );
+
+               $tbl_pag = $dbw->tableName( 'page' );
+               $tbl_idx = $dbw->tableName( 'searchindex' );
+               
+               $searchWhere = $all ? '' : ' AND NOT EXISTS (SELECT null FROM 
'.$tbl_idx.' WHERE si_page=p.page_id AND si_url IS NOT null)';
+               $result = $dbw->doQuery('SELECT p.page_id FROM '.$tbl_pag.' p 
WHERE p.page_namespace = '.NS_FILE.$searchWhere );
+               $this->output($result->numRows().' files found.'."\n\n");
+               
+               $syncIdx = false;
+               
+               while (($row = $result->fetchObject()) !== false) {
+                       $titleObj = Title::newFromID($row->page_id);
+                       $file = wfLocalFile($titleObj->getText());
+
+                       $this->output('Updating "'.$titleObj->getText().'" ... 
');
+
+                       if (in_array( $file->getMimeType(), $wgExIndexMIMETypes 
)) {
+                               $url = $wgExIndexOnHTTP ? preg_replace( 
'/^https:/i', 'http:', $file->getFullUrl() ) : $file->getFullUrl();
+                               $dbw->update('searchindex',
+                                       array( 'si_url' => $url ), 
+                                       array( 'si_page' => $row->page_id ),
+                                       'SearchIndexUpdate:update' );
+                               $this->output('complete'."\n");
+                               $syncIdx = true;
+                       } else {
+                               $this->output('skipped (unsupported or excluded 
mime-type)'."\n");
+                       }
+               }
+               
+               if ( $syncIdx ) {
+                       $this->output("\n".'Syncing Index'."\n");
+                       $index = $dbw->getProperty('mTablePrefix')."si_url_idx";
+                       $dbw->query( "CALL ctx_ddl.sync_index('$index')" );
+               }
+               
+               $this->output('Recreate finished');
+       }
+}
+
+$maintClass = "FixOTSLinks";
+require_once( DO_MAINTENANCE );
+


Property changes on: 
trunk/extensions/OracleTextSearch/maintainenceFixOTSLinks.php
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/extensions/OracleTextSearch/patch_searchindex_si_url.sql
===================================================================
--- trunk/extensions/OracleTextSearch/patch_searchindex_si_url.sql              
                (rev 0)
+++ trunk/extensions/OracleTextSearch/patch_searchindex_si_url.sql      
2011-06-14 07:46:21 UTC (rev 90038)
@@ -0,0 +1,6 @@
+define mw_prefix='{$wgDBprefix}';
+
+ALTER TABLE &mw_prefix.searchindex ADD si_url VARCHAR2(512); 
+
+CREATE INDEX &mw_prefix.si_url_idx ON &mw_prefix.searchindex(si_url) INDEXTYPE 
IS ctxsys.context PARAMETERS ('DATASTORE ctxsys.url_datastore FILTER 
ctxsys.inso_filter');
+


Property changes on: 
trunk/extensions/OracleTextSearch/patch_searchindex_si_url.sql
___________________________________________________________________
Added: svn:eol-style
   + native


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

Reply via email to