r90038 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90037‎ | r90038 | r90039 >
Date:07:46, 14 June 2011
Author:freakolowsky
Status:deferred (Comments)
Tags:
Comment:
* Initial commit
Modified paths:
  • /trunk/extensions/OracleTextSearch/OracleTextSearch.i18n.php (added) (history)
  • /trunk/extensions/OracleTextSearch/OracleTextSearch.php (added) (history)
  • /trunk/extensions/OracleTextSearch/SearchOracleText.php (added) (history)
  • /trunk/extensions/OracleTextSearch/maintainenceFixOTSLinks.php (added) (history)
  • /trunk/extensions/OracleTextSearch/patch_searchindex_si_url.sql (added) (history)

Diff [purge]

Index: trunk/extensions/OracleTextSearch/maintainenceFixOTSLinks.php
@@ -0,0 +1,66 @@
 2+<?php
 3+/* run this script out of your $IP/maintenance folder */
 4+require_once( 'Maintenance.php' );
 5+
 6+class FixOTSLinks extends Maintenance {
 7+ public function __construct() {
 8+ parent::__construct();
 9+ $this->mDescription = "Fix oracle text index links for documents";
 10+ $this->addOption( 'all', 'Update all links (not only missing ones)' );
 11+ }
 12+
 13+ public function execute() {
 14+ $doAll = $this->hasOption( 'all' );
 15+ if ($doAll) {
 16+ $this->output( "Recreate all index links to documents\n\n" );
 17+ } else {
 18+ $this->output( "Recreate missing index links to documents\n\n" );
 19+ }
 20+ $this->doRecreate($doAll);
 21+ }
 22+
 23+ private function doRecreate($all) {
 24+ global $wgExIndexMIMETypes, $wgExIndexOnHTTP;
 25+ $dbw = wfGetDB( DB_MASTER );
 26+
 27+ $tbl_pag = $dbw->tableName( 'page' );
 28+ $tbl_idx = $dbw->tableName( 'searchindex' );
 29+
 30+ $searchWhere = $all ? '' : ' AND NOT EXISTS (SELECT null FROM '.$tbl_idx.' WHERE si_page=p.page_id AND si_url IS NOT null)';
 31+ $result = $dbw->doQuery('SELECT p.page_id FROM '.$tbl_pag.' p WHERE p.page_namespace = '.NS_FILE.$searchWhere );
 32+ $this->output($result->numRows().' files found.'."\n\n");
 33+
 34+ $syncIdx = false;
 35+
 36+ while (($row = $result->fetchObject()) !== false) {
 37+ $titleObj = Title::newFromID($row->page_id);
 38+ $file = wfLocalFile($titleObj->getText());
 39+
 40+ $this->output('Updating "'.$titleObj->getText().'" ... ');
 41+
 42+ if (in_array( $file->getMimeType(), $wgExIndexMIMETypes )) {
 43+ $url = $wgExIndexOnHTTP ? preg_replace( '/^https:/i', 'http:', $file->getFullUrl() ) : $file->getFullUrl();
 44+ $dbw->update('searchindex',
 45+ array( 'si_url' => $url ),
 46+ array( 'si_page' => $row->page_id ),
 47+ 'SearchIndexUpdate:update' );
 48+ $this->output('complete'."\n");
 49+ $syncIdx = true;
 50+ } else {
 51+ $this->output('skipped (unsupported or excluded mime-type)'."\n");
 52+ }
 53+ }
 54+
 55+ if ( $syncIdx ) {
 56+ $this->output("\n".'Syncing Index'."\n");
 57+ $index = $dbw->getProperty('mTablePrefix')."si_url_idx";
 58+ $dbw->query( "CALL ctx_ddl.sync_index('$index')" );
 59+ }
 60+
 61+ $this->output('Recreate finished');
 62+ }
 63+}
 64+
 65+$maintClass = "FixOTSLinks";
 66+require_once( DO_MAINTENANCE );
 67+
Property changes on: trunk/extensions/OracleTextSearch/maintainenceFixOTSLinks.php
___________________________________________________________________
Added: svn:eol-style
168 + native
Index: trunk/extensions/OracleTextSearch/OracleTextSearch.i18n.php
@@ -0,0 +1,7 @@
 2+<?php
 3+$messages = array();
 4+
 5+$messages['en'] = array(
 6+ 'oracletextsearch' => 'OracleTextSearch',
 7+ 'oracletextsearch-desc' => 'Search content/metadata of uploaded files using Oracle Text indexing.',
 8+);
Property changes on: trunk/extensions/OracleTextSearch/OracleTextSearch.i18n.php
___________________________________________________________________
Added: svn:eol-style
19 + native
Index: trunk/extensions/OracleTextSearch/OracleTextSearch.php
@@ -0,0 +1,41 @@
 2+<?php
 3+# Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
 4+if (!defined('MEDIAWIKI')) {
 5+ echo <<<EOT
 6+To install this extension put the following line in LocalSettings.php:
 7+require_once( "\$IP/extensions/OracleTextSearch/OracleTextSearch.php" );
 8+EOT;
 9+ exit( 1 );
 10+}
 11+$wgExtensionCredits['other'][] = array(
 12+ 'name' => 'OracleTextSearch',
 13+ 'author' => 'freakolowsky [Jure Kajzer]',
 14+ 'url' => 'http://www.mediawiki.org/wiki/Extension:OracleTextSearch',
 15+ 'description' => 'Show SQL data directly in the page contents..',
 16+ 'descriptionmsg' => 'oracletextsearch-desc',
 17+ 'version' => '1.0.0',
 18+);
 19+
 20+$dir = dirname(__FILE__) . '/';
 21+$wgAutoloadClasses['SearchOracleText'] = $dir . 'SearchOracleText.php';
 22+$wgHooks['UploadComplete'][] = 'SearchOracleText::onUploadCompleteHook';
 23+
 24+/**
 25+ * extension defaults
 26+ */
 27+
 28+/**
 29+ * index on http (false requires you to setup credentials wallet in oracle)
 30+ */
 31+$wgExIndexOnHTTP = true;
 32+/**
 33+ * default set of mime types Oracle Text will index (set according to DB version)
 34+ */
 35+$wgExIndexMIMETypes = array( 'application/pdf',
 36+ 'application/xml',
 37+ 'text/xml',
 38+ 'application/msword' ,
 39+ 'text/plain',
 40+ 'text/html' );
 41+
 42+
