MediaWiki REL1_28
Go to the documentation of this file.
28require_once __DIR__ . '/Maintenance.php';
36 const RTI_CHUNK_SIZE = 500;
41 private $db;
43 public function __construct() {
44 parent::__construct();
45 $this->addDescription( 'Rebuild search index table from scratch' );
46 }
48 public function getDbType() {
50 }
52 public function execute() {
53 // Shouldn't be needed for Postgres
54 $this->db = $this->getDB( DB_MASTER );
55 if ( $this->db->getType() == 'postgres' ) {
56 $this->error( "This script is not needed when using Postgres.\n", true );
57 }
59 if ( $this->db->getType() == 'sqlite' ) {
61 $this->error( "Your version of SQLite module for PHP doesn't "
62 . "support full-text search (FTS3).\n", true );
63 }
64 if ( !$this->db->checkForEnabledSearch() ) {
65 $this->error( "Your database schema is not configured for "
66 . "full-text search support. Run update.php.\n", true );
67 }
68 }
70 if ( $this->db->getType() == 'mysql' ) {
71 $this->dropMysqlTextIndex();
72 $this->clearSearchIndex();
73 $this->populateSearchIndex();
74 $this->createMysqlTextIndex();
75 } else {
76 $this->clearSearchIndex();
77 $this->populateSearchIndex();
78 }
80 $this->output( "Done.\n" );
81 }
86 protected function populateSearchIndex() {
87 $res = $this->db->select( 'page', 'MAX(page_id) AS count' );
88 $s = $this->db->fetchObject( $res );
89 $count = $s->count;
90 $this->output( "Rebuilding index fields for {$count} pages...\n" );
91 $n = 0;
93 $fields = array_merge(
97 );
99 while ( $n < $count ) {
100 if ( $n ) {
101 $this->output( $n . "\n" );
102 }
103 $end = $n + self::RTI_CHUNK_SIZE - 1;
105 $res = $this->db->select( [ 'page', 'revision', 'text' ], $fields,
106 [ "page_id BETWEEN $n AND $end", 'page_latest = rev_id', 'rev_text_id = old_id' ],
107 __METHOD__
108 );
110 foreach ( $res as $s ) {
111 try {
112 $title = Title::makeTitle( $s->page_namespace, $s->page_title );
114 $rev = new Revision( $s );
115 $content = $rev->getContent();
117 $u = new SearchUpdate( $s->page_id, $title, $content );
118 $u->doUpdate();
119 } catch ( MWContentSerializationException $ex ) {
120 $this->output( "Failed to deserialize content of revision {$s->rev_id} of page "
121 . "`" . $title->getPrefixedDBkey() . "`!\n" );
122 }
123 }
125 }
126 }
131 private function dropMysqlTextIndex() {
132 $searchindex = $this->db->tableName( 'searchindex' );
133 if ( $this->db->indexExists( 'searchindex', 'si_title', __METHOD__ ) ) {
134 $this->output( "Dropping index...\n" );
135 $sql = "ALTER TABLE $searchindex DROP INDEX si_title, DROP INDEX si_text";
136 $this->db->query( $sql, __METHOD__ );
137 }
138 }
143 private function createMysqlTextIndex() {
144 $searchindex = $this->db->tableName( 'searchindex' );
145 $this->output( "\nRebuild the index...\n" );
146 $sql = "ALTER TABLE $searchindex ADD FULLTEXT si_title (si_title), " .
147 "ADD FULLTEXT si_text (si_text)";
148 $this->db->query( $sql, __METHOD__ );
149 }
154 private function clearSearchIndex() {
155 $this->output( 'Clearing searchindex table...' );
156 $this->db->delete( 'searchindex', '*', __METHOD__ );
157 $this->output( "Done\n" );
158 }
161$maintClass = "RebuildTextIndex";
162require_once RUN_MAINTENANCE_IF_MAIN;
static getFulltextSearchModule()
Returns version of currently supported SQLite fulltext search module or false if none present.
Relational database abstraction object.
Definition Database.php:36
Exception representing a failure to serialize or unserialize a content object.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
Maintenance script that rebuilds search index table from scratch.
Do the actual work.
(MySQL only) Drops fulltext index before populating the table.
(MySQL only) Adds back fulltext index after populating the table.
Deletes everything from search index.
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Default constructor.
Populates the search index with content from all pages.
static selectTextFields()
Return the list of text fields that should be selected to read the revision text.
Definition Revision.php:504
static selectPageFields()
Return the list of page fields that should be selected from page table.
Definition Revision.php:515
static selectFields()
Return the list of revision fields that should be selected to create a new revision.
Definition Revision.php:442
Database independant search index updater.
Definition database.txt:21
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:986
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
Definition hooks.txt:1094
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition hooks.txt:1734
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Definition defines.php:23