2004-06-26 03:27:08 +00:00
|
|
|
<?php
|
2004-09-03 20:33:01 +00:00
|
|
|
/**
|
2012-09-03 18:10:09 +00:00
|
|
|
* Periodic off-peak updating of the search index.
|
2004-09-03 20:33:01 +00:00
|
|
|
*
|
|
|
|
|
* Usage: php updateSearchIndex.php [-s START] [-e END] [-p POSFILE] [-l LOCKTIME] [-q]
|
|
|
|
|
* Where START is the starting timestamp
|
|
|
|
|
* END is the ending timestamp
|
2009-08-02 19:35:17 +00:00
|
|
|
* POSFILE is a file to load timestamps from and save them to, searchUpdate.WIKI_ID.pos by default
|
|
|
|
|
* LOCKTIME is how long the searchindex and revision tables will be locked for
|
2004-09-03 20:33:01 +00:00
|
|
|
* -q means quiet
|
|
|
|
|
*
|
2009-08-02 19:35:17 +00:00
|
|
|
* 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
|
|
|
|
|
*
|
2010-09-01 19:36:18 +00:00
|
|
|
* @file
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Maintenance
|
2004-09-03 20:33:01 +00:00
|
|
|
*/
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2021-03-30 23:00:56 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
|
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2004-09-03 20:33:01 +00:00
|
|
|
|
2012-09-03 18:10:09 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script for periodic off-peak updating of the search index.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2009-08-02 19:35:17 +00:00
|
|
|
class UpdateSearchIndex extends Maintenance {
|
2004-06-26 03:27:08 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
2016-02-09 13:24:28 +00:00
|
|
|
$this->addDescription( 'Script for periodic off-peak updating of the search index' );
|
2020-04-01 18:29:10 +00:00
|
|
|
$this->addOption( 's', 'Starting timestamp', false, true );
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->addOption( 'e', 'Ending timestamp', false, true );
|
2014-04-22 20:55:25 +00:00
|
|
|
$this->addOption(
|
|
|
|
|
'p',
|
|
|
|
|
'File for saving/loading timestamps, searchUpdate.WIKI_ID.pos by default',
|
|
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
$this->addOption(
|
|
|
|
|
'l',
|
2021-03-30 23:00:56 +00:00
|
|
|
'Deprecated, has no effect (formerly lock time)',
|
2014-04-22 20:55:25 +00:00
|
|
|
false,
|
|
|
|
|
true
|
|
|
|
|
);
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2004-06-26 03:27:08 +00:00
|
|
|
|
2010-03-10 12:59:44 +00:00
|
|
|
public function getDbType() {
|
2009-08-09 15:22:34 +00:00
|
|
|
return Maintenance::DB_ADMIN;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
public function execute() {
|
2019-07-04 07:31:06 +00:00
|
|
|
$dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
|
|
|
|
|
$posFile = $this->getOption( 'p', 'searchUpdate.' . rawurlencode( $dbDomain ) . '.pos' );
|
2009-08-02 19:35:17 +00:00
|
|
|
$end = $this->getOption( 'e', wfTimestampNow() );
|
|
|
|
|
if ( $this->hasOption( 's' ) ) {
|
2010-05-22 16:50:39 +00:00
|
|
|
$start = $this->getOption( 's' );
|
2013-04-18 18:48:44 +00:00
|
|
|
} elseif ( is_readable( $posFile ) ) {
|
2011-07-06 21:57:44 +00:00
|
|
|
$start = file_get_contents( $posFile );
|
2009-08-02 19:35:17 +00:00
|
|
|
} else {
|
2011-07-06 21:57:44 +00:00
|
|
|
$start = wfTimestamp( TS_MW, time() - 86400 );
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2021-03-30 23:00:56 +00:00
|
|
|
|
|
|
|
|
$this->doUpdateSearchIndex( $start, $end );
|
|
|
|
|
$file = fopen( $posFile, 'w' );
|
|
|
|
|
if ( $file !== false ) {
|
|
|
|
|
fwrite( $file, $end );
|
|
|
|
|
fclose( $file );
|
2010-03-10 21:54:23 +00:00
|
|
|
} else {
|
2010-12-14 13:37:53 +00:00
|
|
|
$this->error( "*** Couldn't write to the $posFile!\n" );
|
2010-03-10 21:54:23 +00:00
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2021-03-30 23:00:56 +00:00
|
|
|
private function doUpdateSearchIndex( $start, $end ) {
|
2009-08-02 19:35:17 +00:00
|
|
|
global $wgDisableSearchUpdate;
|
2004-06-26 03:27:08 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$wgDisableSearchUpdate = false;
|
2004-06-26 03:27:08 +00:00
|
|
|
|
2021-04-29 02:37:11 +00:00
|
|
|
$dbw = $this->getDB( DB_PRIMARY );
|
2004-06-26 03:27:08 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Updating searchindex between $start and $end\n" );
|
2004-06-26 03:27:08 +00:00
|
|
|
|
2009-08-02 19:35:17 +00:00
|
|
|
# Select entries from recentchanges which are on top and between the specified times
|
2009-08-02 19:49:24 +00:00
|
|
|
$start = $dbw->timestamp( $start );
|
|
|
|
|
$end = $dbw->timestamp( $end );
|
2009-06-24 02:02:37 +00:00
|
|
|
|
2021-03-30 23:00:56 +00:00
|
|
|
$res = $dbw->select(
|
|
|
|
|
[ 'recentchanges', 'page' ],
|
|
|
|
|
'rc_cur_id',
|
|
|
|
|
[
|
|
|
|
|
'rc_type != ' . $dbw->addQuotes( RC_LOG ),
|
|
|
|
|
'rc_timestamp BETWEEN ' . $dbw->addQuotes( $start ) . ' AND ' . $dbw->addQuotes( $end )
|
|
|
|
|
],
|
|
|
|
|
__METHOD__,
|
|
|
|
|
[],
|
|
|
|
|
[
|
|
|
|
|
'page' => [ 'JOIN', 'rc_cur_id=page_id AND rc_this_oldid=page_latest' ]
|
|
|
|
|
]
|
|
|
|
|
);
|
2009-06-24 02:02:37 +00:00
|
|
|
|
2021-03-30 23:00:56 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$this->updateSearchIndexForPage( (int)$row->rc_cur_id );
|
|
|
|
|
}
|
2009-08-02 19:35:17 +00:00
|
|
|
$this->output( "Done\n" );
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-30 23:00:56 +00:00
|
|
|
/**
|
|
|
|
|
* Update the searchindex table for a given pageid
|
|
|
|
|
* @param int $pageId The page ID to update.
|
|
|
|
|
* @return null|string
|
|
|
|
|
*/
|
|
|
|
|
private function updateSearchIndexForPage( int $pageId ) {
|
|
|
|
|
// Get current revision
|
|
|
|
|
$rev = MediaWikiServices::getInstance()
|
|
|
|
|
->getRevisionLookup()
|
|
|
|
|
->getRevisionByPageId( $pageId, 0, IDBAccessObject::READ_LATEST );
|
|
|
|
|
$title = null;
|
|
|
|
|
if ( $rev ) {
|
|
|
|
|
$titleObj = Title::newFromLinkTarget( $rev->getPageAsLinkTarget() );
|
|
|
|
|
$title = $titleObj->getPrefixedDBkey();
|
|
|
|
|
$this->output( "$title..." );
|
|
|
|
|
# Update searchindex
|
|
|
|
|
$u = new SearchUpdate( $pageId, $titleObj, $rev->getContent( SlotRecord::MAIN ) );
|
|
|
|
|
$u->doUpdate();
|
|
|
|
|
$this->output( "\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $title;
|
2009-08-02 19:35:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-06-29 01:19:14 +00:00
|
|
|
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = UpdateSearchIndex::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|