Property changes on: trunk/extensions/OracleTextSearch/OracleTextSearch.php
___________________________________________________________________
Added: svn:eol-style
143 + native
Index: trunk/extensions/OracleTextSearch/SearchOracleText.php
@@ -0,0 +1,55 @@
 2+<?php
 3+
 4+class SearchOracleText extends SearchOracle {
 5+
 6+
 7+ public function update( $id, $title, $text ) {
 8+ global $wgExIndexMIMETypes;
 9+
 10+ parent::update( $id, $title, $text );
 11+
 12+ $titleObj = Title::newFromID( $id );
 13+ $file = wfLocalFile( $titleObj->getText() );
 14+ if ( in_array( $file->getMimeType(), $wgExIndexMIMETypes ) ) {
 15+ $dbw = wfGetDB(DB_MASTER);
 16+ //$dbw->query("CALL CTXSYS.CTX_OUTPUT.START_LOG('wiki_ctx.log')"); //use for INTERNAL debuging ONLY!!!
 17+
 18+ $url = $wgExIndexOnHTTP ? preg_replace( '/^https:/i', 'http:', $file->getFullUrl() ) : $file->getFullUrl();
 19+ $dbw->update('searchindex',
 20+ array( 'si_url' => $url ),
 21+ array( 'si_page' => $id ),
 22+ 'SearchIndexUpdate:update' );
 23+ wfDebugLog( 'OracleTextSearch', 'Updated si_url for page ' . $id );
 24+
 25+ $index = $dbw->getProperty('mTablePrefix')."si_url_idx";
 26+ $dbw->query( "CALL ctx_ddl.sync_index('$index')" );
 27+ wfDebugLog( 'OracleTextSearch', 'Synced index: '.$index);
 28+ }
 29+ }
 30+
 31+ function parseQuery( $filteredText, $fulltext ) {
 32+ $match = parent::parseQuery( $filteredText, $fulltext );
 33+
 34+ if ( $fulltext ) {
 35+ $field = $this->getIndexField($fulltext);
 36+ $searchon = preg_replace( "/ CONTAINS\($field, ('.*'), 1\) > 0 /", "\\1", $match);
 37+ $match = "($match OR CONTAINS(si_url, $searchon, 2) > 0) ";
 38+ }
 39+
 40+ wfDebugLog( 'OracleTextSearch', 'Matching: '.$match );
 41+ return $match;
 42+ }
 43+
 44+ public static function onUploadCompleteHook( &$file ) {
 45+ global $wgExIndexMIMETypes;
 46+
 47+ $localFile = $file->getLocalFile();
 48+ if ( $localFile != null && in_array( $localFile->getMimeType(), $wgExIndexMIMETypes ) ) {
 49+ wfDebugLog( 'OracleTextSearch', 'Touching file page to force indexing');
 50+ $article = new Article( $localFile->getTitle() );
 51+ $article->loadContent();
 52+ $article->doEdit( $article->mContent, $article->mComment );
 53+ }
 54+ return true;
 55+ }
 56+}
Property changes on: trunk/extensions/OracleTextSearch/SearchOracleText.php
___________________________________________________________________
Added: svn:eol-style
157 + native
Index: trunk/extensions/OracleTextSearch/patch_searchindex_si_url.sql
@@ -0,0 +1,6 @@
 2+define mw_prefix='{$wgDBprefix}';
 3+
 4+ALTER TABLE &mw_prefix.searchindex ADD si_url VARCHAR2(512);
 5+
 6+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');
 7+
Property changes on: trunk/extensions/OracleTextSearch/patch_searchindex_si_url.sql
___________________________________________________________________
Added: svn:eol-style
18 + native

Sign-offs

UserFlagDate
Nikerabbitinspected12:19, 14 June 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r90040(Nikerabbit comments on r90038#c18029)...freakolowsky13:02, 14 June 2011

Comments

#Comment by Nikerabbit (talk | contribs)   12:19, 14 June 2011
+/* run this script out of your $IP/maintenance folder */
+require_once( 'Maintenance.php' );

I don't think this is the best way to do this. I've used:

if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
        $IP = getenv( 'MW_INSTALL_PATH' );
} else {
        $dir = dirname( __FILE__ ); $IP = "$dir/../..";
}
require_once( "$IP/maintenance/commandLine.inc" );
+$this->output('Updating "'.$titleObj->getText().'" ... ');
+$this->output('complete'."\n");

You could use the second parameter for output() for this. Doesn't matter so much if you are not throwing errors in the middle.

Here the indentation looks horrible. I suggest using tabs only up to the current indentation level and do the rest with spaces if at all. Here you could just split the line after array( to avoid the extra indentation.

+$wgExIndexMIMETypes = array(	'application/pdf', 
+								'application/xml', 
+								'text/xml', 
+								'application/msword' , 
+								'text/plain', 
+								'text/html' );

Running stylize script over the code would be nice.

I haven't seen $wgEx prefixed used elsewhere.

Status & tagging log