MediaWiki REL1_27
ContentHandler.php
Go to the documentation of this file.
1<?php
35
46 private $modelId;
47
49 function __construct( $modelId ) {
50 parent::__construct( "The content model '$modelId' is not registered on this wiki.\n" .
51 'See https://www.mediawiki.org/wiki/Content_handlers to find out which extensions ' .
52 'handle this content model.' );
53 $this->modelId = $modelId;
54 }
55
57 public function getModelId() {
58 return $this->modelId;
59 }
60}
61
81abstract class ContentHandler {
89 protected static $enableDeprecationWarnings = false;
90
120 public static function getContentText( Content $content = null ) {
122
123 if ( is_null( $content ) ) {
124 return '';
125 }
126
127 if ( $content instanceof TextContent ) {
128 return $content->getNativeData();
129 }
130
131 wfDebugLog( 'ContentHandler', 'Accessing ' . $content->getModel() . ' content as text!' );
132
133 if ( $wgContentHandlerTextFallback == 'fail' ) {
134 throw new MWException(
135 "Attempt to get text from Content with model " .
136 $content->getModel()
137 );
138 }
139
140 if ( $wgContentHandlerTextFallback == 'serialize' ) {
141 return $content->serialize();
142 }
143
144 return null;
145 }
146
170 public static function makeContent( $text, Title $title = null,
171 $modelId = null, $format = null ) {
172 if ( is_null( $modelId ) ) {
173 if ( is_null( $title ) ) {
174 throw new MWException( "Must provide a Title object or a content model ID." );
175 }
176
177 $modelId = $title->getContentModel();
178 }
179
181
182 return $handler->unserializeContent( $text, $format );
183 }
184
219 public static function getDefaultModelFor( Title $title ) {
220 // NOTE: this method must not rely on $title->getContentModel() directly or indirectly,
221 // because it is used to initialize the mContentModel member.
222
223 $ns = $title->getNamespace();
224
225 $ext = false;
226 $m = null;
228
229 // Hook can determine default model
230 if ( !Hooks::run( 'ContentHandlerDefaultModelFor', [ $title, &$model ] ) ) {
231 if ( !is_null( $model ) ) {
232 return $model;
233 }
234 }
235
236 // Could this page contain code based on the title?
237 $isCodePage = NS_MEDIAWIKI == $ns && preg_match( '!\.(css|js|json)$!u', $title->getText(), $m );
238 if ( $isCodePage ) {
239 $ext = $m[1];
240 }
241
242 // Hook can force JS/CSS
243 Hooks::run( 'TitleIsCssOrJsPage', [ $title, &$isCodePage ], '1.25' );
244
245 // Is this a user subpage containing code?
246 $isCodeSubpage = NS_USER == $ns
247 && !$isCodePage
248 && preg_match( "/\\/.*\\.(js|css|json)$/", $title->getText(), $m );
249 if ( $isCodeSubpage ) {
250 $ext = $m[1];
251 }
252
253 // Is this wikitext, according to $wgNamespaceContentModels or the DefaultModelFor hook?
254 $isWikitext = is_null( $model ) || $model == CONTENT_MODEL_WIKITEXT;
255 $isWikitext = $isWikitext && !$isCodePage && !$isCodeSubpage;
256
257 // Hook can override $isWikitext
258 Hooks::run( 'TitleIsWikitextPage', [ $title, &$isWikitext ], '1.25' );
259
260 if ( !$isWikitext ) {
261 switch ( $ext ) {
262 case 'js':
264 case 'css':
265 return CONTENT_MODEL_CSS;
266 case 'json':
267 return CONTENT_MODEL_JSON;
268 default:
269 return is_null( $model ) ? CONTENT_MODEL_TEXT : $model;
270 }
271 }
272
273 // We established that it must be wikitext
274
276 }
277
287 public static function getForTitle( Title $title ) {
288 $modelId = $title->getContentModel();
289
290 return ContentHandler::getForModelID( $modelId );
291 }
292
303 public static function getForContent( Content $content ) {
304 $modelId = $content->getModel();
305
306 return ContentHandler::getForModelID( $modelId );
307 }
308
312 protected static $handlers;
313
340 public static function getForModelID( $modelId ) {
342
343 if ( isset( ContentHandler::$handlers[$modelId] ) ) {
344 return ContentHandler::$handlers[$modelId];
345 }
346
347 if ( empty( $wgContentHandlers[$modelId] ) ) {
348 $handler = null;
349
350 Hooks::run( 'ContentHandlerForModelID', [ $modelId, &$handler ] );
351
352 if ( $handler === null ) {
353 throw new MWUnknownContentModelException( $modelId );
354 }
355
356 if ( !( $handler instanceof ContentHandler ) ) {
357 throw new MWException( "ContentHandlerForModelID must supply a ContentHandler instance" );
358 }
359 } else {
360 $classOrCallback = $wgContentHandlers[$modelId];
361
362 if ( is_callable( $classOrCallback ) ) {
363 $handler = call_user_func( $classOrCallback, $modelId );
364 } else {
365 $handler = new $classOrCallback( $modelId );
366 }
367
368 if ( !( $handler instanceof ContentHandler ) ) {
369 throw new MWException( "$classOrCallback from \$wgContentHandlers is not " .
370 "compatible with ContentHandler" );
371 }
372 }
373
374 wfDebugLog( 'ContentHandler', 'Created handler for ' . $modelId
375 . ': ' . get_class( $handler ) );
376
378
379 return ContentHandler::$handlers[$modelId];
380 }
381
395 public static function getLocalizedName( $name, Language $lang = null ) {
396 // Messages: content-model-wikitext, content-model-text,
397 // content-model-javascript, content-model-css
398 $key = "content-model-$name";
399
400 $msg = wfMessage( $key );
401 if ( $lang ) {
402 $msg->inLanguage( $lang );
403 }
404
405 return $msg->exists() ? $msg->plain() : $name;
406 }
407
408 public static function getContentModels() {
410
411 return array_keys( $wgContentHandlers );
412 }
413
414 public static function getAllContentFormats() {
416
417 $formats = [];
418
419 foreach ( $wgContentHandlers as $model => $class ) {
421 $formats = array_merge( $formats, $handler->getSupportedFormats() );
422 }
423
424 $formats = array_unique( $formats );
425
426 return $formats;
427 }
428
429 // ------------------------------------------------------------------------
430
434 protected $mModelID;
435
440
450 public function __construct( $modelId, $formats ) {
451 $this->mModelID = $modelId;
452 $this->mSupportedFormats = $formats;
453
454 $this->mModelName = preg_replace( '/(Content)?Handler$/', '', get_class( $this ) );
455 $this->mModelName = preg_replace( '/[_\\\\]/', '', $this->mModelName );
456 $this->mModelName = strtolower( $this->mModelName );
457 }
458
469 abstract public function serializeContent( Content $content, $format = null );
470
481 public function exportTransform( $blob, $format = null ) {
482 return $blob;
483 }
484
495 abstract public function unserializeContent( $blob, $format = null );
496
508 public function importTransform( $blob, $format = null ) {
509 return $blob;
510 }
511
520 abstract public function makeEmptyContent();
521
539 public function makeRedirectContent( Title $destination, $text = '' ) {
540 return null;
541 }
542
551 public function getModelID() {
552 return $this->mModelID;
553 }
554
563 protected function checkModelID( $model_id ) {
564 if ( $model_id !== $this->mModelID ) {
565 throw new MWException( "Bad content model: " .
566 "expected {$this->mModelID} " .
567 "but got $model_id." );
568 }
569 }
570
580 public function getSupportedFormats() {
582 }
583
595 public function getDefaultFormat() {
596 return $this->mSupportedFormats[0];
597 }
598
612 public function isSupportedFormat( $format ) {
613 if ( !$format ) {
614 return true; // this means "use the default"
615 }
616
617 return in_array( $format, $this->mSupportedFormats );
618 }
619
627 protected function checkFormat( $format ) {
628 if ( !$this->isSupportedFormat( $format ) ) {
629 throw new MWException(
630 "Format $format is not supported for content model "
631 . $this->getModelID()
632 );
633 }
634 }
635
646 public function getActionOverrides() {
647 return [];
648 }
649
664 public function createDifferenceEngine( IContextSource $context, $old = 0, $new = 0,
665 $rcid = 0, // FIXME: Deprecated, no longer used
666 $refreshCache = false, $unhide = false ) {
667
668 // hook: get difference engine
669 $differenceEngine = null;
670 if ( !Hooks::run( 'GetDifferenceEngine',
672 ) ) {
673 return $differenceEngine;
674 }
675 $diffEngineClass = $this->getDiffEngineClass();
676 return new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide );
677 }
678
698 public function getPageLanguage( Title $title, Content $content = null ) {
700 $pageLang = $wgContLang;
701
702 if ( $title->getNamespace() == NS_MEDIAWIKI ) {
703 // Parse mediawiki messages with correct target language
704 list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $title->getText() );
705 $pageLang = wfGetLangObj( $lang );
706 }
707
708 Hooks::run( 'PageContentLanguage', [ $title, &$pageLang, $wgLang ] );
709
710 return wfGetLangObj( $pageLang );
711 }
712
733 public function getPageViewLanguage( Title $title, Content $content = null ) {
734 $pageLang = $this->getPageLanguage( $title, $content );
735
736 if ( $title->getNamespace() !== NS_MEDIAWIKI ) {
737 // If the user chooses a variant, the content is actually
738 // in a language whose code is the variant code.
739 $variant = $pageLang->getPreferredVariant();
740 if ( $pageLang->getCode() !== $variant ) {
741 $pageLang = Language::factory( $variant );
742 }
743 }
744
745 return $pageLang;
746 }
747
764 public function canBeUsedOn( Title $title ) {
765 $ok = true;
766
767 Hooks::run( 'ContentModelCanBeUsedOn', [ $this->getModelID(), $title, &$ok ] );
768
769 return $ok;
770 }
771
779 protected function getDiffEngineClass() {
780 return DifferenceEngine::class;
781 }
782
797 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
798 return false;
799 }
800
812 public function getAutosummary( Content $oldContent = null, Content $newContent = null,
813 $flags ) {
814 // Decide what kind of auto-summary is needed.
815
816 // Redirect auto-summaries
817
823 $ot = !is_null( $oldContent ) ? $oldContent->getRedirectTarget() : null;
824 $rt = !is_null( $newContent ) ? $newContent->getRedirectTarget() : null;
825
826 if ( is_object( $rt ) ) {
827 if ( !is_object( $ot )
828 || !$rt->equals( $ot )
829 || $ot->getFragment() != $rt->getFragment()
830 ) {
831 $truncatedtext = $newContent->getTextForSummary(
832 250
833 - strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
834 - strlen( $rt->getFullText() ) );
835
836 return wfMessage( 'autoredircomment', $rt->getFullText() )
837 ->rawParams( $truncatedtext )->inContentLanguage()->text();
838 }
839 }
840
841 // New page auto-summaries
842 if ( $flags & EDIT_NEW && $newContent->getSize() > 0 ) {
843 // If they're making a new article, give its text, truncated, in
844 // the summary.
845
846 $truncatedtext = $newContent->getTextForSummary(
847 200 - strlen( wfMessage( 'autosumm-new' )->inContentLanguage()->text() ) );
848
849 return wfMessage( 'autosumm-new' )->rawParams( $truncatedtext )
850 ->inContentLanguage()->text();
851 }
852
853 // Blanking auto-summaries
854 if ( !empty( $oldContent ) && $oldContent->getSize() > 0 && $newContent->getSize() == 0 ) {
855 return wfMessage( 'autosumm-blank' )->inContentLanguage()->text();
856 } elseif ( !empty( $oldContent )
857 && $oldContent->getSize() > 10 * $newContent->getSize()
858 && $newContent->getSize() < 500
859 ) {
860 // Removing more than 90% of the article
861
862 $truncatedtext = $newContent->getTextForSummary(
863 200 - strlen( wfMessage( 'autosumm-replace' )->inContentLanguage()->text() ) );
864
865 return wfMessage( 'autosumm-replace' )->rawParams( $truncatedtext )
866 ->inContentLanguage()->text();
867 }
868
869 // New blank article auto-summary
870 if ( $flags & EDIT_NEW && $newContent->isEmpty() ) {
871 return wfMessage( 'autosumm-newblank' )->inContentLanguage()->text();
872 }
873
874 // If we reach this point, there's no applicable auto-summary for our
875 // case, so our auto-summary is empty.
876 return '';
877 }
878
894 public function getAutoDeleteReason( Title $title, &$hasHistory ) {
895 $dbr = wfGetDB( DB_SLAVE );
896
897 // Get the last revision
899
900 if ( is_null( $rev ) ) {
901 return false;
902 }
903
904 // Get the article's contents
905 $content = $rev->getContent();
906 $blank = false;
907
908 // If the page is blank, use the text from the previous revision,
909 // which can only be blank if there's a move/import/protect dummy
910 // revision involved
911 if ( !$content || $content->isEmpty() ) {
912 $prev = $rev->getPrevious();
913
914 if ( $prev ) {
915 $rev = $prev;
916 $content = $rev->getContent();
917 $blank = true;
918 }
919 }
920
921 $this->checkModelID( $rev->getContentModel() );
922
923 // Find out if there was only one contributor
924 // Only scan the last 20 revisions
925 $res = $dbr->select( 'revision', 'rev_user_text',
926 [
927 'rev_page' => $title->getArticleID(),
928 $dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0'
929 ],
930 __METHOD__,
931 [ 'LIMIT' => 20 ]
932 );
933
934 if ( $res === false ) {
935 // This page has no revisions, which is very weird
936 return false;
937 }
938
939 $hasHistory = ( $res->numRows() > 1 );
940 $row = $dbr->fetchObject( $res );
941
942 if ( $row ) { // $row is false if the only contributor is hidden
943 $onlyAuthor = $row->rev_user_text;
944 // Try to find a second contributor
945 foreach ( $res as $row ) {
946 if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999
947 $onlyAuthor = false;
948 break;
949 }
950 }
951 } else {
952 $onlyAuthor = false;
953 }
954
955 // Generate the summary with a '$1' placeholder
956 if ( $blank ) {
957 // The current revision is blank and the one before is also
958 // blank. It's just not our lucky day
959 $reason = wfMessage( 'exbeforeblank', '$1' )->inContentLanguage()->text();
960 } else {
961 if ( $onlyAuthor ) {
962 $reason = wfMessage(
963 'excontentauthor',
964 '$1',
965 $onlyAuthor
966 )->inContentLanguage()->text();
967 } else {
968 $reason = wfMessage( 'excontent', '$1' )->inContentLanguage()->text();
969 }
970 }
971
972 if ( $reason == '-' ) {
973 // Allow these UI messages to be blanked out cleanly
974 return '';
975 }
976
977 // Max content length = max comment length - length of the comment (excl. $1)
978 $text = $content ? $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) ) : '';
979
980 // Now replace the '$1' placeholder
981 $reason = str_replace( '$1', $text, $reason );
982
983 return $reason;
984 }
985
999 public function getUndoContent( Revision $current, Revision $undo, Revision $undoafter ) {
1000 $cur_content = $current->getContent();
1001
1002 if ( empty( $cur_content ) ) {
1003 return false; // no page
1004 }
1005
1006 $undo_content = $undo->getContent();
1007 $undoafter_content = $undoafter->getContent();
1008
1009 if ( !$undo_content || !$undoafter_content ) {
1010 return false; // no content to undo
1011 }
1012
1013 $this->checkModelID( $cur_content->getModel() );
1014 $this->checkModelID( $undo_content->getModel() );
1015 $this->checkModelID( $undoafter_content->getModel() );
1016
1017 if ( $cur_content->equals( $undo_content ) ) {
1018 // No use doing a merge if it's just a straight revert.
1019 return $undoafter_content;
1020 }
1021
1022 $undone_content = $this->merge3( $undo_content, $undoafter_content, $cur_content );
1023
1024 return $undone_content;
1025 }
1026
1041 public function makeParserOptions( $context ) {
1043
1044 if ( $context instanceof IContextSource ) {
1046 } elseif ( $context instanceof User ) { // settings per user (even anons)
1048 } elseif ( $context === 'canonical' ) { // canonical settings
1050 } else {
1051 throw new MWException( "Bad context for parser options: $context" );
1052 }
1053
1054 $options->enableLimitReport( $wgEnableParserLimitReporting ); // show inclusion/loop reports
1055 $options->setTidy( true ); // fix bad HTML
1056
1057 return $options;
1058 }
1059
1068 public function isParserCacheSupported() {
1069 return false;
1070 }
1071
1081 public function supportsSections() {
1082 return false;
1083 }
1084
1091 public function supportsCategories() {
1092 return true;
1093 }
1094
1104 public function supportsRedirects() {
1105 return false;
1106 }
1107
1113 public function supportsDirectEditing() {
1114 return false;
1115 }
1116
1122 public function supportsDirectApiEditing() {
1123 return $this->supportsDirectEditing();
1124 }
1125
1139 public static function deprecated( $func, $version, $component = false ) {
1140 if ( self::$enableDeprecationWarnings ) {
1141 wfDeprecated( $func, $version, $component, 3 );
1142 }
1143 }
1144
1162 public static function runLegacyHooks( $event, $args = [],
1163 $warn = null
1164 ) {
1165
1166 if ( $warn === null ) {
1168 }
1169
1170 if ( !Hooks::isRegistered( $event ) ) {
1171 return true; // nothing to do here
1172 }
1173
1174 if ( $warn ) {
1175 // Log information about which handlers are registered for the legacy hook,
1176 // so we can find and fix them.
1177
1178 $handlers = Hooks::getHandlers( $event );
1179 $handlerInfo = [];
1180
1181 MediaWiki\suppressWarnings();
1182
1183 foreach ( $handlers as $handler ) {
1184 if ( is_array( $handler ) ) {
1185 if ( is_object( $handler[0] ) ) {
1186 $info = get_class( $handler[0] );
1187 } else {
1188 $info = $handler[0];
1189 }
1190
1191 if ( isset( $handler[1] ) ) {
1192 $info .= '::' . $handler[1];
1193 }
1194 } elseif ( is_object( $handler ) ) {
1195 $info = get_class( $handler[0] );
1196 $info .= '::on' . $event;
1197 } else {
1198 $info = $handler;
1199 }
1200
1201 $handlerInfo[] = $info;
1202 }
1203
1204 MediaWiki\restoreWarnings();
1205
1206 wfWarn( "Using obsolete hook $event via ContentHandler::runLegacyHooks()! Handlers: " .
1207 implode( ', ', $handlerInfo ), 2 );
1208 }
1209
1210 // convert Content objects to text
1211 $contentObjects = [];
1212 $contentTexts = [];
1213
1214 foreach ( $args as $k => $v ) {
1215 if ( $v instanceof Content ) {
1216 /* @var Content $v */
1217
1218 $contentObjects[$k] = $v;
1219
1220 $v = $v->serialize();
1221 $contentTexts[$k] = $v;
1222 $args[$k] = $v;
1223 }
1224 }
1225
1226 // call the hook functions
1227 $ok = Hooks::run( $event, $args );
1228
1229 // see if the hook changed the text
1230 foreach ( $contentTexts as $k => $orig ) {
1231 /* @var Content $content */
1232
1233 $modified = $args[$k];
1234 $content = $contentObjects[$k];
1235
1236 if ( $modified !== $orig ) {
1237 // text was changed, create updated Content object
1238 $content = $content->getContentHandler()->unserializeContent( $modified );
1239 }
1240
1241 $args[$k] = $content;
1242 }
1243
1244 return $ok;
1245 }
1246}
$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.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
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.
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.
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.
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 runLegacyHooks( $event, $args=[], $warn=null)
Call a legacy hook that uses text instead of Content objects.
static getDefaultModelFor(Title $title)
Returns the name of the default content model to be used for the page with the given title.
static $enableDeprecationWarnings
Switch for enabling deprecation warnings.
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.
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 deprecated( $func, $version, $component=false)
Logs a deprecation warning, visible if $wgDevelopmentWarnings, but only if self::$enableDeprecationWa...
static array $handlers
A Cache of ContentHandler instances by model id.
makeParserOptions( $context)
Get parser options suitable for rendering and caching the article.
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:39
Exception representing a failure to serialize or unserialize a content object.
MediaWiki exception.
static getNamespaceContentModel( $index)
Get the default content model for a namespace This does not mean that all pages in that namespace hav...
Exception thrown when an unregistered content model is requested.
string $modelId
The name of the unknown content model.
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.
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:78
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:117
Content object implementation for representing flat text.
Represents a title within MediaWiki.
Definition Title.php:34
getArticleID( $flags=0)
Get the article ID for this Title from the link cache, adding it if necessary.
Definition Title.php:3204
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:47
$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:72
const CONTENT_MODEL_CSS
Definition Defines.php:280
const NS_MEDIAWIKI
Definition Defines.php:78
const CONTENT_MODEL_WIKITEXT
Definition Defines.php:278
const CONTENT_MODEL_JSON
Definition Defines.php:282
const CONTENT_MODEL_TEXT
Definition Defines.php:281
const CONTENT_MODEL_JAVASCRIPT
Definition Defines.php:279
const EDIT_NEW
Definition Defines.php:180
const DB_SLAVE
Definition Defines.php:47
the array() calling protocol came about after MediaWiki 1.4rc1.
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 allow viewing deleted revs & $differenceEngine
Definition hooks.txt:1461
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 an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing 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
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:1042
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:1459
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:1040
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:944
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2555
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:1460
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:314
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:885
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:1597
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.
$context
Definition load.php:44
$version
if(!isset( $args[0])) $lang