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