63 'table' =>
'revision_comment_temp',
64 'pk' =>
'revcomment_rev',
65 'field' =>
'revcomment_comment_id',
68 'img_description' => [
69 'table' =>
'image_comment_temp',
70 'pk' =>
'imgcomment_name',
71 'field' =>
'imgcomment_description_id',
72 'joinPK' =>
'img_name',
105 $this->stage = $migrationStage;
131 return MediaWikiServices::getInstance()->getCommentStore();
140 private function getKey( $methodKey =
null ) {
141 $key = $this->
key !==
null ? $this->
key : $methodKey;
142 if (
$key ===
null ) {
144 throw new InvalidArgumentException(
'$key should not be null' );
170 $fields[
"{$key}_text"] =
$key;
171 $fields[
"{$key}_data"] =
'NULL';
172 $fields[
"{$key}_cid"] =
'NULL';
175 $fields[
"{$key}_old"] =
$key;
177 if ( isset( self::$tempTables[
$key] ) ) {
178 $fields[
"{$key}_pk"] = self::$tempTables[$key][
'joinPK'];
180 $fields[
"{$key}_id"] =
"{$key}_id";
204 if ( !array_key_exists(
$key, $this->joinCache ) ) {
210 $fields[
"{$key}_text"] =
$key;
211 $fields[
"{$key}_data"] =
'NULL';
212 $fields[
"{$key}_cid"] =
'NULL';
214 $join = $this->stage ===
MIGRATION_NEW ?
'JOIN' :
'LEFT JOIN';
216 if ( isset( self::$tempTables[
$key] ) ) {
217 $t = self::$tempTables[$key];
218 $alias =
"temp_$key";
220 $joins[$alias] = [ $join,
"{$alias}.{$t['pk']} = {$t['joinPK']}" ];
221 $joinField =
"{$alias}.{$t['field']}";
223 $joinField =
"{$key}_id";
226 $alias =
"comment_$key";
228 $joins[$alias] = [ $join,
"{$alias}.comment_id = {$joinField}" ];
231 $fields[
"{$key}_text"] =
"{$alias}.comment_text";
233 $fields[
"{$key}_text"] =
"COALESCE( {$alias}.comment_text, $key )";
235 $fields[
"{$key}_data"] =
"{$alias}.comment_data";
236 $fields[
"{$key}_cid"] =
"{$alias}.comment_id";
239 $this->joinCache[
$key] = [
246 return $this->joinCache[
$key];
263 if ( array_key_exists(
"{$key}_text", $row ) && array_key_exists(
"{$key}_data", $row ) ) {
264 $cid = isset( $row[
"{$key}_cid"] ) ? $row[
"{$key}_cid"] :
null;
265 $text = $row[
"{$key}_text"];
266 $data = $row[
"{$key}_data"];
270 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
273 wfLogWarning(
"Missing {$key}_text and {$key}_data fields in row with MIGRATION_OLD" );
278 if ( isset( self::$tempTables[
$key] ) ) {
279 if ( array_key_exists(
"{$key}_pk", $row ) ) {
281 throw new InvalidArgumentException(
282 "\$row does not contain fields needed for comment $key and getComment(), but "
283 .
"does have fields for getCommentLegacy()"
286 $t = self::$tempTables[$key];
287 $id = $row[
"{$key}_pk"];
288 $row2 = $db->selectRow(
289 [
$t[
'table'],
'comment' ],
290 [
'comment_id',
'comment_text',
'comment_data' ],
294 [
'comment' => [
'JOIN', [
"comment_id = {$t['field']}" ] ] ]
296 } elseif (
$fallback && isset( $row[$key] ) ) {
297 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
298 $row2 = (
object)[
'comment_text' => $row[$key],
'comment_data' =>
null ];
300 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
303 if ( array_key_exists(
"{$key}_id", $row ) ) {
305 throw new InvalidArgumentException(
306 "\$row does not contain fields needed for comment $key and getComment(), but "
307 .
"does have fields for getCommentLegacy()"
310 $id = $row[
"{$key}_id"];
311 $row2 = $db->selectRow(
313 [
'comment_id',
'comment_text',
'comment_data' ],
314 [
'comment_id' => $id ],
317 } elseif (
$fallback && isset( $row[$key] ) ) {
318 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
319 $row2 = (
object)[
'comment_text' => $row[$key],
'comment_data' =>
null ];
321 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
326 $cid = $row2->comment_id;
327 $text = $row2->comment_text;
328 $data = $row2->comment_data;
329 } elseif ( $this->stage <
MIGRATION_NEW && array_key_exists(
"{$key}_old", $row ) ) {
331 $text = $row[
"{$key}_old"];
344 if ( $data !==
null ) {
345 $data = FormatJson::decode( $data );
346 if ( !is_object( $data ) ) {
348 wfLogWarning(
"Invalid JSON object in comment: $data" );
352 $data = (
array)$data;
353 if ( isset( $data[
'_message'] ) ) {
354 $msg = self::decodeMessage( $data[
'_message'] )
355 ->setInterfaceMessageFlag(
true );
357 if ( !empty( $data[
'_null'] ) ) {
360 foreach ( $data as $k => $v ) {
361 if ( substr( $k, 0, 1 ) ===
'_' ) {
390 if ( $this->
key !==
null ) {
395 if ( $row ===
null ) {
397 throw new InvalidArgumentException(
'$row must not be null' );
424 if ( $this->
key !==
null ) {
429 if ( $row ===
null ) {
431 throw new InvalidArgumentException(
'$row must not be null' );
458 $comment = CommentStoreComment::newUnsavedComment( $comment, $data );
460 # Truncate comment in a Unicode-sensitive manner
461 $comment->text = $this->lang->truncate( $comment->text, self::MAX_COMMENT_LENGTH );
462 if ( mb_strlen( $comment->text,
'UTF-8' ) > self::COMMENT_CHARACTER_LIMIT ) {
463 $ellipsis =
wfMessage(
'ellipsis' )->inLanguage( $this->lang )->escaped();
464 if ( mb_strlen( $ellipsis ) >= self::COMMENT_CHARACTER_LIMIT ) {
468 $maxLength = self::COMMENT_CHARACTER_LIMIT - mb_strlen( $ellipsis,
'UTF-8' );
469 $comment->text = mb_substr( $comment->text, 0, $maxLength,
'UTF-8' ) . $ellipsis;
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->truncate( $comment->text, 255 );
537 if ( isset( self::$tempTables[
$key] ) ) {
538 $t = self::$tempTables[$key];
540 $commentId = $comment->id;
541 $callback =
function ( $id ) use ( $dbw, $commentId,
$t, $func ) {
546 $t[
'field'] => $commentId,
552 $fields[
"{$key}_id"] = $comment->id;
556 return [ $fields, $callback ];
576 if ( $this->
key !==
null ) {
581 if ( $comment ===
null ) {
583 throw new InvalidArgumentException(
'$comment can not be null' );
587 if ( isset( self::$tempTables[
$key] ) ) {
588 throw new InvalidArgumentException(
"Must use insertWithTempTable() for $key" );
618 if ( $this->
key !==
null ) {
623 if ( $comment ===
null ) {
625 throw new InvalidArgumentException(
'$comment can not be null' );
629 if ( isset( self::$formerTempTables[
$key] ) ) {
630 wfDeprecated( __METHOD__ .
" for $key", self::$formerTempTables[$key] );
631 } elseif ( !isset( self::$tempTables[$key] ) ) {
632 throw new InvalidArgumentException(
"Must use insert() for $key" );
637 $callback =
function () {
641 return [ $fields, $callback ];
650 $key = count( $msg->getKeysToTry() ) > 1 ? $msg->getKeysToTry() : $msg->getKey();
652 foreach (
$params as &$param ) {
653 if ( $param instanceof
Message ) {
655 'message' => self::encodeMessage( $param )
669 $key = array_shift( $data );
670 foreach ( $data as &$param ) {
671 if ( is_object( $param ) ) {
672 $param = (
array)$param;
674 if ( is_array( $param ) && count( $param ) === 1 && isset( $param[
'message'] ) ) {
675 $param = self::decodeMessage( $param[
'message'] );
687 public static function hash( $text, $data ) {
688 $hash = crc32( $text ) ^ crc32( (
string)$data );
692 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
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
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 but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
the array() calling protocol came about after MediaWiki 1.4rc1.
this hook is for auditing only RecentChangesLinked and Watchlist 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
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 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 additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
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 For a description of the see design txt $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_BOTH
if(!isset( $args[0])) $lang