MediaWiki REL1_33
ContentHandler.php
Go to the documentation of this file.
1<?php
28use Wikimedia\Assert\Assert;
33
53abstract class ContentHandler {
83 public static function getContentText( Content $content = null ) {
85
86 if ( is_null( $content ) ) {
87 return '';
88 }
89
90 if ( $content instanceof TextContent ) {
91 return $content->getText();
92 }
93
94 wfDebugLog( 'ContentHandler', 'Accessing ' . $content->getModel() . ' content as text!' );
95
96 if ( $wgContentHandlerTextFallback == 'fail' ) {
97 throw new MWException(
98 "Attempt to get text from Content with model " .
99 $content->getModel()
100 );
101 }
102
103 if ( $wgContentHandlerTextFallback == 'serialize' ) {
104 return $content->serialize();
105 }
106
107 return null;
108 }
109
133 public static function makeContent( $text, Title $title = null,
134 $modelId = null, $format = null ) {
135 if ( is_null( $modelId ) ) {
136 if ( is_null( $title ) ) {
137 throw new MWException( "Must provide a Title object or a content model ID." );
138 }
139
140 $modelId = $title->getContentModel();
141 }
142
143 $handler = self::getForModelID( $modelId );
144
145 return $handler->unserializeContent( $text, $format );
146 }
147
184 public static function getDefaultModelFor( Title $title ) {
185 $slotRoleregistry = MediaWikiServices::getInstance()->getSlotRoleRegistry();
186 $mainSlotHandler = $slotRoleregistry->getRoleHandler( 'main' );
187 return $mainSlotHandler->getDefaultModel( $title );
188 }
189
199 public static function getForTitle( Title $title ) {
200 $modelId = $title->getContentModel();
201
202 return self::getForModelID( $modelId );
203 }
204
215 public static function getForContent( Content $content ) {
216 $modelId = $content->getModel();
217
218 return self::getForModelID( $modelId );
219 }
220
224 protected static $handlers;
225
252 public static function getForModelID( $modelId ) {
253 global $wgContentHandlers;
254
255 if ( isset( self::$handlers[$modelId] ) ) {
256 return self::$handlers[$modelId];
257 }
258
259 if ( empty( $wgContentHandlers[$modelId] ) ) {
260 $handler = null;
261
262 Hooks::run( 'ContentHandlerForModelID', [ $modelId, &$handler ] );
263
264 if ( $handler === null ) {
265 throw new MWUnknownContentModelException( $modelId );
266 }
267
268 if ( !( $handler instanceof ContentHandler ) ) {
269 throw new MWException( "ContentHandlerForModelID must supply a ContentHandler instance" );
270 }
271 } else {
272 $classOrCallback = $wgContentHandlers[$modelId];
273
274 if ( is_callable( $classOrCallback ) ) {
275 $handler = call_user_func( $classOrCallback, $modelId );
276 } else {
277 $handler = new $classOrCallback( $modelId );
278 }
279
280 if ( !( $handler instanceof ContentHandler ) ) {
281 throw new MWException( "$classOrCallback from \$wgContentHandlers is not " .
282 "compatible with ContentHandler" );
283 }
284 }
285
286 wfDebugLog( 'ContentHandler', 'Created handler for ' . $modelId
287 . ': ' . get_class( $handler ) );
288
289 self::$handlers[$modelId] = $handler;
290
291 return self::$handlers[$modelId];
292 }
293
297 public static function cleanupHandlersCache() {
298 self::$handlers = [];
299 }
300
314 public static function getLocalizedName( $name, Language $lang = null ) {
315 // Messages: content-model-wikitext, content-model-text,
316 // content-model-javascript, content-model-css
317 $key = "content-model-$name";
318
319 $msg = wfMessage( $key );
320 if ( $lang ) {
321 $msg->inLanguage( $lang );
322 }
323
324 return $msg->exists() ? $msg->plain() : $name;
325 }
326
327 public static function getContentModels() {
328 global $wgContentHandlers;
329
330 $models = array_keys( $wgContentHandlers );
331 Hooks::run( 'GetContentModels', [ &$models ] );
332 return $models;
333 }
334
335 public static function getAllContentFormats() {
336 global $wgContentHandlers;
337
338 $formats = [];
339
340 foreach ( $wgContentHandlers as $model => $class ) {
341 $handler = self::getForModelID( $model );
342 $formats = array_merge( $formats, $handler->getSupportedFormats() );
343 }
344
345 $formats = array_unique( $formats );
346
347 return $formats;
348 }
349
350 // ------------------------------------------------------------------------
351
355 protected $mModelID;
356
361
371 public function __construct( $modelId, $formats ) {
372 $this->mModelID = $modelId;
373 $this->mSupportedFormats = $formats;
374 }
375
386 abstract public function serializeContent( Content $content, $format = null );
387
398 public function exportTransform( $blob, $format = null ) {
399 return $blob;
400 }
401
412 abstract public function unserializeContent( $blob, $format = null );
413
425 public function importTransform( $blob, $format = null ) {
426 return $blob;
427 }
428
437 abstract public function makeEmptyContent();
438
456 public function makeRedirectContent( Title $destination, $text = '' ) {
457 return null;
458 }
459
468 public function getModelID() {
469 return $this->mModelID;
470 }
471
480 protected function checkModelID( $model_id ) {
481 if ( $model_id !== $this->mModelID ) {
482 throw new MWException( "Bad content model: " .
483 "expected {$this->mModelID} " .
484 "but got $model_id." );
485 }
486 }
487
497 public function getSupportedFormats() {
498 return $this->mSupportedFormats;
499 }
500
512 public function getDefaultFormat() {
513 return $this->mSupportedFormats[0];
514 }
515
529 public function isSupportedFormat( $format ) {
530 if ( !$format ) {
531 return true; // this means "use the default"
532 }
533
534 return in_array( $format, $this->mSupportedFormats );
535 }
536
544 protected function checkFormat( $format ) {
545 if ( !$this->isSupportedFormat( $format ) ) {
546 throw new MWException(
547 "Format $format is not supported for content model "
548 . $this->getModelID()
549 );
550 }
551 }
552
568 public function getActionOverrides() {
569 return [];
570 }
571
599 public function createDifferenceEngine( IContextSource $context, $old = 0, $new = 0,
600 $rcid = 0, // FIXME: Deprecated, no longer used
601 $refreshCache = false, $unhide = false
602 ) {
603 $diffEngineClass = $this->getDiffEngineClass();
604 $differenceEngine = new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide );
605 Hooks::run( 'GetDifferenceEngine', [ $context, $old, $new, $refreshCache, $unhide,
607 return $differenceEngine;
608 }
609
616 final public function getSlotDiffRenderer( IContextSource $context ) {
617 $slotDiffRenderer = $this->getSlotDiffRendererInternal( $context );
618 if ( get_class( $slotDiffRenderer ) === TextSlotDiffRenderer::class ) {
619 // To keep B/C, when SlotDiffRenderer is not overridden for a given content type
620 // but DifferenceEngine is, use that instead.
622 if ( get_class( $differenceEngine ) !== DifferenceEngine::class ) {
623 // TODO turn this into a deprecation warning in a later release
624 LoggerFactory::getInstance( 'diff' )->info(
625 'Falling back to DifferenceEngineSlotDiffRenderer', [
626 'modelID' => $this->getModelID(),
627 'DifferenceEngine' => get_class( $differenceEngine ),
628 ] );
629 $slotDiffRenderer = new DifferenceEngineSlotDiffRenderer( $differenceEngine );
630 }
631 }
632 Hooks::run( 'GetSlotDiffRenderer', [ $this, &$slotDiffRenderer, $context ] );
633 return $slotDiffRenderer;
634 }
635
642 $contentLanguage = MediaWikiServices::getInstance()->getContentLanguage();
643 $statsdDataFactory = MediaWikiServices::getInstance()->getStatsdDataFactory();
644 $slotDiffRenderer = new TextSlotDiffRenderer();
645 $slotDiffRenderer->setStatsdDataFactory( $statsdDataFactory );
646 // XXX using the page language would be better, but it's unclear how that should be injected
647 $slotDiffRenderer->setLanguage( $contentLanguage );
648 $slotDiffRenderer->setWikiDiff2MovedParagraphDetectionCutoff(
649 $context->getConfig()->get( 'WikiDiff2MovedParagraphDetectionCutoff' )
650 );
651
653 if ( $engine === false ) {
654 $slotDiffRenderer->setEngine( TextSlotDiffRenderer::ENGINE_PHP );
655 } elseif ( $engine === 'wikidiff2' ) {
656 $slotDiffRenderer->setEngine( TextSlotDiffRenderer::ENGINE_WIKIDIFF2 );
657 } else {
658 $slotDiffRenderer->setEngine( TextSlotDiffRenderer::ENGINE_EXTERNAL, $engine );
659 }
660
661 return $slotDiffRenderer;
662 }
663
683 public function getPageLanguage( Title $title, Content $content = null ) {
684 global $wgLang;
685 $pageLang = MediaWikiServices::getInstance()->getContentLanguage();
686
687 if ( $title->inNamespace( NS_MEDIAWIKI ) ) {
688 // Parse mediawiki messages with correct target language
689 list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $title->getText() );
690 $pageLang = Language::factory( $lang );
691 }
692
693 Hooks::run( 'PageContentLanguage', [ $title, &$pageLang, $wgLang ] );
694
695 return wfGetLangObj( $pageLang );
696 }
697
718 public function getPageViewLanguage( Title $title, Content $content = null ) {
719 $pageLang = $this->getPageLanguage( $title, $content );
720
721 if ( $title->getNamespace() !== NS_MEDIAWIKI ) {
722 // If the user chooses a variant, the content is actually
723 // in a language whose code is the variant code.
724 $variant = $pageLang->getPreferredVariant();
725 if ( $pageLang->getCode() !== $variant ) {
726 $pageLang = Language::factory( $variant );
727 }
728 }
729
730 return $pageLang;
731 }
732
751 public function canBeUsedOn( Title $title ) {
752 $ok = true;
753
754 Hooks::run( 'ContentModelCanBeUsedOn', [ $this->getModelID(), $title, &$ok ] );
755
756 return $ok;
757 }
758
766 protected function getDiffEngineClass() {
767 return DifferenceEngine::class;
768 }
769
784 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
785 return false;
786 }
787
799 private function getChangeType(
800 Content $oldContent = null,
801 Content $newContent = null,
802 $flags = 0
803 ) {
804 $oldTarget = $oldContent !== null ? $oldContent->getRedirectTarget() : null;
805 $newTarget = $newContent !== null ? $newContent->getRedirectTarget() : null;
806
807 // We check for the type of change in the given edit, and return string key accordingly
808
809 // Blanking of a page
810 if ( $oldContent && $oldContent->getSize() > 0 &&
811 $newContent && $newContent->getSize() === 0
812 ) {
813 return 'blank';
814 }
815
816 // Redirects
817 if ( $newTarget ) {
818 if ( !$oldTarget ) {
819 // New redirect page (by creating new page or by changing content page)
820 return 'new-redirect';
821 } elseif ( !$newTarget->equals( $oldTarget ) ||
822 $oldTarget->getFragment() !== $newTarget->getFragment()
823 ) {
824 // Redirect target changed
825 return 'changed-redirect-target';
826 }
827 } elseif ( $oldTarget ) {
828 // Changing an existing redirect into a non-redirect
829 return 'removed-redirect';
830 }
831
832 // New page created
833 if ( $flags & EDIT_NEW && $newContent ) {
834 if ( $newContent->getSize() === 0 ) {
835 // New blank page
836 return 'newblank';
837 } else {
838 return 'newpage';
839 }
840 }
841
842 // Removing more than 90% of the page
843 if ( $oldContent && $newContent && $oldContent->getSize() > 10 * $newContent->getSize() ) {
844 return 'replace';
845 }
846
847 // Content model changed
848 if ( $oldContent && $newContent && $oldContent->getModel() !== $newContent->getModel() ) {
849 return 'contentmodelchange';
850 }
851
852 return null;
853 }
854
866 public function getAutosummary(
867 Content $oldContent = null,
868 Content $newContent = null,
869 $flags = 0
870 ) {
871 $changeType = $this->getChangeType( $oldContent, $newContent, $flags );
872
873 // There's no applicable auto-summary for our case, so our auto-summary is empty.
874 if ( !$changeType ) {
875 return '';
876 }
877
878 // Decide what kind of auto-summary is needed.
879 switch ( $changeType ) {
880 case 'new-redirect':
881 $newTarget = $newContent->getRedirectTarget();
882 $truncatedtext = $newContent->getTextForSummary(
883 250
884 - strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
885 - strlen( $newTarget->getFullText() )
886 );
887
888 return wfMessage( 'autoredircomment', $newTarget->getFullText() )
889 ->plaintextParams( $truncatedtext )->inContentLanguage()->text();
890 case 'changed-redirect-target':
891 $oldTarget = $oldContent->getRedirectTarget();
892 $newTarget = $newContent->getRedirectTarget();
893
894 $truncatedtext = $newContent->getTextForSummary(
895 250
896 - strlen( wfMessage( 'autosumm-changed-redirect-target' )
897 ->inContentLanguage()->text() )
898 - strlen( $oldTarget->getFullText() )
899 - strlen( $newTarget->getFullText() )
900 );
901
902 return wfMessage( 'autosumm-changed-redirect-target',
903 $oldTarget->getFullText(),
904 $newTarget->getFullText() )
905 ->rawParams( $truncatedtext )->inContentLanguage()->text();
906 case 'removed-redirect':
907 $oldTarget = $oldContent->getRedirectTarget();
908 $truncatedtext = $newContent->getTextForSummary(
909 250
910 - strlen( wfMessage( 'autosumm-removed-redirect' )
911 ->inContentLanguage()->text() )
912 - strlen( $oldTarget->getFullText() ) );
913
914 return wfMessage( 'autosumm-removed-redirect', $oldTarget->getFullText() )
915 ->rawParams( $truncatedtext )->inContentLanguage()->text();
916 case 'newpage':
917 // If they're making a new article, give its text, truncated, in the summary.
918 $truncatedtext = $newContent->getTextForSummary(
919 200 - strlen( wfMessage( 'autosumm-new' )->inContentLanguage()->text() ) );
920
921 return wfMessage( 'autosumm-new' )->rawParams( $truncatedtext )
922 ->inContentLanguage()->text();
923 case 'blank':
924 return wfMessage( 'autosumm-blank' )->inContentLanguage()->text();
925 case 'replace':
926 $truncatedtext = $newContent->getTextForSummary(
927 200 - strlen( wfMessage( 'autosumm-replace' )->inContentLanguage()->text() ) );
928
929 return wfMessage( 'autosumm-replace' )->rawParams( $truncatedtext )
930 ->inContentLanguage()->text();
931 case 'newblank':
932 return wfMessage( 'autosumm-newblank' )->inContentLanguage()->text();
933 default:
934 return '';
935 }
936 }
937
949 public function getChangeTag(
950 Content $oldContent = null,
951 Content $newContent = null,
952 $flags = 0
953 ) {
954 $changeType = $this->getChangeType( $oldContent, $newContent, $flags );
955
956 // There's no applicable tag for this change.
957 if ( !$changeType ) {
958 return null;
959 }
960
961 // Core tags use the same keys as ones returned from $this->getChangeType()
962 // but prefixed with pseudo namespace 'mw-', so we add the prefix before checking
963 // if this type of change should be tagged
964 $tag = 'mw-' . $changeType;
965
966 // Not all change types are tagged, so we check against the list of defined tags.
967 if ( in_array( $tag, ChangeTags::getSoftwareTags() ) ) {
968 return $tag;
969 }
970
971 return null;
972 }
973
989 public function getAutoDeleteReason( Title $title, &$hasHistory ) {
991
992 // Get the last revision
994
995 if ( is_null( $rev ) ) {
996 return false;
997 }
998
999 // Get the article's contents
1000 $content = $rev->getContent();
1001 $blank = false;
1002
1003 // If the page is blank, use the text from the previous revision,
1004 // which can only be blank if there's a move/import/protect dummy
1005 // revision involved
1006 if ( !$content || $content->isEmpty() ) {
1007 $prev = $rev->getPrevious();
1008
1009 if ( $prev ) {
1010 $rev = $prev;
1011 $content = $rev->getContent();
1012 $blank = true;
1013 }
1014 }
1015
1016 $this->checkModelID( $rev->getContentModel() );
1017
1018 // Find out if there was only one contributor
1019 // Only scan the last 20 revisions
1021 $res = $dbr->select(
1022 $revQuery['tables'],
1023 [ 'rev_user_text' => $revQuery['fields']['rev_user_text'] ],
1024 [
1025 'rev_page' => $title->getArticleID(),
1026 $dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0'
1027 ],
1028 __METHOD__,
1029 [ 'LIMIT' => 20 ],
1030 $revQuery['joins']
1031 );
1032
1033 if ( $res === false ) {
1034 // This page has no revisions, which is very weird
1035 return false;
1036 }
1037
1038 $hasHistory = ( $res->numRows() > 1 );
1039 $row = $dbr->fetchObject( $res );
1040
1041 if ( $row ) { // $row is false if the only contributor is hidden
1042 $onlyAuthor = $row->rev_user_text;
1043 // Try to find a second contributor
1044 foreach ( $res as $row ) {
1045 if ( $row->rev_user_text != $onlyAuthor ) { // T24999
1046 $onlyAuthor = false;
1047 break;
1048 }
1049 }
1050 } else {
1051 $onlyAuthor = false;
1052 }
1053
1054 // Generate the summary with a '$1' placeholder
1055 if ( $blank ) {
1056 // The current revision is blank and the one before is also
1057 // blank. It's just not our lucky day
1058 $reason = wfMessage( 'exbeforeblank', '$1' )->inContentLanguage()->text();
1059 } else {
1060 if ( $onlyAuthor ) {
1061 $reason = wfMessage(
1062 'excontentauthor',
1063 '$1',
1064 $onlyAuthor
1065 )->inContentLanguage()->text();
1066 } else {
1067 $reason = wfMessage( 'excontent', '$1' )->inContentLanguage()->text();
1068 }
1069 }
1070
1071 if ( $reason == '-' ) {
1072 // Allow these UI messages to be blanked out cleanly
1073 return '';
1074 }
1075
1076 // Max content length = max comment length - length of the comment (excl. $1)
1077 $text = $content ? $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) ) : '';
1078
1079 // Now replace the '$1' placeholder
1080 $reason = str_replace( '$1', $text, $reason );
1081
1082 return $reason;
1083 }
1084
1101 public function getUndoContent( $current, $undo, $undoafter, $undoIsLatest = false ) {
1102 Assert::parameterType( Revision::class . '|' . Content::class, $current, '$current' );
1103 if ( $current instanceof Content ) {
1104 Assert::parameter( $undo instanceof Content, '$undo',
1105 'Must be Content when $current is Content' );
1106 Assert::parameter( $undoafter instanceof Content, '$undoafter',
1107 'Must be Content when $current is Content' );
1108 $cur_content = $current;
1109 $undo_content = $undo;
1110 $undoafter_content = $undoafter;
1111 } else {
1112 Assert::parameter( $undo instanceof Revision, '$undo',
1113 'Must be Revision when $current is Revision' );
1114 Assert::parameter( $undoafter instanceof Revision, '$undoafter',
1115 'Must be Revision when $current is Revision' );
1116
1117 $cur_content = $current->getContent();
1118
1119 if ( empty( $cur_content ) ) {
1120 return false; // no page
1121 }
1122
1123 $undo_content = $undo->getContent();
1124 $undoafter_content = $undoafter->getContent();
1125
1126 if ( !$undo_content || !$undoafter_content ) {
1127 return false; // no content to undo
1128 }
1129
1130 $undoIsLatest = $current->getId() === $undo->getId();
1131 }
1132
1133 try {
1134 $this->checkModelID( $cur_content->getModel() );
1135 $this->checkModelID( $undo_content->getModel() );
1136 if ( !$undoIsLatest ) {
1137 // If we are undoing the most recent revision,
1138 // its ok to revert content model changes. However
1139 // if we are undoing a revision in the middle, then
1140 // doing that will be confusing.
1141 $this->checkModelID( $undoafter_content->getModel() );
1142 }
1143 } catch ( MWException $e ) {
1144 // If the revisions have different content models
1145 // just return false
1146 return false;
1147 }
1148
1149 if ( $cur_content->equals( $undo_content ) ) {
1150 // No use doing a merge if it's just a straight revert.
1151 return $undoafter_content;
1152 }
1153
1154 $undone_content = $this->merge3( $undo_content, $undoafter_content, $cur_content );
1155
1156 return $undone_content;
1157 }
1158
1175 public function makeParserOptions( $context ) {
1176 wfDeprecated( __METHOD__, '1.32' );
1177 return ParserOptions::newCanonical( $context );
1178 }
1179
1188 public function isParserCacheSupported() {
1189 return false;
1190 }
1191
1201 public function supportsSections() {
1202 return false;
1203 }
1204
1211 public function supportsCategories() {
1212 return true;
1213 }
1214
1224 public function supportsRedirects() {
1225 return false;
1226 }
1227
1233 public function supportsDirectEditing() {
1234 return false;
1235 }
1236
1242 public function supportsDirectApiEditing() {
1243 return $this->supportsDirectEditing();
1244 }
1245
1257 $fields['category'] = $engine->makeSearchFieldMapping(
1258 'category',
1260 );
1261 $fields['category']->setFlag( SearchIndexField::FLAG_CASEFOLD );
1262
1263 $fields['external_link'] = $engine->makeSearchFieldMapping(
1264 'external_link',
1266 );
1267
1268 $fields['outgoing_link'] = $engine->makeSearchFieldMapping(
1269 'outgoing_link',
1271 );
1272
1273 $fields['template'] = $engine->makeSearchFieldMapping(
1274 'template',
1276 );
1277 $fields['template']->setFlag( SearchIndexField::FLAG_CASEFOLD );
1278
1279 $fields['content_model'] = $engine->makeSearchFieldMapping(
1280 'content_model',
1282 );
1283
1284 return $fields;
1285 }
1286
1296 protected function addSearchField( &$fields, SearchEngine $engine, $name, $type ) {
1297 $fields[$name] = $engine->makeSearchFieldMapping( $name, $type );
1298 return $fields;
1299 }
1300
1312 public function getDataForSearchIndex(
1313 WikiPage $page,
1316 ) {
1317 $fieldData = [];
1318 $content = $page->getContent();
1319
1320 if ( $content ) {
1321 $searchDataExtractor = new ParserOutputSearchDataExtractor();
1322
1323 $fieldData['category'] = $searchDataExtractor->getCategories( $output );
1324 $fieldData['external_link'] = $searchDataExtractor->getExternalLinks( $output );
1325 $fieldData['outgoing_link'] = $searchDataExtractor->getOutgoingLinks( $output );
1326 $fieldData['template'] = $searchDataExtractor->getTemplates( $output );
1327
1328 $text = $content->getTextForSearchIndex();
1329
1330 $fieldData['text'] = $text;
1331 $fieldData['source_text'] = $text;
1332 $fieldData['text_bytes'] = $content->getSize();
1333 $fieldData['content_model'] = $content->getModel();
1334 }
1335
1336 Hooks::run( 'SearchDataForIndex', [ &$fieldData, $this, $page, $output, $engine ] );
1337 return $fieldData;
1338 }
1339
1349 public function getParserOutputForIndexing( WikiPage $page, ParserCache $cache = null ) {
1350 // TODO: MCR: ContentHandler should be called per slot, not for the whole page.
1351 // See T190066.
1352 $parserOptions = $page->makeParserOptions( 'canonical' );
1353 if ( $cache ) {
1354 $parserOutput = $cache->get( $page, $parserOptions );
1355 }
1356
1357 if ( empty( $parserOutput ) ) {
1358 $renderer = MediaWikiServices::getInstance()->getRevisionRenderer();
1359 $parserOutput =
1360 $renderer->getRenderedRevision(
1361 $page->getRevision()->getRevisionRecord(),
1362 $parserOptions
1363 )->getRevisionParserOutput();
1364 if ( $cache ) {
1365 $cache->save( $parserOutput, $page, $parserOptions );
1366 }
1367 }
1368 return $parserOutput;
1369 }
1370
1402 Title $title,
1404 $role,
1405 SlotRenderingProvider $slotOutput
1406 ) {
1407 return [];
1408 }
1409
1438 public function getDeletionUpdates( Title $title, $role ) {
1439 return [];
1440 }
1441
1442}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
$wgContentHandlerTextFallback
How to react if a plain text version of a non-text Content object is requested using ContentHandler::...
$wgContentHandlers
Plugins for page content model handling.
wfGetLangObj( $langcode=false)
Return a Language object from $langcode.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
$wgLang
Definition Setup.php:875
static getSoftwareTags( $all=false)
Loads defined core tags, checks for invalid types (if not array), and filters for supported and enabl...
A content handler knows how do deal with a specific type of content on a wiki page.
getParserOutputForIndexing(WikiPage $page, ParserCache $cache=null)
Produce page output suitable for indexing.
getModelID()
Returns the model id that identifies the content model this ContentHandler can handle.
makeRedirectContent(Title $destination, $text='')
Creates a new Content object that acts as a redirect to the given page, or null if redirects are not ...
__construct( $modelId, $formats)
Constructor, initializing the ContentHandler instance with its model ID and a list of supported forma...
static getAllContentFormats()
string[] $mSupportedFormats
getChangeType(Content $oldContent=null, Content $newContent=null, $flags=0)
Return type of change if one exists for the given edit.
checkModelID( $model_id)
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
importTransform( $blob, $format=null)
Apply import transformation (per default, returns $blob unchanged).
isParserCacheSupported()
Returns true for content models that support caching using the ParserCache mechanism.
static getForModelID( $modelId)
Returns the ContentHandler singleton for the given model ID.
supportsDirectApiEditing()
Whether or not this content model supports direct editing via ApiEditPage.
getAutoDeleteReason(Title $title, &$hasHistory)
Auto-generates a deletion reason.
getChangeTag(Content $oldContent=null, Content $newContent=null, $flags=0)
Return an applicable tag if one exists for the given edit or return null.
getDiffEngineClass()
Returns the name of the diff engine to use.
static getForTitle(Title $title)
Returns the appropriate ContentHandler singleton for the given title.
exportTransform( $blob, $format=null)
Applies transformations on export (returns the blob unchanged per default).
merge3(Content $oldContent, Content $myContent, Content $yourContent)
Attempts to merge differences between three versions.
getAutosummary(Content $oldContent=null, Content $newContent=null, $flags=0)
Return an applicable auto-summary if one exists for the given edit.
checkFormat( $format)
Convenient for checking whether a format provided as a parameter is actually supported.
addSearchField(&$fields, SearchEngine $engine, $name, $type)
Add new field definition to array.
getActionOverrides()
Returns overrides for action handlers.
createDifferenceEngine(IContextSource $context, $old=0, $new=0, $rcid=0, $refreshCache=false, $unhide=false)
Factory for creating an appropriate DifferenceEngine for this content model.
getSecondaryDataUpdates(Title $title, Content $content, $role, SlotRenderingProvider $slotOutput)
Returns a list of DeferrableUpdate objects for recording information about the given Content in some ...
static getContentModels()
getPageLanguage(Title $title, Content $content=null)
Get the language in which the content of the given page is written.
getDefaultFormat()
The format used for serialization/deserialization by default by this ContentHandler.
getSlotDiffRendererInternal(IContextSource $context)
Return the SlotDiffRenderer appropriate for this content handler.
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
unserializeContent( $blob, $format=null)
Unserializes a Content object of the type supported by this ContentHandler.
static getLocalizedName( $name, Language $lang=null)
Returns the localized name for a given content model.
supportsDirectEditing()
Return true if this content model supports direct editing, such as via EditPage.
getDeletionUpdates(Title $title, $role)
Returns a list of DeferrableUpdate objects for removing information about content in some secondary d...
isSupportedFormat( $format)
Returns true if $format is a serialization format supported by this ContentHandler,...
getSupportedFormats()
Returns a list of serialization formats supported by the serializeContent() and unserializeContent() ...
supportsSections()
Returns true if this content model supports sections.
getSlotDiffRenderer(IContextSource $context)
Get an appropriate SlotDiffRenderer for this content model.
static cleanupHandlersCache()
Clean up handlers cache.
static getContentText(Content $content=null)
Convenience function for getting flat text from a Content object.
getDataForSearchIndex(WikiPage $page, ParserOutput $output, SearchEngine $engine)
Return fields to be indexed by search engine as representation of this document.
supportsCategories()
Returns true if this content model supports categories.
static getForContent(Content $content)
Returns the appropriate ContentHandler singleton for the given Content object.
supportsRedirects()
Returns true if this content model supports redirects.
canBeUsedOn(Title $title)
Determines whether the content type handled by this ContentHandler can be used for the main slot of t...
serializeContent(Content $content, $format=null)
Serializes a Content object of the type supported by this ContentHandler.
makeEmptyContent()
Creates an empty Content object of the type supported by this ContentHandler.
static array $handlers
A Cache of ContentHandler instances by model id.
makeParserOptions( $context)
Get parser options suitable for rendering and caching the article.
getFieldsForSearchIndex(SearchEngine $engine)
Get fields definition for search index.
getUndoContent( $current, $undo, $undoafter, $undoIsLatest=false)
Get the Content object that needs to be saved in order to undo all revisions between $undo and $undoa...
getPageViewLanguage(Title $title, Content $content=null)
Get the language in which the content of this page is written when viewed by user.
B/C adapter for turning a DifferenceEngine into a SlotDiffRenderer.
static getEngine()
Process $wgExternalDiffEngine and get a sane, usable engine.
Internationalisation code.
Definition Language.php:36
MediaWiki exception.
Exception thrown when an unregistered content model is requested.
PSR-3 logger instance factory.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Extracts data from ParserOutput for indexing in the search engine.
const DELETED_USER
Definition Revision.php:48
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Definition Revision.php:511
static newFromTitle(LinkTarget $linkTarget, $id=0, $flags=0)
Load either the current, or a specified, revision that's attached to a given link target.
Definition Revision.php:137
Contain a class for special pages.
Content object implementation for representing flat text.
Renders a slot diff by doing a text diff on the native representation.
const ENGINE_PHP
Use the PHP diff implementation (DiffEngine).
const ENGINE_EXTERNAL
Use an external executable.
const ENGINE_WIKIDIFF2
Use the wikidiff2 PHP module.
Represents a title within MediaWiki.
Definition Title.php:40
Class representing a MediaWiki article and history.
Definition WikiPage.php:45
getRevision()
Get the latest revision.
Definition WikiPage.php:783
makeParserOptions( $context)
Get parser options suitable for rendering the primary article wikitext.
getContent( $audience=Revision::FOR_PUBLIC, User $user=null)
Get the content of the current revision.
Definition WikiPage.php:816
$res
Definition database.txt:21
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
Definition deferred.txt:11
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
const NS_MEDIAWIKI
Definition Defines.php:81
const EDIT_NEW
Definition Defines.php:161
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify as strings Extensions should add to this list prev or next $refreshCache
Definition hooks.txt:1628
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify as strings Extensions should add to this list prev or next refreshes the diff cache $unhide
Definition hooks.txt:1629
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition hooks.txt:894
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2848
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify as strings Extensions should add to this list prev or next refreshes the diff cache allow viewing deleted revs & $differenceEngine
Definition hooks.txt:1639
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 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 "&lt;div ...>$1&lt;/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
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:271
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition hooks.txt:2925
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2272
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:1779
returning false will NOT prevent logging $e
Definition hooks.txt:2175
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
Base interface for content objects.
Definition Content.php:34
Interface for objects which can provide a MediaWiki context on request.
A lazy provider of ParserOutput objects for a revision's individual slots.
const INDEX_TYPE_TEXT
TEXT fields are suitable for natural language and may be subject to analysis such as stemming.
const INDEX_TYPE_KEYWORD
KEYWORD fields are indexed without any processing, so are appropriate for e.g.
const FLAG_CASEFOLD
Generic field flags.
$cache
Definition mcc.php:33
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))
$content
const DB_REPLICA
Definition defines.php:25
if(!isset( $args[0])) $lang