Merge "Remove parameter 'options' from hook 'SkinEditSectionLinks'"
[lhc/web/wiklou.git] / includes / content / ContentHandler.php
1 <?php
2
3 /**
4 * Base class for content handling.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @since 1.21
22 *
23 * @file
24 * @ingroup Content
25 *
26 * @author Daniel Kinzler
27 */
28
29 use Wikimedia\Assert\Assert;
30 use MediaWiki\Logger\LoggerFactory;
31 use MediaWiki\MediaWikiServices;
32 use MediaWiki\Revision\SlotRenderingProvider;
33 use MediaWiki\Search\ParserOutputSearchDataExtractor;
34
35 /**
36 * A content handler knows how do deal with a specific type of content on a wiki
37 * page. Content is stored in the database in a serialized form (using a
38 * serialization format a.k.a. MIME type) and is unserialized into its native
39 * PHP representation (the content model), which is wrapped in an instance of
40 * the appropriate subclass of Content.
41 *
42 * ContentHandler instances are stateless singletons that serve, among other
43 * things, as a factory for Content objects. Generally, there is one subclass
44 * of ContentHandler and one subclass of Content for every type of content model.
45 *
46 * Some content types have a flat model, that is, their native representation
47 * is the same as their serialized form. Examples would be JavaScript and CSS
48 * code. As of now, this also applies to wikitext (MediaWiki's default content
49 * type), but wikitext content may be represented by a DOM or AST structure in
50 * the future.
51 *
52 * @ingroup Content
53 */
54 abstract class ContentHandler {
55 /**
56 * Convenience function for getting flat text from a Content object. This
57 * should only be used in the context of backwards compatibility with code
58 * that is not yet able to handle Content objects!
59 *
60 * If $content is null, this method returns the empty string.
61 *
62 * If $content is an instance of TextContent, this method returns the flat
63 * text as returned by $content->getText().
64 *
65 * If $content is not a TextContent object, the behavior of this method
66 * depends on the global $wgContentHandlerTextFallback:
67 * - If $wgContentHandlerTextFallback is 'fail' and $content is not a
68 * TextContent object, an MWException is thrown.
69 * - If $wgContentHandlerTextFallback is 'serialize' and $content is not a
70 * TextContent object, $content->serialize() is called to get a string
71 * form of the content.
72 * - If $wgContentHandlerTextFallback is 'ignore' and $content is not a
73 * TextContent object, this method returns null.
74 * - otherwise, the behavior is undefined.
75 *
76 * @since 1.21
77 *
78 * @param Content|null $content
79 *
80 * @throws MWException If the content is not an instance of TextContent and
81 * wgContentHandlerTextFallback was set to 'fail'.
82 * @return string|null Textual form of the content, if available.
83 */
84 public static function getContentText( Content $content = null ) {
85 global $wgContentHandlerTextFallback;
86
87 if ( is_null( $content ) ) {
88 return '';
89 }
90
91 if ( $content instanceof TextContent ) {
92 return $content->getText();
93 }
94
95 wfDebugLog( 'ContentHandler', 'Accessing ' . $content->getModel() . ' content as text!' );
96
97 if ( $wgContentHandlerTextFallback == 'fail' ) {
98 throw new MWException(
99 "Attempt to get text from Content with model " .
100 $content->getModel()
101 );
102 }
103
104 if ( $wgContentHandlerTextFallback == 'serialize' ) {
105 return $content->serialize();
106 }
107
108 return null;
109 }
110
111 /**
112 * Convenience function for creating a Content object from a given textual
113 * representation.
114 *
115 * $text will be deserialized into a Content object of the model specified
116 * by $modelId (or, if that is not given, $title->getContentModel()) using
117 * the given format.
118 *
119 * @since 1.21
120 *
121 * @param string $text The textual representation, will be
122 * unserialized to create the Content object
123 * @param Title|null $title The title of the page this text belongs to.
124 * Required if $modelId is not provided.
125 * @param string|null $modelId The model to deserialize to. If not provided,
126 * $title->getContentModel() is used.
127 * @param string|null $format The format to use for deserialization. If not
128 * given, the model's default format is used.
129 *
130 * @throws MWException If model ID or format is not supported or if the text can not be
131 * unserialized using the format.
132 * @return Content A Content object representing the text.
133 */
134 public static function makeContent( $text, Title $title = null,
135 $modelId = null, $format = null ) {
136 if ( is_null( $modelId ) ) {
137 if ( is_null( $title ) ) {
138 throw new MWException( "Must provide a Title object or a content model ID." );
139 }
140
141 $modelId = $title->getContentModel();
142 }
143
144 $handler = self::getForModelID( $modelId );
145
146 return $handler->unserializeContent( $text, $format );
147 }
148
149 /**
150 * Returns the name of the default content model to be used for the page
151 * with the given title.
152 *
153 * Note: There should rarely be need to call this method directly.
154 * To determine the actual content model for a given page, use
155 * Title::getContentModel().
156 *
157 * Which model is to be used by default for the page is determined based
158 * on several factors:
159 * - The global setting $wgNamespaceContentModels specifies a content model
160 * per namespace.
161 * - The hook ContentHandlerDefaultModelFor may be used to override the page's default
162 * model.
163 * - Pages in NS_MEDIAWIKI and NS_USER default to the CSS or JavaScript
164 * model if they end in .js or .css, respectively.
165 * - Pages in NS_MEDIAWIKI default to the wikitext model otherwise.
166 * - The hook TitleIsCssOrJsPage may be used to force a page to use the CSS
167 * or JavaScript model. This is a compatibility feature. The ContentHandlerDefaultModelFor
168 * hook should be used instead if possible.
169 * - The hook TitleIsWikitextPage may be used to force a page to use the
170 * wikitext model. This is a compatibility feature. The ContentHandlerDefaultModelFor
171 * hook should be used instead if possible.
172 *
173 * If none of the above applies, the wikitext model is used.
174 *
175 * Note: this is used by, and may thus not use, Title::getContentModel()
176 *
177 * @since 1.21
178 * @deprecated since 1.33, use SlotRoleHandler::getDefaultModel() together with
179 * SlotRoleRegistry::getRoleHandler().
180 *
181 * @param Title $title
182 *
183 * @return string Default model name for the page given by $title
184 */
185 public static function getDefaultModelFor( Title $title ) {
186 $slotRoleregistry = MediaWikiServices::getInstance()->getSlotRoleRegistry();
187 $mainSlotHandler = $slotRoleregistry->getRoleHandler( 'main' );
188 return $mainSlotHandler->getDefaultModel( $title );
189 }
190
191 /**
192 * Returns the appropriate ContentHandler singleton for the given title.
193 *
194 * @since 1.21
195 *
196 * @param Title $title
197 *
198 * @return ContentHandler
199 */
200 public static function getForTitle( Title $title ) {
201 $modelId = $title->getContentModel();
202
203 return self::getForModelID( $modelId );
204 }
205
206 /**
207 * Returns the appropriate ContentHandler singleton for the given Content
208 * object.
209 *
210 * @since 1.21
211 *
212 * @param Content $content
213 *
214 * @return ContentHandler
215 */
216 public static function getForContent( Content $content ) {
217 $modelId = $content->getModel();
218
219 return self::getForModelID( $modelId );
220 }
221
222 /**
223 * @var array A Cache of ContentHandler instances by model id
224 */
225 protected static $handlers;
226
227 /**
228 * Returns the ContentHandler singleton for the given model ID. Use the
229 * CONTENT_MODEL_XXX constants to identify the desired content model.
230 *
231 * ContentHandler singletons are taken from the global $wgContentHandlers
232 * array. Keys in that array are model names, the values are either
233 * ContentHandler singleton objects, or strings specifying the appropriate
234 * subclass of ContentHandler.
235 *
236 * If a class name is encountered when looking up the singleton for a given
237 * model name, the class is instantiated and the class name is replaced by
238 * the resulting singleton in $wgContentHandlers.
239 *
240 * If no ContentHandler is defined for the desired $modelId, the
241 * ContentHandler may be provided by the ContentHandlerForModelID hook.
242 * If no ContentHandler can be determined, an MWException is raised.
243 *
244 * @since 1.21
245 *
246 * @param string $modelId The ID of the content model for which to get a
247 * handler. Use CONTENT_MODEL_XXX constants.
248 *
249 * @throws MWException For internal errors and problems in the configuration.
250 * @throws MWUnknownContentModelException If no handler is known for the model ID.
251 * @return ContentHandler The ContentHandler singleton for handling the model given by the ID.
252 */
253 public static function getForModelID( $modelId ) {
254 global $wgContentHandlers;
255
256 if ( isset( self::$handlers[$modelId] ) ) {
257 return self::$handlers[$modelId];
258 }
259
260 if ( empty( $wgContentHandlers[$modelId] ) ) {
261 $handler = null;
262
263 Hooks::run( 'ContentHandlerForModelID', [ $modelId, &$handler ] );
264
265 if ( $handler === null ) {
266 throw new MWUnknownContentModelException( $modelId );
267 }
268
269 if ( !( $handler instanceof ContentHandler ) ) {
270 throw new MWException( "ContentHandlerForModelID must supply a ContentHandler instance" );
271 }
272 } else {
273 $classOrCallback = $wgContentHandlers[$modelId];
274
275 if ( is_callable( $classOrCallback ) ) {
276 $handler = call_user_func( $classOrCallback, $modelId );
277 } else {
278 $handler = new $classOrCallback( $modelId );
279 }
280
281 if ( !( $handler instanceof ContentHandler ) ) {
282 throw new MWException( "$classOrCallback from \$wgContentHandlers is not " .
283 "compatible with ContentHandler" );
284 }
285 }
286
287 wfDebugLog( 'ContentHandler', 'Created handler for ' . $modelId
288 . ': ' . get_class( $handler ) );
289
290 self::$handlers[$modelId] = $handler;
291
292 return self::$handlers[$modelId];
293 }
294
295 /**
296 * Clean up handlers cache.
297 */
298 public static function cleanupHandlersCache() {
299 self::$handlers = [];
300 }
301
302 /**
303 * Returns the localized name for a given content model.
304 *
305 * Model names are localized using system messages. Message keys
306 * have the form content-model-$name, where $name is getContentModelName( $id ).
307 *
308 * @param string $name The content model ID, as given by a CONTENT_MODEL_XXX
309 * constant or returned by Revision::getContentModel().
310 * @param Language|null $lang The language to parse the message in (since 1.26)
311 *
312 * @throws MWException If the model ID isn't known.
313 * @return string The content model's localized name.
314 */
315 public static function getLocalizedName( $name, Language $lang = null ) {
316 // Messages: content-model-wikitext, content-model-text,
317 // content-model-javascript, content-model-css
318 $key = "content-model-$name";
319
320 $msg = wfMessage( $key );
321 if ( $lang ) {
322 $msg->inLanguage( $lang );
323 }
324
325 return $msg->exists() ? $msg->plain() : $name;
326 }
327
328 public static function getContentModels() {
329 global $wgContentHandlers;
330
331 $models = array_keys( $wgContentHandlers );
332 Hooks::run( 'GetContentModels', [ &$models ] );
333 return $models;
334 }
335
336 public static function getAllContentFormats() {
337 global $wgContentHandlers;
338
339 $formats = [];
340
341 foreach ( $wgContentHandlers as $model => $class ) {
342 $handler = self::getForModelID( $model );
343 $formats = array_merge( $formats, $handler->getSupportedFormats() );
344 }
345
346 $formats = array_unique( $formats );
347
348 return $formats;
349 }
350
351 // ------------------------------------------------------------------------
352
353 /**
354 * @var string
355 */
356 protected $mModelID;
357
358 /**
359 * @var string[]
360 */
361 protected $mSupportedFormats;
362
363 /**
364 * Constructor, initializing the ContentHandler instance with its model ID
365 * and a list of supported formats. Values for the parameters are typically
366 * provided as literals by subclass's constructors.
367 *
368 * @param string $modelId (use CONTENT_MODEL_XXX constants).
369 * @param string[] $formats List for supported serialization formats
370 * (typically as MIME types)
371 */
372 public function __construct( $modelId, $formats ) {
373 $this->mModelID = $modelId;
374 $this->mSupportedFormats = $formats;
375 }
376
377 /**
378 * Serializes a Content object of the type supported by this ContentHandler.
379 *
380 * @since 1.21
381 *
382 * @param Content $content The Content object to serialize
383 * @param string|null $format The desired serialization format
384 *
385 * @return string Serialized form of the content
386 */
387 abstract public function serializeContent( Content $content, $format = null );
388
389 /**
390 * Applies transformations on export (returns the blob unchanged per default).
391 * Subclasses may override this to perform transformations such as conversion
392 * of legacy formats or filtering of internal meta-data.
393 *
394 * @param string $blob The blob to be exported
395 * @param string|null $format The blob's serialization format
396 *
397 * @return string
398 */
399 public function exportTransform( $blob, $format = null ) {
400 return $blob;
401 }
402
403 /**
404 * Unserializes a Content object of the type supported by this ContentHandler.
405 *
406 * @since 1.21
407 *
408 * @param string $blob Serialized form of the content
409 * @param string|null $format The format used for serialization
410 *
411 * @return Content The Content object created by deserializing $blob
412 */
413 abstract public function unserializeContent( $blob, $format = null );
414
415 /**
416 * Apply import transformation (per default, returns $blob unchanged).
417 * This gives subclasses an opportunity to transform data blobs on import.
418 *
419 * @since 1.24
420 *
421 * @param string $blob
422 * @param string|null $format
423 *
424 * @return string
425 */
426 public function importTransform( $blob, $format = null ) {
427 return $blob;
428 }
429
430 /**
431 * Creates an empty Content object of the type supported by this
432 * ContentHandler.
433 *
434 * @since 1.21
435 *
436 * @return Content
437 */
438 abstract public function makeEmptyContent();
439
440 /**
441 * Creates a new Content object that acts as a redirect to the given page,
442 * or null if redirects are not supported by this content model.
443 *
444 * This default implementation always returns null. Subclasses supporting redirects
445 * must override this method.
446 *
447 * Note that subclasses that override this method to return a Content object
448 * should also override supportsRedirects() to return true.
449 *
450 * @since 1.21
451 *
452 * @param Title $destination The page to redirect to.
453 * @param string $text Text to include in the redirect, if possible.
454 *
455 * @return Content Always null.
456 */
457 public function makeRedirectContent( Title $destination, $text = '' ) {
458 return null;
459 }
460
461 /**
462 * Returns the model id that identifies the content model this
463 * ContentHandler can handle. Use with the CONTENT_MODEL_XXX constants.
464 *
465 * @since 1.21
466 *
467 * @return string The model ID
468 */
469 public function getModelID() {
470 return $this->mModelID;
471 }
472
473 /**
474 * @since 1.21
475 *
476 * @param string $model_id The model to check
477 *
478 * @throws MWException If the model ID is not the ID of the content model supported by this
479 * ContentHandler.
480 */
481 protected function checkModelID( $model_id ) {
482 if ( $model_id !== $this->mModelID ) {
483 throw new MWException( "Bad content model: " .
484 "expected {$this->mModelID} " .
485 "but got $model_id." );
486 }
487 }
488
489 /**
490 * Returns a list of serialization formats supported by the
491 * serializeContent() and unserializeContent() methods of this
492 * ContentHandler.
493 *
494 * @since 1.21
495 *
496 * @return string[] List of serialization formats as MIME type like strings
497 */
498 public function getSupportedFormats() {
499 return $this->mSupportedFormats;
500 }
501
502 /**
503 * The format used for serialization/deserialization by default by this
504 * ContentHandler.
505 *
506 * This default implementation will return the first element of the array
507 * of formats that was passed to the constructor.
508 *
509 * @since 1.21
510 *
511 * @return string The name of the default serialization format as a MIME type
512 */
513 public function getDefaultFormat() {
514 return $this->mSupportedFormats[0];
515 }
516
517 /**
518 * Returns true if $format is a serialization format supported by this
519 * ContentHandler, and false otherwise.
520 *
521 * Note that if $format is null, this method always returns true, because
522 * null means "use the default format".
523 *
524 * @since 1.21
525 *
526 * @param string $format The serialization format to check
527 *
528 * @return bool
529 */
530 public function isSupportedFormat( $format ) {
531 if ( !$format ) {
532 return true; // this means "use the default"
533 }
534
535 return in_array( $format, $this->mSupportedFormats );
536 }
537
538 /**
539 * Convenient for checking whether a format provided as a parameter is actually supported.
540 *
541 * @param string $format The serialization format to check
542 *
543 * @throws MWException If the format is not supported by this content handler.
544 */
545 protected function checkFormat( $format ) {
546 if ( !$this->isSupportedFormat( $format ) ) {
547 throw new MWException(
548 "Format $format is not supported for content model "
549 . $this->getModelID()
550 );
551 }
552 }
553
554 /**
555 * Returns overrides for action handlers.
556 * Classes listed here will be used instead of the default one when
557 * (and only when) $wgActions[$action] === true. This allows subclasses
558 * to override the default action handlers.
559 *
560 * @since 1.21
561 *
562 * @return array An array mapping action names (typically "view", "edit", "history" etc.) to
563 * either the full qualified class name of an Action class, a callable taking ( Page $page,
564 * IContextSource $context = null ) as parameters and returning an Action object, or an actual
565 * Action object. An empty array in this default implementation.
566 *
567 * @see Action::factory
568 */
569 public function getActionOverrides() {
570 return [];
571 }
572
573 /**
574 * Factory for creating an appropriate DifferenceEngine for this content model.
575 * Since 1.32, this is only used for page-level diffs; to diff two content objects,
576 * use getSlotDiffRenderer.
577 *
578 * The DifferenceEngine subclass to use is selected in getDiffEngineClass(). The
579 * GetDifferenceEngine hook will receive the DifferenceEngine object and can replace or
580 * wrap it.
581 * (Note that in older versions of MediaWiki the hook documentation instructed extensions
582 * to return false from the hook; you should not rely on always being able to decorate
583 * the DifferenceEngine instance from the hook. If the owner of the content type wants to
584 * decorare the instance, overriding this method is a safer approach.)
585 *
586 * @todo This is page-level functionality so it should not belong to ContentHandler.
587 * Move it to a better place once one exists (e.g. PageTypeHandler).
588 *
589 * @since 1.21
590 *
591 * @param IContextSource $context Context to use, anything else will be ignored.
592 * @param int $old Revision ID we want to show and diff with.
593 * @param int|string $new Either a revision ID or one of the strings 'cur', 'prev' or 'next'.
594 * @param int $rcid FIXME: Deprecated, no longer used. Defaults to 0.
595 * @param bool $refreshCache If set, refreshes the diff cache. Defaults to false.
596 * @param bool $unhide If set, allow viewing deleted revs. Defaults to false.
597 *
598 * @return DifferenceEngine
599 */
600 public function createDifferenceEngine( IContextSource $context, $old = 0, $new = 0,
601 $rcid = 0, // FIXME: Deprecated, no longer used
602 $refreshCache = false, $unhide = false
603 ) {
604 $diffEngineClass = $this->getDiffEngineClass();
605 $differenceEngine = new $diffEngineClass( $context, $old, $new, $rcid, $refreshCache, $unhide );
606 Hooks::run( 'GetDifferenceEngine', [ $context, $old, $new, $refreshCache, $unhide,
607 &$differenceEngine ] );
608 return $differenceEngine;
609 }
610
611 /**
612 * Get an appropriate SlotDiffRenderer for this content model.
613 * @since 1.32
614 * @param IContextSource $context
615 * @return SlotDiffRenderer
616 */
617 final public function getSlotDiffRenderer( IContextSource $context ) {
618 $slotDiffRenderer = $this->getSlotDiffRendererInternal( $context );
619 if ( get_class( $slotDiffRenderer ) === TextSlotDiffRenderer::class ) {
620 // To keep B/C, when SlotDiffRenderer is not overridden for a given content type
621 // but DifferenceEngine is, use that instead.
622 $differenceEngine = $this->createDifferenceEngine( $context );
623 if ( get_class( $differenceEngine ) !== DifferenceEngine::class ) {
624 // TODO turn this into a deprecation warning in a later release
625 LoggerFactory::getInstance( 'diff' )->info(
626 'Falling back to DifferenceEngineSlotDiffRenderer', [
627 'modelID' => $this->getModelID(),
628 'DifferenceEngine' => get_class( $differenceEngine ),
629 ] );
630 $slotDiffRenderer = new DifferenceEngineSlotDiffRenderer( $differenceEngine );
631 }
632 }
633 Hooks::run( 'GetSlotDiffRenderer', [ $this, &$slotDiffRenderer, $context ] );
634 return $slotDiffRenderer;
635 }
636
637 /**
638 * Return the SlotDiffRenderer appropriate for this content handler.
639 * @param IContextSource $context
640 * @return SlotDiffRenderer
641 */
642 protected function getSlotDiffRendererInternal( IContextSource $context ) {
643 $contentLanguage = MediaWikiServices::getInstance()->getContentLanguage();
644 $statsdDataFactory = MediaWikiServices::getInstance()->getStatsdDataFactory();
645 $slotDiffRenderer = new TextSlotDiffRenderer();
646 $slotDiffRenderer->setStatsdDataFactory( $statsdDataFactory );
647 // XXX using the page language would be better, but it's unclear how that should be injected
648 $slotDiffRenderer->setLanguage( $contentLanguage );
649 $slotDiffRenderer->setWikiDiff2MovedParagraphDetectionCutoff(
650 $context->getConfig()->get( 'WikiDiff2MovedParagraphDetectionCutoff' )
651 );
652
653 $engine = DifferenceEngine::getEngine();
654 if ( $engine === false ) {
655 $slotDiffRenderer->setEngine( TextSlotDiffRenderer::ENGINE_PHP );
656 } elseif ( $engine === 'wikidiff2' ) {
657 $slotDiffRenderer->setEngine( TextSlotDiffRenderer::ENGINE_WIKIDIFF2 );
658 } else {
659 $slotDiffRenderer->setEngine( TextSlotDiffRenderer::ENGINE_EXTERNAL, $engine );
660 }
661
662 return $slotDiffRenderer;
663 }
664
665 /**
666 * Get the language in which the content of the given page is written.
667 *
668 * This default implementation just returns the content language (except for pages
669 * in the MediaWiki namespace)
670 *
671 * Note that the page's language is not cacheable, since it may in some
672 * cases depend on user settings.
673 *
674 * Also note that the page language may or may not depend on the actual content of the page,
675 * that is, this method may load the content in order to determine the language.
676 *
677 * @since 1.21
678 *
679 * @param Title $title The page to determine the language for.
680 * @param Content|null $content The page's content, if you have it handy, to avoid reloading it.
681 *
682 * @return Language The page's language
683 */
684 public function getPageLanguage( Title $title, Content $content = null ) {
685 global $wgLang;
686 $pageLang = MediaWikiServices::getInstance()->getContentLanguage();
687
688 if ( $title->inNamespace( NS_MEDIAWIKI ) ) {
689 // Parse mediawiki messages with correct target language
690 list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $title->getText() );
691 $pageLang = Language::factory( $lang );
692 }
693
694 Hooks::run( 'PageContentLanguage', [ $title, &$pageLang, $wgLang ] );
695
696 return wfGetLangObj( $pageLang );
697 }
698
699 /**
700 * Get the language in which the content of this page is written when
701 * viewed by user. Defaults to $this->getPageLanguage(), but if the user
702 * specified a preferred variant, the variant will be used.
703 *
704 * This default implementation just returns $this->getPageLanguage( $title, $content ) unless
705 * the user specified a preferred variant.
706 *
707 * Note that the pages view language is not cacheable, since it depends on user settings.
708 *
709 * Also note that the page language may or may not depend on the actual content of the page,
710 * that is, this method may load the content in order to determine the language.
711 *
712 * @since 1.21
713 *
714 * @param Title $title The page to determine the language for.
715 * @param Content|null $content The page's content, if you have it handy, to avoid reloading it.
716 *
717 * @return Language The page's language for viewing
718 */
719 public function getPageViewLanguage( Title $title, Content $content = null ) {
720 $pageLang = $this->getPageLanguage( $title, $content );
721
722 if ( $title->getNamespace() !== NS_MEDIAWIKI ) {
723 // If the user chooses a variant, the content is actually
724 // in a language whose code is the variant code.
725 $variant = $pageLang->getPreferredVariant();
726 if ( $pageLang->getCode() !== $variant ) {
727 $pageLang = Language::factory( $variant );
728 }
729 }
730
731 return $pageLang;
732 }
733
734 /**
735 * Determines whether the content type handled by this ContentHandler
736 * can be used for the main slot of the given page.
737 *
738 * This default implementation always returns true.
739 * Subclasses may override this to restrict the use of this content model to specific locations,
740 * typically based on the namespace or some other aspect of the title, such as a special suffix
741 * (e.g. ".svg" for SVG content).
742 *
743 * @note this calls the ContentHandlerCanBeUsedOn hook which may be used to override which
744 * content model can be used where.
745 *
746 * @see SlotRoleHandler::isAllowedModel
747 *
748 * @param Title $title The page's title.
749 *
750 * @return bool True if content of this kind can be used on the given page, false otherwise.
751 */
752 public function canBeUsedOn( Title $title ) {
753 $ok = true;
754
755 Hooks::run( 'ContentModelCanBeUsedOn', [ $this->getModelID(), $title, &$ok ] );
756
757 return $ok;
758 }
759
760 /**
761 * Returns the name of the diff engine to use.
762 *
763 * @since 1.21
764 *
765 * @return string
766 */
767 protected function getDiffEngineClass() {
768 return DifferenceEngine::class;
769 }
770
771 /**
772 * Attempts to merge differences between three versions. Returns a new
773 * Content object for a clean merge and false for failure or a conflict.
774 *
775 * This default implementation always returns false.
776 *
777 * @since 1.21
778 *
779 * @param Content $oldContent The page's previous content.
780 * @param Content $myContent One of the page's conflicting contents.
781 * @param Content $yourContent One of the page's conflicting contents.
782 *
783 * @return Content|bool Always false.
784 */
785 public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
786 return false;
787 }
788
789 /**
790 * Return type of change if one exists for the given edit.
791 *
792 * @since 1.31
793 *
794 * @param Content|null $oldContent The previous text of the page.
795 * @param Content|null $newContent The submitted text of the page.
796 * @param int $flags Bit mask: a bit mask of flags submitted for the edit.
797 *
798 * @return string|null String key representing type of change, or null.
799 */
800 private function getChangeType(
801 Content $oldContent = null,
802 Content $newContent = null,
803 $flags = 0
804 ) {
805 $oldTarget = $oldContent !== null ? $oldContent->getRedirectTarget() : null;
806 $newTarget = $newContent !== null ? $newContent->getRedirectTarget() : null;
807
808 // We check for the type of change in the given edit, and return string key accordingly
809
810 // Blanking of a page
811 if ( $oldContent && $oldContent->getSize() > 0 &&
812 $newContent && $newContent->getSize() === 0
813 ) {
814 return 'blank';
815 }
816
817 // Redirects
818 if ( $newTarget ) {
819 if ( !$oldTarget ) {
820 // New redirect page (by creating new page or by changing content page)
821 return 'new-redirect';
822 } elseif ( !$newTarget->equals( $oldTarget ) ||
823 $oldTarget->getFragment() !== $newTarget->getFragment()
824 ) {
825 // Redirect target changed
826 return 'changed-redirect-target';
827 }
828 } elseif ( $oldTarget ) {
829 // Changing an existing redirect into a non-redirect
830 return 'removed-redirect';
831 }
832
833 // New page created
834 if ( $flags & EDIT_NEW && $newContent ) {
835 if ( $newContent->getSize() === 0 ) {
836 // New blank page
837 return 'newblank';
838 } else {
839 return 'newpage';
840 }
841 }
842
843 // Removing more than 90% of the page
844 if ( $oldContent && $newContent && $oldContent->getSize() > 10 * $newContent->getSize() ) {
845 return 'replace';
846 }
847
848 // Content model changed
849 if ( $oldContent && $newContent && $oldContent->getModel() !== $newContent->getModel() ) {
850 return 'contentmodelchange';
851 }
852
853 return null;
854 }
855
856 /**
857 * Return an applicable auto-summary if one exists for the given edit.
858 *
859 * @since 1.21
860 *
861 * @param Content|null $oldContent The previous text of the page.
862 * @param Content|null $newContent The submitted text of the page.
863 * @param int $flags Bit mask: a bit mask of flags submitted for the edit.
864 *
865 * @return string An appropriate auto-summary, or an empty string.
866 */
867 public function getAutosummary(
868 Content $oldContent = null,
869 Content $newContent = null,
870 $flags = 0
871 ) {
872 $changeType = $this->getChangeType( $oldContent, $newContent, $flags );
873
874 // There's no applicable auto-summary for our case, so our auto-summary is empty.
875 if ( !$changeType ) {
876 return '';
877 }
878
879 // Decide what kind of auto-summary is needed.
880 switch ( $changeType ) {
881 case 'new-redirect':
882 $newTarget = $newContent->getRedirectTarget();
883 $truncatedtext = $newContent->getTextForSummary(
884 250
885 - strlen( wfMessage( 'autoredircomment' )->inContentLanguage()->text() )
886 - strlen( $newTarget->getFullText() )
887 );
888
889 return wfMessage( 'autoredircomment', $newTarget->getFullText() )
890 ->plaintextParams( $truncatedtext )->inContentLanguage()->text();
891 case 'changed-redirect-target':
892 $oldTarget = $oldContent->getRedirectTarget();
893 $newTarget = $newContent->getRedirectTarget();
894
895 $truncatedtext = $newContent->getTextForSummary(
896 250
897 - strlen( wfMessage( 'autosumm-changed-redirect-target' )
898 ->inContentLanguage()->text() )
899 - strlen( $oldTarget->getFullText() )
900 - strlen( $newTarget->getFullText() )
901 );
902
903 return wfMessage( 'autosumm-changed-redirect-target',
904 $oldTarget->getFullText(),
905 $newTarget->getFullText() )
906 ->rawParams( $truncatedtext )->inContentLanguage()->text();
907 case 'removed-redirect':
908 $oldTarget = $oldContent->getRedirectTarget();
909 $truncatedtext = $newContent->getTextForSummary(
910 250
911 - strlen( wfMessage( 'autosumm-removed-redirect' )
912 ->inContentLanguage()->text() )
913 - strlen( $oldTarget->getFullText() ) );
914
915 return wfMessage( 'autosumm-removed-redirect', $oldTarget->getFullText() )
916 ->rawParams( $truncatedtext )->inContentLanguage()->text();
917 case 'newpage':
918 // If they're making a new article, give its text, truncated, in the summary.
919 $truncatedtext = $newContent->getTextForSummary(
920 200 - strlen( wfMessage( 'autosumm-new' )->inContentLanguage()->text() ) );
921
922 return wfMessage( 'autosumm-new' )->rawParams( $truncatedtext )
923 ->inContentLanguage()->text();
924 case 'blank':
925 return wfMessage( 'autosumm-blank' )->inContentLanguage()->text();
926 case 'replace':
927 $truncatedtext = $newContent->getTextForSummary(
928 200 - strlen( wfMessage( 'autosumm-replace' )->inContentLanguage()->text() ) );
929
930 return wfMessage( 'autosumm-replace' )->rawParams( $truncatedtext )
931 ->inContentLanguage()->text();
932 case 'newblank':
933 return wfMessage( 'autosumm-newblank' )->inContentLanguage()->text();
934 default:
935 return '';
936 }
937 }
938
939 /**
940 * Return an applicable tag if one exists for the given edit or return null.
941 *
942 * @since 1.31
943 *
944 * @param Content|null $oldContent The previous text of the page.
945 * @param Content|null $newContent The submitted text of the page.
946 * @param int $flags Bit mask: a bit mask of flags submitted for the edit.
947 *
948 * @return string|null An appropriate tag, or null.
949 */
950 public function getChangeTag(
951 Content $oldContent = null,
952 Content $newContent = null,
953 $flags = 0
954 ) {
955 $changeType = $this->getChangeType( $oldContent, $newContent, $flags );
956
957 // There's no applicable tag for this change.
958 if ( !$changeType ) {
959 return null;
960 }
961
962 // Core tags use the same keys as ones returned from $this->getChangeType()
963 // but prefixed with pseudo namespace 'mw-', so we add the prefix before checking
964 // if this type of change should be tagged
965 $tag = 'mw-' . $changeType;
966
967 // Not all change types are tagged, so we check against the list of defined tags.
968 if ( in_array( $tag, ChangeTags::getSoftwareTags() ) ) {
969 return $tag;
970 }
971
972 return null;
973 }
974
975 /**
976 * Auto-generates a deletion reason
977 *
978 * @since 1.21
979 *
980 * @param Title $title The page's title
981 * @param bool &$hasHistory Whether the page has a history
982 *
983 * @return mixed String containing deletion reason or empty string, or
984 * boolean false if no revision occurred
985 *
986 * @todo &$hasHistory is extremely ugly, it's here because
987 * WikiPage::getAutoDeleteReason() and Article::generateReason()
988 * have it / want it.
989 */
990 public function getAutoDeleteReason( Title $title, &$hasHistory ) {
991 $dbr = wfGetDB( DB_REPLICA );
992
993 // Get the last revision
994 $rev = Revision::newFromTitle( $title );
995
996 if ( is_null( $rev ) ) {
997 return false;
998 }
999
1000 // Get the article's contents
1001 $content = $rev->getContent();
1002 $blank = false;
1003
1004 // If the page is blank, use the text from the previous revision,
1005 // which can only be blank if there's a move/import/protect dummy
1006 // revision involved
1007 if ( !$content || $content->isEmpty() ) {
1008 $prev = $rev->getPrevious();
1009
1010 if ( $prev ) {
1011 $rev = $prev;
1012 $content = $rev->getContent();
1013 $blank = true;
1014 }
1015 }
1016
1017 $this->checkModelID( $rev->getContentModel() );
1018
1019 // Find out if there was only one contributor
1020 // Only scan the last 20 revisions
1021 $revQuery = Revision::getQueryInfo();
1022 $res = $dbr->select(
1023 $revQuery['tables'],
1024 [ 'rev_user_text' => $revQuery['fields']['rev_user_text'] ],
1025 [
1026 'rev_page' => $title->getArticleID(),
1027 $dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0'
1028 ],
1029 __METHOD__,
1030 [ 'LIMIT' => 20 ],
1031 $revQuery['joins']
1032 );
1033
1034 if ( $res === false ) {
1035 // This page has no revisions, which is very weird
1036 return false;
1037 }
1038
1039 $hasHistory = ( $res->numRows() > 1 );
1040 $row = $dbr->fetchObject( $res );
1041
1042 if ( $row ) { // $row is false if the only contributor is hidden
1043 $onlyAuthor = $row->rev_user_text;
1044 // Try to find a second contributor
1045 foreach ( $res as $row ) {
1046 if ( $row->rev_user_text != $onlyAuthor ) { // T24999
1047 $onlyAuthor = false;
1048 break;
1049 }
1050 }
1051 } else {
1052 $onlyAuthor = false;
1053 }
1054
1055 // Generate the summary with a '$1' placeholder
1056 if ( $blank ) {
1057 // The current revision is blank and the one before is also
1058 // blank. It's just not our lucky day
1059 $reason = wfMessage( 'exbeforeblank', '$1' )->inContentLanguage()->text();
1060 } else {
1061 if ( $onlyAuthor ) {
1062 $reason = wfMessage(
1063 'excontentauthor',
1064 '$1',
1065 $onlyAuthor
1066 )->inContentLanguage()->text();
1067 } else {
1068 $reason = wfMessage( 'excontent', '$1' )->inContentLanguage()->text();
1069 }
1070 }
1071
1072 if ( $reason == '-' ) {
1073 // Allow these UI messages to be blanked out cleanly
1074 return '';
1075 }
1076
1077 // Max content length = max comment length - length of the comment (excl. $1)
1078 $text = $content ? $content->getTextForSummary( 255 - ( strlen( $reason ) - 2 ) ) : '';
1079
1080 // Now replace the '$1' placeholder
1081 $reason = str_replace( '$1', $text, $reason );
1082
1083 return $reason;
1084 }
1085
1086 /**
1087 * Get the Content object that needs to be saved in order to undo all revisions
1088 * between $undo and $undoafter. Revisions must belong to the same page,
1089 * must exist and must not be deleted.
1090 *
1091 * @since 1.21
1092 * @since 1.32 accepts Content objects for all parameters instead of Revision objects.
1093 * Passing Revision objects is deprecated.
1094 *
1095 * @param Revision|Content $current The current text
1096 * @param Revision|Content $undo The content of the revision to undo
1097 * @param Revision|Content $undoafter Must be from an earlier revision than $undo
1098 * @param bool $undoIsLatest Set true if $undo is from the current revision (since 1.32)
1099 *
1100 * @return mixed Content on success, false on failure
1101 */
1102 public function getUndoContent( $current, $undo, $undoafter, $undoIsLatest = false ) {
1103 Assert::parameterType( Revision::class . '|' . Content::class, $current, '$current' );
1104 if ( $current instanceof Content ) {
1105 Assert::parameter( $undo instanceof Content, '$undo',
1106 'Must be Content when $current is Content' );
1107 Assert::parameter( $undoafter instanceof Content, '$undoafter',
1108 'Must be Content when $current is Content' );
1109 $cur_content = $current;
1110 $undo_content = $undo;
1111 $undoafter_content = $undoafter;
1112 } else {
1113 Assert::parameter( $undo instanceof Revision, '$undo',
1114 'Must be Revision when $current is Revision' );
1115 Assert::parameter( $undoafter instanceof Revision, '$undoafter',
1116 'Must be Revision when $current is Revision' );
1117
1118 $cur_content = $current->getContent();
1119
1120 if ( empty( $cur_content ) ) {
1121 return false; // no page
1122 }
1123
1124 $undo_content = $undo->getContent();
1125 $undoafter_content = $undoafter->getContent();
1126
1127 if ( !$undo_content || !$undoafter_content ) {
1128 return false; // no content to undo
1129 }
1130
1131 $undoIsLatest = $current->getId() === $undo->getId();
1132 }
1133
1134 try {
1135 $this->checkModelID( $cur_content->getModel() );
1136 $this->checkModelID( $undo_content->getModel() );
1137 if ( !$undoIsLatest ) {
1138 // If we are undoing the most recent revision,
1139 // its ok to revert content model changes. However
1140 // if we are undoing a revision in the middle, then
1141 // doing that will be confusing.
1142 $this->checkModelID( $undoafter_content->getModel() );
1143 }
1144 } catch ( MWException $e ) {
1145 // If the revisions have different content models
1146 // just return false
1147 return false;
1148 }
1149
1150 if ( $cur_content->equals( $undo_content ) ) {
1151 // No use doing a merge if it's just a straight revert.
1152 return $undoafter_content;
1153 }
1154
1155 $undone_content = $this->merge3( $undo_content, $undoafter_content, $cur_content );
1156
1157 return $undone_content;
1158 }
1159
1160 /**
1161 * Get parser options suitable for rendering and caching the article
1162 *
1163 * @deprecated since 1.32, use WikiPage::makeParserOptions() or
1164 * ParserOptions::newCanonical() instead.
1165 * @param IContextSource|User|string $context One of the following:
1166 * - IContextSource: Use the User and the Language of the provided
1167 * context
1168 * - User: Use the provided User object and $wgLang for the language,
1169 * so use an IContextSource object if possible.
1170 * - 'canonical': Canonical options (anonymous user with default
1171 * preferences and content language).
1172 *
1173 * @throws MWException
1174 * @return ParserOptions
1175 */
1176 public function makeParserOptions( $context ) {
1177 wfDeprecated( __METHOD__, '1.32' );
1178 return ParserOptions::newCanonical( $context );
1179 }
1180
1181 /**
1182 * Returns true for content models that support caching using the
1183 * ParserCache mechanism. See WikiPage::shouldCheckParserCache().
1184 *
1185 * @since 1.21
1186 *
1187 * @return bool Always false.
1188 */
1189 public function isParserCacheSupported() {
1190 return false;
1191 }
1192
1193 /**
1194 * Returns true if this content model supports sections.
1195 * This default implementation returns false.
1196 *
1197 * Content models that return true here should also implement
1198 * Content::getSection, Content::replaceSection, etc. to handle sections..
1199 *
1200 * @return bool Always false.
1201 */
1202 public function supportsSections() {
1203 return false;
1204 }
1205
1206 /**
1207 * Returns true if this content model supports categories.
1208 * The default implementation returns true.
1209 *
1210 * @return bool Always true.
1211 */
1212 public function supportsCategories() {
1213 return true;
1214 }
1215
1216 /**
1217 * Returns true if this content model supports redirects.
1218 * This default implementation returns false.
1219 *
1220 * Content models that return true here should also implement
1221 * ContentHandler::makeRedirectContent to return a Content object.
1222 *
1223 * @return bool Always false.
1224 */
1225 public function supportsRedirects() {
1226 return false;
1227 }
1228
1229 /**
1230 * Return true if this content model supports direct editing, such as via EditPage.
1231 *
1232 * @return bool Default is false, and true for TextContent and it's derivatives.
1233 */
1234 public function supportsDirectEditing() {
1235 return false;
1236 }
1237
1238 /**
1239 * Whether or not this content model supports direct editing via ApiEditPage
1240 *
1241 * @return bool Default is false, and true for TextContent and derivatives.
1242 */
1243 public function supportsDirectApiEditing() {
1244 return $this->supportsDirectEditing();
1245 }
1246
1247 /**
1248 * Get fields definition for search index
1249 *
1250 * @todo Expose title, redirect, namespace, text, source_text, text_bytes
1251 * field mappings here. (see T142670 and T143409)
1252 *
1253 * @param SearchEngine $engine
1254 * @return SearchIndexField[] List of fields this content handler can provide.
1255 * @since 1.28
1256 */
1257 public function getFieldsForSearchIndex( SearchEngine $engine ) {
1258 $fields['category'] = $engine->makeSearchFieldMapping(
1259 'category',
1260 SearchIndexField::INDEX_TYPE_TEXT
1261 );
1262 $fields['category']->setFlag( SearchIndexField::FLAG_CASEFOLD );
1263
1264 $fields['external_link'] = $engine->makeSearchFieldMapping(
1265 'external_link',
1266 SearchIndexField::INDEX_TYPE_KEYWORD
1267 );
1268
1269 $fields['outgoing_link'] = $engine->makeSearchFieldMapping(
1270 'outgoing_link',
1271 SearchIndexField::INDEX_TYPE_KEYWORD
1272 );
1273
1274 $fields['template'] = $engine->makeSearchFieldMapping(
1275 'template',
1276 SearchIndexField::INDEX_TYPE_KEYWORD
1277 );
1278 $fields['template']->setFlag( SearchIndexField::FLAG_CASEFOLD );
1279
1280 $fields['content_model'] = $engine->makeSearchFieldMapping(
1281 'content_model',
1282 SearchIndexField::INDEX_TYPE_KEYWORD
1283 );
1284
1285 return $fields;
1286 }
1287
1288 /**
1289 * Add new field definition to array.
1290 * @param SearchIndexField[] &$fields
1291 * @param SearchEngine $engine
1292 * @param string $name
1293 * @param int $type
1294 * @return SearchIndexField[] new field defs
1295 * @since 1.28
1296 */
1297 protected function addSearchField( &$fields, SearchEngine $engine, $name, $type ) {
1298 $fields[$name] = $engine->makeSearchFieldMapping( $name, $type );
1299 return $fields;
1300 }
1301
1302 /**
1303 * Return fields to be indexed by search engine
1304 * as representation of this document.
1305 * Overriding class should call parent function or take care of calling
1306 * the SearchDataForIndex hook.
1307 * @param WikiPage $page Page to index
1308 * @param ParserOutput $output
1309 * @param SearchEngine $engine Search engine for which we are indexing
1310 * @return array Map of name=>value for fields
1311 * @since 1.28
1312 */
1313 public function getDataForSearchIndex(
1314 WikiPage $page,
1315 ParserOutput $output,
1316 SearchEngine $engine
1317 ) {
1318 $fieldData = [];
1319 $content = $page->getContent();
1320
1321 if ( $content ) {
1322 $searchDataExtractor = new ParserOutputSearchDataExtractor();
1323
1324 $fieldData['category'] = $searchDataExtractor->getCategories( $output );
1325 $fieldData['external_link'] = $searchDataExtractor->getExternalLinks( $output );
1326 $fieldData['outgoing_link'] = $searchDataExtractor->getOutgoingLinks( $output );
1327 $fieldData['template'] = $searchDataExtractor->getTemplates( $output );
1328
1329 $text = $content->getTextForSearchIndex();
1330
1331 $fieldData['text'] = $text;
1332 $fieldData['source_text'] = $text;
1333 $fieldData['text_bytes'] = $content->getSize();
1334 $fieldData['content_model'] = $content->getModel();
1335 }
1336
1337 Hooks::run( 'SearchDataForIndex', [ &$fieldData, $this, $page, $output, $engine ] );
1338 return $fieldData;
1339 }
1340
1341 /**
1342 * Produce page output suitable for indexing.
1343 *
1344 * Specific content handlers may override it if they need different content handling.
1345 *
1346 * @param WikiPage $page
1347 * @param ParserCache|null $cache
1348 * @return ParserOutput
1349 */
1350 public function getParserOutputForIndexing( WikiPage $page, ParserCache $cache = null ) {
1351 // TODO: MCR: ContentHandler should be called per slot, not for the whole page.
1352 // See T190066.
1353 $parserOptions = $page->makeParserOptions( 'canonical' );
1354 if ( $cache ) {
1355 $parserOutput = $cache->get( $page, $parserOptions );
1356 }
1357
1358 if ( empty( $parserOutput ) ) {
1359 $renderer = MediaWikiServices::getInstance()->getRevisionRenderer();
1360 $parserOutput =
1361 $renderer->getRenderedRevision(
1362 $page->getRevision()->getRevisionRecord(),
1363 $parserOptions
1364 )->getRevisionParserOutput();
1365 if ( $cache ) {
1366 $cache->save( $parserOutput, $page, $parserOptions );
1367 }
1368 }
1369 return $parserOutput;
1370 }
1371
1372 /**
1373 * Returns a list of DeferrableUpdate objects for recording information about the
1374 * given Content in some secondary data store.
1375 *
1376 * Application logic should not call this method directly. Instead, it should call
1377 * DerivedPageDataUpdater::getSecondaryDataUpdates().
1378 *
1379 * @note Implementations must not return a LinksUpdate instance. Instead, a LinksUpdate
1380 * is created by the calling code in DerivedPageDataUpdater, on the combined ParserOutput
1381 * of all slots, not for each slot individually. This is in contrast to the old
1382 * getSecondaryDataUpdates method defined by AbstractContent, which returned a LinksUpdate.
1383 *
1384 * @note Implementations should not call $content->getParserOutput, they should call
1385 * $slotOutput->getSlotRendering( $role, false ) instead if they need to access a ParserOutput
1386 * of $content. This allows existing ParserOutput objects to be re-used, while avoiding
1387 * creating a ParserOutput when none is needed.
1388 *
1389 * @param Title $title The title of the page to supply the updates for
1390 * @param Content $content The content to generate data updates for.
1391 * @param string $role The role (slot) in which the content is being used. Which updates
1392 * are performed should generally not depend on the role the content has, but the
1393 * DeferrableUpdates themselves may need to know the role, to track to which slot the
1394 * data refers, and to avoid overwriting data of the same kind from another slot.
1395 * @param SlotRenderingProvider $slotOutput A provider that can be used to gain access to
1396 * a ParserOutput of $content by calling $slotOutput->getSlotParserOutput( $role, false ).
1397 * @return DeferrableUpdate[] A list of DeferrableUpdate objects for putting information
1398 * about this content object somewhere. The default implementation returns an empty
1399 * array.
1400 * @since 1.32
1401 */
1402 public function getSecondaryDataUpdates(
1403 Title $title,
1404 Content $content,
1405 $role,
1406 SlotRenderingProvider $slotOutput
1407 ) {
1408 return [];
1409 }
1410
1411 /**
1412 * Returns a list of DeferrableUpdate objects for removing information about content
1413 * in some secondary data store. This is used when a page is deleted, and also when
1414 * a slot is removed from a page.
1415 *
1416 * Application logic should not call this method directly. Instead, it should call
1417 * WikiPage::getSecondaryDataUpdates().
1418 *
1419 * @note Implementations must not return a LinksDeletionUpdate instance. Instead, a
1420 * LinksDeletionUpdate is created by the calling code in WikiPage.
1421 * This is in contrast to the old getDeletionUpdates method defined by AbstractContent,
1422 * which returned a LinksUpdate.
1423 *
1424 * @note Implementations should not rely on the page's current content, but rather the current
1425 * state of the secondary data store.
1426 *
1427 * @param Title $title The title of the page to supply the updates for
1428 * @param string $role The role (slot) in which the content is being used. Which updates
1429 * are performed should generally not depend on the role the content has, but the
1430 * DeferrableUpdates themselves may need to know the role, to track to which slot the
1431 * data refers, and to avoid overwriting data of the same kind from another slot.
1432 *
1433 * @return DeferrableUpdate[] A list of DeferrableUpdate objects for putting information
1434 * about this content object somewhere. The default implementation returns an empty
1435 * array.
1436 *
1437 * @since 1.32
1438 */
1439 public function getDeletionUpdates( Title $title, $role ) {
1440 return [];
1441 }
1442
1443 }