65 'table' =>
'revision_comment_temp',
66 'pk' =>
'revcomment_rev',
67 'field' =>
'revcomment_comment_id',
70 'deprecatedIn' =>
null,
72 'img_description' => [
74 'deprecatedIn' =>
'1.32',
100 $this->stage = $migrationStage;
114 $store =
new CommentStore( MediaWikiServices::getInstance()->getContentLanguage(),
126 return MediaWikiServices::getInstance()->getCommentStore();
135 private function getKey( $methodKey =
null ) {
136 $key = $this->
key ?? $methodKey;
137 if (
$key ===
null ) {
139 throw new InvalidArgumentException(
'$key should not be null' );
165 $fields[
"{$key}_text"] =
$key;
166 $fields[
"{$key}_data"] =
'NULL';
167 $fields[
"{$key}_cid"] =
'NULL';
170 $fields[
"{$key}_old"] =
$key;
173 $tempTableStage = isset( $this->tempTables[
$key] )
176 $fields[
"{$key}_pk"] = $this->tempTables[$key][
'joinPK'];
179 $fields[
"{$key}_id"] =
"{$key}_id";
203 if ( !array_key_exists(
$key, $this->joinCache ) ) {
209 $fields[
"{$key}_text"] =
$key;
210 $fields[
"{$key}_data"] =
'NULL';
211 $fields[
"{$key}_cid"] =
'NULL';
213 $join = $this->stage ===
MIGRATION_NEW ?
'JOIN' :
'LEFT JOIN';
215 $tempTableStage = isset( $this->tempTables[
$key] )
218 $t = $this->tempTables[$key];
219 $alias =
"temp_$key";
221 $joins[$alias] = [ $join,
"{$alias}.{$t['pk']} = {$t['joinPK']}" ];
223 $joinField =
"{$alias}.{$t['field']}";
229 $joins[$alias][0] =
'LEFT JOIN';
230 $joinField =
"(CASE WHEN {$key}_id != 0 THEN {$key}_id ELSE {$alias}.{$t['field']} END)";
231 throw new LogicException(
'Nothing should reach this code path at this time' );
235 $joinField =
"{$key}_id";
238 $alias =
"comment_$key";
240 $joins[$alias] = [ $join,
"{$alias}.comment_id = {$joinField}" ];
243 $fields[
"{$key}_text"] =
"{$alias}.comment_text";
245 $fields[
"{$key}_text"] =
"COALESCE( {$alias}.comment_text, $key )";
247 $fields[
"{$key}_data"] =
"{$alias}.comment_data";
248 $fields[
"{$key}_cid"] =
"{$alias}.comment_id";
251 $this->joinCache[
$key] = [
258 return $this->joinCache[
$key];
275 if ( array_key_exists(
"{$key}_text", $row ) && array_key_exists(
"{$key}_data", $row ) ) {
276 $cid = $row[
"{$key}_cid"] ??
null;
277 $text = $row[
"{$key}_text"];
278 $data = $row[
"{$key}_data"];
282 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
285 wfLogWarning(
"Missing {$key}_text and {$key}_data fields in row with MIGRATION_OLD" );
290 $tempTableStage = isset( $this->tempTables[
$key] )
293 if ( $tempTableStage >
MIGRATION_OLD && array_key_exists(
"{$key}_id", $row ) ) {
295 throw new InvalidArgumentException(
296 "\$row does not contain fields needed for comment $key and getComment(), but "
297 .
"does have fields for getCommentLegacy()"
300 $id = $row[
"{$key}_id"];
301 $row2 = $db->selectRow(
303 [
'comment_id',
'comment_text',
'comment_data' ],
304 [
'comment_id' => $id ],
308 if ( !$row2 && $tempTableStage <
MIGRATION_NEW && array_key_exists(
"{$key}_pk", $row ) ) {
310 throw new InvalidArgumentException(
311 "\$row does not contain fields needed for comment $key and getComment(), but "
312 .
"does have fields for getCommentLegacy()"
315 $t = $this->tempTables[$key];
316 $id = $row[
"{$key}_pk"];
317 $row2 = $db->selectRow(
318 [
$t[
'table'],
'comment' ],
319 [
'comment_id',
'comment_text',
'comment_data' ],
323 [
'comment' => [
'JOIN', [
"comment_id = {$t['field']}" ] ] ]
326 if ( $row2 ===
null &&
$fallback && isset( $row[$key] ) ) {
327 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
328 $row2 = (
object)[
'comment_text' => $row[$key],
'comment_data' =>
null ];
330 if ( $row2 ===
null ) {
331 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
335 $cid = $row2->comment_id;
336 $text = $row2->comment_text;
337 $data = $row2->comment_data;
338 } elseif ( $this->stage <
MIGRATION_NEW && array_key_exists(
"{$key}_old", $row ) ) {
340 $text = $row[
"{$key}_old"];
353 if ( $data !==
null ) {
354 $data = FormatJson::decode( $data );
355 if ( !is_object( $data ) ) {
357 wfLogWarning(
"Invalid JSON object in comment: $data" );
361 $data = (
array)$data;
362 if ( isset( $data[
'_message'] ) ) {
363 $msg = self::decodeMessage( $data[
'_message'] )
364 ->setInterfaceMessageFlag(
true );
366 if ( !empty( $data[
'_null'] ) ) {
369 foreach ( $data as $k => $v ) {
370 if ( substr( $k, 0, 1 ) ===
'_' ) {
399 if ( $this->
key !==
null ) {
404 if ( $row ===
null ) {
406 throw new InvalidArgumentException(
'$row must not be null' );
433 if ( $this->
key !==
null ) {
438 if ( $row ===
null ) {
440 throw new InvalidArgumentException(
'$row must not be null' );
467 $comment = CommentStoreComment::newUnsavedComment( $comment, $data );
469 # Truncate comment in a Unicode-sensitive manner
470 $comment->text = $this->lang->truncateForVisual( $comment->text, self::COMMENT_CHARACTER_LIMIT );
473 $dbData = $comment->data;
474 if ( !$comment->message instanceof
RawMessage ) {
475 if ( $dbData ===
null ) {
476 $dbData = [
'_null' =>
true ];
478 $dbData[
'_message'] = self::encodeMessage( $comment->message );
480 if ( $dbData !==
null ) {
481 $dbData = FormatJson::encode( (
object)$dbData,
false, FormatJson::ALL_OK );
482 $len = strlen( $dbData );
483 if ( $len > self::MAX_DATA_LENGTH ) {
484 $max = self::MAX_DATA_LENGTH;
485 throw new OverflowException(
"Comment data is too long ($len bytes, maximum is $max)" );
489 $hash = self::hash( $comment->text, $dbData );
494 'comment_hash' => $hash,
495 'comment_text' => $comment->text,
496 'comment_data' => $dbData,
500 if ( !$comment->id ) {
504 'comment_hash' => $hash,
505 'comment_text' => $comment->text,
506 'comment_data' => $dbData,
533 $fields[
$key] = $this->lang->truncateForDatabase( $comment->text, 255 );
537 $tempTableStage = isset( $this->tempTables[
$key] )
540 $t = $this->tempTables[$key];
542 $commentId = $comment->id;
543 $callback =
function ( $id ) use ( $dbw, $commentId,
$t, $func ) {
548 $t[
'field'] => $commentId,
555 $fields[
"{$key}_id"] = $comment->id;
559 return [ $fields, $callback ];
579 if ( $this->
key !==
null ) {
584 if ( $comment ===
null ) {
586 throw new InvalidArgumentException(
'$comment can not be null' );
590 $tempTableStage = isset( $this->tempTables[
$key] )
593 throw new InvalidArgumentException(
"Must use insertWithTempTable() for $key" );
623 if ( $this->
key !==
null ) {
628 if ( $comment ===
null ) {
630 throw new InvalidArgumentException(
'$comment can not be null' );
634 if ( !isset( $this->tempTables[
$key] ) ) {
635 throw new InvalidArgumentException(
"Must use insert() for $key" );
636 } elseif ( isset( $this->tempTables[$key][
'deprecatedIn'] ) ) {
637 wfDeprecated( __METHOD__ .
" for $key", $this->tempTables[$key][
'deprecatedIn'] );
642 $callback =
function () {
646 return [ $fields, $callback ];
655 $key = count( $msg->getKeysToTry() ) > 1 ? $msg->getKeysToTry() : $msg->getKey();
657 foreach (
$params as &$param ) {
658 if ( $param instanceof
Message ) {
660 'message' => self::encodeMessage( $param )
674 $key = array_shift( $data );
675 foreach ( $data as &$param ) {
676 if ( is_object( $param ) ) {
677 $param = (
array)$param;
679 if ( is_array( $param ) && count( $param ) === 1 && isset( $param[
'message'] ) ) {
680 $param = self::decodeMessage( $param[
'message'] );
692 public static function hash( $text, $data ) {
693 $hash = crc32( $text ) ^ crc32( (
string)$data );
697 if ( $hash >= 0x80000000 ) {
int $wgCommentTableSchemaMigrationStage
Comment table schema migration stage.
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Internationalisation code.
The Message class provides methods which fulfil two basic services:
Variant of the Message class.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation use $formDescriptor instead default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message key
this hook is for auditing only RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
const MIGRATION_WRITE_NEW
const MIGRATION_WRITE_BOTH
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(!isset( $args[0])) $lang