MediaWiki REL1_28
ContentHandler.php
Go to the documentation of this file.
1<?php
2
4
38
49 private $modelId;
50
52 function __construct( $modelId ) {
53 parent::__construct( "The content model '$modelId' is not registered on this wiki.\n" .
54 'See https://www.mediawiki.org/wiki/Content_handlers to find out which extensions ' .
55 'handle this content model.' );
56 $this->modelId = $modelId;
57 }
58
60 public function getModelId() {
61 return $this->modelId;
62 }
63}
64
84abstract class ContentHandler {
114 public static function getContentText( Content $content = null ) {
116
117 if ( is_null( $content ) ) {
118 return '';
119 }
120
121 if ( $content instanceof TextContent ) {
122 return $content->getNativeData();
123 }
124
125 wfDebugLog( 'ContentHandler', 'Accessing ' . $content->getModel() . ' content as text!' );
126
127 if ( $wgContentHandlerTextFallback == 'fail' ) {
128 throw new MWException(
129 "Attempt to get text from Content with model " .
130 $content->getModel()
131 );
132 }
133
134 if ( $wgContentHandlerTextFallback == 'serialize' ) {
135 return $content->serialize();
136 }
137
138 return null;
139 }
140
164 public static function makeContent( $text, Title $title = null,
165 $modelId = null, $format = null ) {
166 if ( is_null( $modelId ) ) {
167 if ( is_null( $title ) ) {
168 throw new MWException( "Must provide a Title object or a content model ID." );
169 }
170
171 $modelId = $title->getContentModel();
172 }
173
175
176 return $handler->unserializeContent( $text, $format );
177 }
178
213 public static function getDefaultModelFor( Title $title ) {
214 // NOTE: this method must not rely on $title->getContentModel() directly or indirectly,
215 // because it is used to initialize the mContentModel member.
216
217 $ns = $title->getNamespace();
218
219 $ext = false;
220 $m = null;
221 $model = MWNamespace::getNamespaceContentModel( $ns );
222
223 // Hook can determine default model
224 if ( !Hooks::run( 'ContentHandlerDefaultModelFor', [ $title, &$model ] ) ) {
225 if ( !is_null( $model ) ) {
226 return $model;
227 }
228 }
229
230 // Could this page contain code based on the title?
231 $isCodePage = NS_MEDIAWIKI == $ns && preg_match( '!\.(css|js|json)$!u', $title->getText(), $m );
232 if ( $isCodePage ) {
233 $ext = $m[1];
234 }
235
236 // Hook can force JS/CSS
237 Hooks::run( 'TitleIsCssOrJsPage', [ $title, &$isCodePage ], '1.21' );
238
239 // Is this a user subpage containing code?
240 $isCodeSubpage = NS_USER == $ns
241 && !$isCodePage
242 && preg_match( "/\\/.*\\.(js|css|json)$/", $title->getText(), $m );
243 if ( $isCodeSubpage ) {
244 $ext = $m[1];
245 }
246
247 // Is this wikitext, according to $wgNamespaceContentModels or the DefaultModelFor hook?
248 $isWikitext = is_null( $model ) || $model == CONTENT_MODEL_WIKITEXT;
249 $isWikitext = $isWikitext && !$isCodePage && !$isCodeSubpage;
250
251 // Hook can override $isWikitext
252 Hooks::run( 'TitleIsWikitextPage', [ $title, &$isWikitext ], '1.21' );
253
254 if ( !$isWikitext ) {
255 switch ( $ext ) {
256 case 'js':
258 case 'css':
259 return CONTENT_MODEL_CSS;
260 case 'json':
261 return CONTENT_MODEL_JSON;
262 default:
263 return is_null( $model ) ? CONTENT_MODEL_TEXT : $model;
264 }
265 }
266
267 // We established that it must be wikitext
268
270 }
271
281 public static function getForTitle( Title $title ) {
282 $modelId = $title->getContentModel();
283
284 return ContentHandler::getForModelID( $modelId );
285 }
286
297 public static function getForContent( Content $content ) {
298 $modelId = $content->getModel();
299
300 return ContentHandler::getForModelID( $modelId );
301 }
302
306 protected static $handlers;
307
334 public static function getForModelID( $modelId ) {
336
337 if ( isset( ContentHandler::$handlers[$modelId] ) ) {
338 return ContentHandler::$handlers[$modelId];
339 }
340
341 if ( empty( $wgContentHandlers[$modelId] ) ) {
342 $handler = null;
343
344 Hooks::run( 'ContentHandlerForModelID', [ $modelId, &$handler ] );
345
346 if ( $handler === null ) {
347 throw new MWUnknownContentModelException( $modelId );
348 }
349
350 if ( !( $handler instanceof ContentHandler ) ) {
351 throw new MWException( "ContentHandlerForModelID must supply a ContentHandler instance" );
352 }
353 } else {
354 $classOrCallback = $wgContentHandlers[$modelId];
355
356 if ( is_callable( $classOrCallback ) ) {
357 $handler = call_user_func( $classOrCallback, $modelId );
358 } else {
359 $handler = new $classOrCallback( $modelId );
360 }
361
362 if ( !( $handler instanceof ContentHandler ) ) {
363 throw new MWException( "$classOrCallback from \$wgContentHandlers is not " .
364 "compatible with ContentHandler" );
365 }
366 }
367
368 wfDebugLog( 'ContentHandler', 'Created handler for ' . $modelId
369 . ': ' . get_class( $handler ) );
370
372
373 return ContentHandler::$handlers[$modelId];
374 }
375
389 public static function getLocalizedName( $name, Language $lang = null ) {
390 // Messages: content-model-wikitext, content-model-text,
391 // content-model-javascript, content-model-css
392 $key = "content-model-$name";
393
394 $msg = wfMessage( $key );
395 if ( $lang ) {
396 $msg->inLanguage( $lang );
397 }
398
399 return $msg->exists() ? $msg->plain() : $name;
400 }
401
402 public static function getContentModels() {
404
405 return array_keys( $wgContentHandlers );
406 }
407
408 public static function getAllContentFormats() {
410
411 $formats = [];
412
413 foreach ( $wgContentHandlers as $model => $class ) {
415 $formats = array_merge( $formats, $handler->getSupportedFormats() );
416 }
417
418 $formats = array_unique( $formats );
419
420 return $formats;
421 }
422
423 // ------------------------------------------------------------------------
424
428 protected $mModelID;
429
434
444 public function __construct( $modelId, $formats ) {
445 $this->mModelID = $modelId;
446 $this->mSupportedFormats = $formats;
447 }
448
459 abstract public function serializeContent( Content $content, $format = null );
460
471 public function exportTransform( $blob, $format = null ) {
472 return $blob;
473 }
474
485 abstract public function unserializeContent( $blob, $format = null );
486
498 public function importTransform( $blob, $format = null ) {
499 return $blob;
500 }
501
510 abstract public function makeEmptyContent();
511
529 public function makeRedirectContent( Title $destination, $text = '' ) {
530 return null;
531 }
532
541 public function getModelID() {
542 return $this->mModelID;
543 }
544
553 protected function checkModelID( $model_id ) {
554 if ( $model_id !== $this->mModelID ) {
555 throw new MWException( "Bad content model: " .
556 "expected {$this->mModelID} " .
557 "but got $model_id." );
558 }
559 }
560
570 public function getSupportedFormats() {
572 }
573
585 public function getDefaultFormat() {
586 return $this->mSupportedFormats[0];
587 }
588
602 public function isSupportedFormat( $format ) {
603 if ( !$format ) {
604 return true; // this means "use the default"
605 }
606
607 return in_array( $format, $this->mSupportedFormats );
608 }
609
617 protected function checkFormat( $format ) {
618 if ( !$this->isSupportedFormat( $format ) ) {
619 throw new MWException(
620 "Format $format is not supported for content model "
621 . $this->getModelID()
622 );
623 }
624 }
625
641 public function getActionOverrides() {
642 return [];
643 }
644
659 public function createDifferenceEngine( IContextSource $context, $old = 0, $new = 0,
660 $rcid = 0, // FIXME: Deprecated, no longer used
661 $refreshCache = false, $unhide = false ) {
662
663 // hook: get difference engine
664 $differenceEngine = null;
665 if ( !Hooks::run( 'GetDifferenceEngine',
667 ) ) {
668 return $differenceEngine;
669 }
670 $diffEngineClass = $this->getDiffEngineClass();
671 return new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide );
672 }
673
693 public function getPageLanguage( Title $title, Content $content = null ) {
695 $pageLang = $wgContLang;
696
697 if ( $title->getNamespace() == NS_MEDIAWIKI ) {
698 // Parse mediawiki messages with correct target language
699 list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $title->getText() );
700 $pageLang = Language::factory( $lang );
701 }
702
703 Hooks::run( 'PageContentLanguage', [ $title, &$pageLang, $wgLang ] );
704
705 return wfGetLangObj( $pageLang );
706 }
707
728 public function getPageViewLanguage( Title $title, Content $content = null ) {
729 $pageLang = $this->getPageLanguage( $title, $content );
730
731 if ( $title->getNamespace() !== NS_MEDIAWIKI ) {
732 // If the user chooses a variant, the content is actually
733 // in a language whose code is the variant code.
734 $variant = $pageLang->getPreferredVariant();
735 if ( $pageLang->getCode() !== $variant ) {
736 $pageLang = Language::factory( $variant );
737 }
738 }
739
740 return $pageLang;
741 }
742
759 public function canBeUsedOn( Title $title ) {
760 $ok = true;
761
762 Hooks::run( 'ContentModelCanBeUsedOn', [ $this->getModelID(), $title, &$ok ] );
763
764 return $ok;
765 }
766
774 protected function getDiffEngineClass() {
775 return DifferenceEngine::class;
776 }
777
792 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
793 return false;
794 }
795
807 public function getAutosummary( Content $oldContent = null, Content $newContent = null,
808 $flags ) {
809 // Decide what kind of auto-summary is needed.
810
811 // Redirect auto-summaries
812
818 $ot = !is_null( $oldContent ) ? $oldContent->getRedirectTarget() : null;
819 $rt = !is_null( $newContent ) ? $newContent->getRedirectTarget() : null;
820
821 if ( is_object( $rt ) ) {
822 if ( !is_object( $ot )
823 || !$rt->equals( $ot )
824 || $ot->getFragment() != $rt->getFragment()
825 ) {
826 $truncatedtext = $newContent->getTextForSummary(
827 250
828 - strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
829 - strlen( $rt->getFullText() ) );
830
831 return wfMessage( 'autoredircomment', $rt->getFullText() )
832 ->rawParams( $truncatedtext )->inContentLanguage()->text();
833 }
834 }
835
836 // New page auto-summaries
837 if ( $flags & EDIT_NEW && $newContent->getSize() > 0 ) {
838 // If they're making a new article, give its text, truncated, in
839 // the summary.
840
841 $truncatedtext = $newContent->getTextForSummary(
842 200 - strlen( wfMessage( 'autosumm-new' )->inContentLanguage()->text() ) );
843
844 return wfMessage( 'autosumm-new' )->rawParams( $truncatedtext )
845 ->inContentLanguage()->text();
846 }
847
848 // Blanking auto-summaries
849 if ( !empty( $oldContent ) && $oldContent->getSize() > 0 && $newContent->getSize() == 0 ) {
850 return wfMessage( 'autosumm-blank' )->inContentLanguage()->text();
851 } elseif ( !empty( $oldContent )
852 && $oldContent->getSize() > 10 * $newContent->getSize()
853 && $newContent->getSize() < 500
854 ) {
855 // Removing more than 90% of the article
856
857 $truncatedtext = $newContent->getTextForSummary(
858 200 - strlen( wfMessage( 'autosumm-replace' )->inContentLanguage()->text() ) );
859
860 return wfMessage( 'autosumm-replace' )->rawParams( $truncatedtext )
861 ->inContentLanguage()->text();
862 }
863
864 // New blank article auto-summary
865 if ( $flags & EDIT_NEW && $newContent->isEmpty() ) {
866 return wfMessage( 'autosumm-newblank' )->inContentLanguage()->text();
867 }
868
869 // If we reach this point, there's no applicable auto-summary for our
870 // case, so our auto-summary is empty.
871 return '';
872 }
873
889 public function getAutoDeleteReason( Title $title, &$hasHistory ) {
891
892 // Get the last revision
894
895 if ( is_null( $rev ) ) {
896 return false;
897 }
898
899 // Get the article's contents
900 $content = $rev->getContent();
901 $blank = false;
902
903 // If the page is blank, use the text from the previous revision,
904 // which can only be blank if there's a move/import/protect dummy
905 // revision involved
906 if ( !$content || $content->isEmpty() ) {
907 $prev = $rev->getPrevious();
908
909 if ( $prev ) {
910 $rev = $prev;
911 $content = $rev->getContent();
912 $blank = true;
913 }
914 }
915
916 $this->checkModelID( $rev->getContentModel() );
917
918 // Find out if there was only one contributor
919 // Only scan the last 20 revisions
920 $res = $dbr->select( 'revision', 'rev_user_text',
921 [
922 'rev_page' => $title->getArticleID(),
923 $dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0'
924 ],
925 __METHOD__,
926 [ 'LIMIT' => 20 ]
927 );
928
929 if ( $res === false ) {
930 // This page has no revisions, which is very weird
931 return false;
932 }
933
934 $hasHistory = ( $res->numRows() > 1 );
935 $row = $dbr->fetchObject( $res );
936
937 if ( $row ) { // $row is false if the only contributor is hidden
938 $onlyAuthor = $row->rev_user_text;
939 // Try to find a second contributor
940 foreach ( $res as $row ) {
941 if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999
942 $onlyAuthor = false;
943 break;
944 }
945 }
946 } else {
947 $onlyAuthor = false;
948 }
949
950 // Generate the summary with a '$1' placeholder
951 if ( $blank ) {
952 // The current revision is blank and the one before is also
953 // blank. It's just not our lucky day
954 $reason = wfMessage( 'exbeforeblank', '$1' )->inContentLanguage()->text();
955 } else {
956 if ( $onlyAuthor ) {
957 $reason = wfMessage(
958 'excontentauthor',
959 '$1',
960 $onlyAuthor
961 )->inContentLanguage()->text();
962 } else {
963 $reason = wfMessage( 'excontent', '$1' )->inContentLanguage()->text();
964 }
965 }
966
967 if ( $reason == '-' ) {
968 // Allow these UI messages to be blanked out cleanly
969 return '';
970 }
971
972 // Max content length = max comment length - length of the comment (excl. $1)
973 $text = $content ? $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) ) : '';
974
975 // Now replace the '$1' placeholder
976 $reason = str_replace( '$1', $text, $reason );
977
978 return $reason;
979 }
980
994 public function getUndoContent( Revision $current, Revision $undo, Revision $undoafter ) {
995 $cur_content = $current->getContent();
996
997 if ( empty( $cur_content ) ) {
998 return false; // no page
999 }
1000
1001 $undo_content = $undo->getContent();
1002 $undoafter_content = $undoafter->getContent();
1003
1004 if ( !$undo_content || !$undoafter_content ) {
1005 return false; // no content to undo
1006 }
1007
1008 try {
1009 $this->checkModelID( $cur_content->getModel() );
1010 $this->checkModelID( $undo_content->getModel() );
1011 if ( $current->getId() !== $undo->getId() ) {
1012 // If we are undoing the most recent revision,
1013 // its ok to revert content model changes. However
1014 // if we are undoing a revision in the middle, then
1015 // doing that will be confusing.
1016 $this->checkModelID( $undoafter_content->getModel() );
1017 }
1018 } catch ( MWException $e ) {
1019 // If the revisions have different content models
1020 // just return false
1021 return false;
1022 }
1023
1024 if ( $cur_content->equals( $undo_content ) ) {
1025 // No use doing a merge if it's just a straight revert.
1026 return $undoafter_content;
1027 }
1028
1029 $undone_content = $this->merge3( $undo_content, $undoafter_content, $cur_content );
1030
1031 return $undone_content;
1032 }
1033
1048 public function makeParserOptions( $context ) {
1050
1051 if ( $context instanceof IContextSource ) {
1053 } elseif ( $context instanceof User ) { // settings per user (even anons)
1055 } elseif ( $context === 'canonical' ) { // canonical settings
1057 } else {
1058 throw new MWException( "Bad context for parser options: $context" );
1059 }
1060
1061 $options->enableLimitReport( $wgEnableParserLimitReporting ); // show inclusion/loop reports
1062 $options->setTidy( true ); // fix bad HTML
1063
1064 return $options;
1065 }
1066
1075 public function isParserCacheSupported() {
1076 return false;
1077 }
1078
1088 public function supportsSections() {
1089 return false;
1090 }
1091
1098 public function supportsCategories() {
1099 return true;
1100 }
1101
1111 public function supportsRedirects() {
1112 return false;
1113 }
1114
1120 public function supportsDirectEditing() {
1121 return false;
1122 }
1123
1129 public function supportsDirectApiEditing() {
1130 return $this->supportsDirectEditing();
1131 }
1132
1147 public static function runLegacyHooks( $event, $args = [],
1148 $deprecatedVersion = null
1149 ) {
1150
1151 if ( !Hooks::isRegistered( $event ) ) {
1152 return true; // nothing to do here
1153 }
1154
1155 // convert Content objects to text
1156 $contentObjects = [];
1157 $contentTexts = [];
1158
1159 foreach ( $args as $k => $v ) {
1160 if ( $v instanceof Content ) {
1161 /* @var Content $v */
1162
1163 $contentObjects[$k] = $v;
1164
1165 $v = $v->serialize();
1166 $contentTexts[$k] = $v;
1167 $args[$k] = $v;
1168 }
1169 }
1170
1171 // call the hook functions
1172 $ok = Hooks::run( $event, $args, $deprecatedVersion );
1173
1174 // see if the hook changed the text
1175 foreach ( $contentTexts as $k => $orig ) {
1176 /* @var Content $content */
1177
1178 $modified = $args[$k];
1179 $content = $contentObjects[$k];
1180
1181 if ( $modified !== $orig ) {
1182 // text was changed, create updated Content object
1183 $content = $content->getContentHandler()->unserializeContent( $modified );
1184 }
1185
1186 $args[$k] = $content;
1187 }
1188
1189 return $ok;
1190 }
1191
1203 $fields['category'] = $engine->makeSearchFieldMapping(
1204 'category',
1206 );
1207
1208 $fields['category']->setFlag( SearchIndexField::FLAG_CASEFOLD );
1209
1210 $fields['external_link'] = $engine->makeSearchFieldMapping(
1211 'external_link',
1213 );
1214
1215 $fields['outgoing_link'] = $engine->makeSearchFieldMapping(
1216 'outgoing_link',
1218 );
1219
1220 $fields['template'] = $engine->makeSearchFieldMapping(
1221 'template',
1223 );
1224
1225 $fields['template']->setFlag( SearchIndexField::FLAG_CASEFOLD );
1226
1227 return $fields;
1228 }
1229
1239 protected function addSearchField( &$fields, SearchEngine $engine, $name, $type ) {
1240 $fields[$name] = $engine->makeSearchFieldMapping( $name, $type );
1241 return $fields;
1242 }
1243
1257 $fieldData = [];
1258 $content = $page->getContent();
1259
1260 if ( $content ) {
1261 $searchDataExtractor = new ParserOutputSearchDataExtractor();
1262
1263 $fieldData['category'] = $searchDataExtractor->getCategories( $output );
1264 $fieldData['external_link'] = $searchDataExtractor->getExternalLinks( $output );
1265 $fieldData['outgoing_link'] = $searchDataExtractor->getOutgoingLinks( $output );
1266 $fieldData['template'] = $searchDataExtractor->getTemplates( $output );
1267
1268 $text = $content->getTextForSearchIndex();
1269
1270 $fieldData['text'] = $text;
1271 $fieldData['source_text'] = $text;
1272 $fieldData['text_bytes'] = $content->getSize();
1273 }
1274
1275 Hooks::run( 'SearchDataForIndex', [ &$fieldData, $this, $page, $output, $engine ] );
1276 return $fieldData;
1277 }
1278
1289 $parserOptions = $page->makeParserOptions( 'canonical' );
1290 $revId = $page->getRevision()->getId();
1291 if ( $cache ) {
1292 $parserOutput = $cache->get( $page, $parserOptions );
1293 }
1294 if ( empty( $parserOutput ) ) {
1296 $page->getContent()->getParserOutput( $page->getTitle(), $revId, $parserOptions );
1297 if ( $cache ) {
1298 $cache->save( $parserOutput, $page, $parserOptions );
1299 }
1300 }
1301 return $parserOutput;
1302 }
1303
1304}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgEnableParserLimitReporting
Whether to include the NewPP limit report as a HTML comment.
$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.
if( $line===false) $args
Definition cdb.php:64
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.
getAutosummary(Content $oldContent=null, Content $newContent=null, $flags)
Return an applicable auto-summary if one exists for the given edit.
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
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.
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.
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.
getUndoContent(Revision $current, Revision $undo, Revision $undoafter)
Get the Content object that needs to be saved in order to undo all revisions between $undo and $undoa...
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.
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.
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.
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 on the given page.
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.
static runLegacyHooks( $event, $args=[], $deprecatedVersion=null)
Call a legacy hook that uses text instead of Content objects.
getPageViewLanguage(Title $title, Content $content=null)
Get the language in which the content of this page is written when viewed by user.
Internationalisation code.
Definition Language.php:35
Exception representing a failure to serialize or unserialize a content object.
MediaWiki exception.
Exception thrown when an unregistered content model is requested.
string $modelId
The name of the unknown content model.
Extracts data from ParserOutput for indexing in the search engine.
static singleton()
Get the signleton instance of this class.
static newFromContext(IContextSource $context)
Get a ParserOptions object from a IContextSource object.
static newFromUser( $user)
Get a ParserOptions object from a given user.
static newFromUserAndLang(User $user, Language $lang)
Get a ParserOptions object from a given user and language.
getId()
Get revision ID.
Definition Revision.php:729
getContent( $audience=self::FOR_PUBLIC, User $user=null)
Fetch revision content if it's available to the specified audience.
const DELETED_USER
Definition Revision.php:87
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:128
Contain a class for special pages.
Content object implementation for representing flat text.
Represents a title within MediaWiki.
Definition Title.php:36
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition Title.php:3209
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
Class representing a MediaWiki article and history.
Definition WikiPage.php:32
$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 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
Definition design.txt:57
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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 text
Definition design.txt:18
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 $wgLang
Definition design.txt:56
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_USER
Definition Defines.php:58
const CONTENT_MODEL_CSS
Definition Defines.php:241
const NS_MEDIAWIKI
Definition Defines.php:64
const CONTENT_MODEL_WIKITEXT
Definition Defines.php:239
const CONTENT_MODEL_JSON
Definition Defines.php:243
const CONTENT_MODEL_TEXT
Definition Defines.php:242
const CONTENT_MODEL_JAVASCRIPT
Definition Defines.php:240
const EDIT_NEW
Definition Defines.php:146
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 as context $revId
Definition hooks.txt:1095
the array() calling protocol came about after MediaWiki 1.4rc1.
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 as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
Definition hooks.txt:1102
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 $parserOutput
Definition hooks.txt:1090
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition hooks.txt:2568
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 as context as context $options
Definition hooks.txt:1096
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 prev or next $refreshCache
Definition hooks.txt:1596
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
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 "&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
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2710
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition hooks.txt:2755
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 prev or next refreshes the diff cache $unhide
Definition hooks.txt:1597
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition hooks.txt:2534
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub 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:925
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
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 as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive false for true for descending in case the handler function wants to provide a converted Content object Note that $result getContentModel() must return $toModel. 'CustomEditor' $rcid is used in generating this variable which contains information about the new such as the revision s whether the revision was marked as a minor edit or etc $differenceEngine
Definition hooks.txt:1209
returning false will NOT prevent logging $e
Definition hooks.txt:2110
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.
const INDEX_TYPE_TEXT
Field types.
const FLAG_CASEFOLD
Generic field flags.
$context
Definition load.php:50
$cache
Definition mcc.php:33
const DB_REPLICA
Definition defines.php:22
if(!isset( $args[0])) $lang