34require_once __DIR__ .
'/Maintenance.php';
44 parent::__construct();
45 $this->
addDescription(
'Script for periodic off-peak updating of the search index' );
46 $this->
addOption(
's',
'Starting timestamp',
false,
true );
47 $this->
addOption(
'e',
'Ending timestamp',
false,
true );
50 'File for saving/loading timestamps, searchUpdate.WIKI_ID.pos by default',
56 'Deprecated, has no effect (formerly lock time)',
67 $dbDomain = WikiMap::getCurrentWikiDbDomain()->getId();
68 $posFile = $this->
getOption(
'p',
'searchUpdate.' . rawurlencode( $dbDomain ) .
'.pos' );
72 } elseif ( is_readable( $posFile ) ) {
73 $start = file_get_contents( $posFile );
78 $this->doUpdateSearchIndex( $start, $end );
79 $file = fopen( $posFile,
'w' );
80 if (
$file !==
false ) {
81 fwrite(
$file, $end );
84 $this->
error(
"*** Couldn't write to the $posFile!\n" );
88 private function doUpdateSearchIndex( $start, $end ) {
95 $this->
output(
"Updating searchindex between $start and $end\n" );
97 # Select entries from recentchanges which are on top and between the specified times
98 $start = $dbw->timestamp( $start );
99 $end = $dbw->timestamp( $end );
102 [
'recentchanges',
'page' ],
105 'rc_type != ' . $dbw->addQuotes(
RC_LOG ),
106 'rc_timestamp BETWEEN ' . $dbw->addQuotes( $start ) .
' AND ' . $dbw->addQuotes( $end )
111 'page' => [
'JOIN',
'rc_cur_id=page_id AND rc_this_oldid=page_latest' ]
115 foreach (
$res as $row ) {
116 $this->updateSearchIndexForPage( (
int)$row->rc_cur_id );
118 $this->
output(
"Done\n" );
126 private function updateSearchIndexForPage(
int $pageId ) {
128 $rev = MediaWikiServices::getInstance()
129 ->getRevisionLookup()
130 ->getRevisionByPageId( $pageId, 0, IDBAccessObject::READ_LATEST );
134 $title = $titleObj->getPrefixedDBkey();
135 $this->
output(
"$title..." );
137 $u =
new SearchUpdate( $pageId, $titleObj, $rev->getContent( SlotRecord::MAIN ) );
147require_once RUN_MAINTENANCE_IF_MAIN;
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
Database independent search index updater.
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Maintenance script for periodic off-peak updating of the search index.
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
execute()
Do the actual work.
__construct()
Default constructor.
$wgDisableSearchUpdate
Config variable stub for the DisableSearchUpdate setting, for use by phpdoc and IDEs.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.