Dvogel hallowelt has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/326078 )

Change subject: ExtendedSearch: add maintenance script to add a list of 
articles to search index
......................................................................

ExtendedSearch: add maintenance script to add a list of articles to search index

Change-Id: I1bf0a3f37666addef34e48c198f53faf1dc0423c
---
A ExtendedSearch/maintenance/searchAddToIndex.php
1 file changed, 72 insertions(+), 0 deletions(-)


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

diff --git a/ExtendedSearch/maintenance/searchAddToIndex.php 
b/ExtendedSearch/maintenance/searchAddToIndex.php
new file mode 100644
index 0000000..2395b00
--- /dev/null
+++ b/ExtendedSearch/maintenance/searchAddToIndex.php
@@ -0,0 +1,72 @@
+<?php
+//useage: php searchAddToIndex.php --input aritclenames.txt
+
+require_once( __DIR__ . 
'/../../../BlueSpiceFoundation/maintenance/BSMaintenance.php' );
+
+class searchAddToIndex extends BSMaintenance {
+
+       protected $sBasePath = '';
+
+       public function __construct() {
+               parent::__construct();
+               $this->addOption( 'input', 'plain text list of article names ( 
NS:Title )', true, true );
+       }
+
+       /**
+        * Get List and Update Seach Index
+        * @param WikiPage $oPage
+        * @param Article $oArticle The article that is created.
+        * @param string $sText New text.
+        * @return bool allow other hooked methods to be executed. Always true.
+        */
+       public function execute() {
+               $sSrc = file_get_contents( $this->getOption( 'input' ) );
+               $aSrc = explode( "\n", $sSrc );
+
+               foreach ( $aSrc as $sLine ) {
+                       if( trim( $sLine ) === '' ){
+                               continue;
+                       }
+                       $oTitle = Title::newFromText( trim( $sLine ) );
+                       if( $oTitle instanceof  Title === false ) {
+                               $this->error( "Error: '$sLine' is not a valid 
title" );
+                               continue;
+                       }
+
+                       if( $oTitle->exists() === false ) {
+                               $this->error( "Error: 
'{$oTitle->getPrefixedDBkey()}' does not exist" );
+                               continue;
+                       }
+
+                       $oArticle = new Article( $oTitle );
+                       $this->addArticle( $oArticle );
+               }
+       }
+
+       /*
+        * Copy of ExtendedSearch.class.php onArticleSaveComplete
+        */
+       protected function addArticle( &$oArticle ) {
+               try {
+                       BuildIndexMainControl::getInstance()->updateIndexWiki( 
$oArticle );
+                       $oTitle = $oArticle->getTitle();
+                       $this->output( "Indexing article 
'{$oTitle->getPrefixedDBkey()}'...");
+
+                       if ( $oTitle->getNamespace() === NS_FILE ) {
+                               $oFile = wfFindFile( $oTitle );
+                               $this->output( "Indexing file 
'{$oTitle->getPrefixedDBkey()}'...");
+
+                               
BuildIndexMainControl::getInstance()->deleteIndexFile( $oFile->getPath(), 
'repo' );
+                               
BuildIndexMainControl::getInstance()->updateIndexFile( $oFile );
+                       }
+               } catch ( BsException $e ) {
+                       $this->error( "Error: " . $e->getMessage() );
+               }
+               return true;
+       }
+
+}
+
+$maintClass = 'searchAddToIndex';
+
+require_once RUN_MAINTENANCE_IF_MAIN;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1bf0a3f37666addef34e48c198f53faf1dc0423c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Dvogel hallowelt <[email protected]>

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

Reply via email to