-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ParserOutput.php
3036 lines (2768 loc) · 99 KB
/
ParserOutput.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace MediaWiki\Parser;
use CacheTime;
use InvalidArgumentException;
use LogicException;
use MediaWiki\Edit\ParsoidRenderID;
use MediaWiki\Json\JsonDeserializable;
use MediaWiki\Json\JsonDeserializableTrait;
use MediaWiki\Json\JsonDeserializer;
use MediaWiki\MainConfigNames;
use MediaWiki\MediaWikiServices;
use MediaWiki\Message\Converter;
use MediaWiki\Output\OutputPage;
use MediaWiki\Parser\Parsoid\PageBundleParserOutputConverter;
use MediaWiki\Title\Title;
use MediaWiki\Title\TitleValue;
use ParserOptions;
use UnexpectedValueException;
use Wikimedia\Bcp47Code\Bcp47Code;
use Wikimedia\Bcp47Code\Bcp47CodeValue;
use Wikimedia\Message\MessageValue;
use Wikimedia\Parsoid\Core\ContentMetadataCollector;
use Wikimedia\Parsoid\Core\ContentMetadataCollectorCompat;
use Wikimedia\Parsoid\Core\LinkTarget as ParsoidLinkTarget;
use Wikimedia\Parsoid\Core\TOCData;
use Wikimedia\Reflection\GhostFieldAccessTrait;
/**
* ParserOutput is a rendering of a Content object or a message.
* Content objects and messages often contain wikitext, but not always.
*
* `ParserOutput` object combine the HTML rendering of Content objects
* or messages, available via `::getRawText()`, with various bits of
* metadata generated during rendering, which may include categories,
* links, page properties, and extension data, among others.
*
* `ParserOutput` objects corresponding to the content of page revisions
* are created by the `ParserOutputAccess` service, which
* automatically caches them via `ParserCache` where appropriate and
* produces new output via `ContentHandler` as needed.
*
* In addition, wikitext from system messages as well as odd bits of
* wikitext rendered to create special pages and other UX elements are
* rendered to `ParserOutput` objects. In these cases the metadata
* from the `ParserOutput` is generally discarded and the
* `ParserOutput` is not cached. These bits of wikitext are generally
* rendered with `ParserOptions::setInterfaceMessage(true)` when
* content is intended to be in the user interface language, but
* sometimes rendered to the content language and displayed in the
* content area instead.
*
* A `ParserOutput` object corresponding to a given revision may be a
* combination of the renderings of multiple "slots":
* the Multi-Content Revisions (MCR) work allows articles to be
* composed from multiple `Content` objects. Each `Content` renders
* to a `ParserOutput`, and those `ParserOutput`s are merged by
* `RevisionRenderer::combineSlotOutput()` to create the final article
* output.
*
* Similarly, `OutputPage` maintains metadata overlapping
* with the metadata kept by `ParserOutput` (T301020) and may merge
* several `ParserOutput`s using `OutputPage::addParserOutput()` to
* create the final output page. Parsoid parses certain transclusions
* in independent top-level contexts using
* `Parser::parseExtensionTagAsTopLevelDoc()` and these also result in
* `ParserOutput`s which are merged via
* `ParserOutput::collectMetadata()`.
*
* Future plans for incremental parsing and asynchronous rendering may
* result in several of these component `ParserOutput` objects being
* cached independently and then recombined asynchronously, so
* operations on `ParserOutput` objects should be compatible with that
* model (T300979).
*
* @ingroup Parser
*/
class ParserOutput extends CacheTime implements ContentMetadataCollector {
use GhostFieldAccessTrait;
use JsonDeserializableTrait;
// This is used to break cyclic dependencies and allow a measure
// of compatibility when new methods are added to ContentMetadataCollector
// by Parsoid.
use ContentMetadataCollectorCompat;
/**
* Feature flags to indicate to extensions that MediaWiki core supports and
* uses getText() stateless transforms.
*
* @since 1.31
*/
public const SUPPORTS_STATELESS_TRANSFORMS = 1;
/**
* @since 1.31
*/
public const SUPPORTS_UNWRAP_TRANSFORM = 1;
/**
* @internal
* @since 1.38
*/
public const MW_MERGE_STRATEGY_KEY = '_mw-strategy';
/**
* Merge strategy to use for ParserOutput accumulators: "union"
* means that values are strings, stored as a set, and exposed as
* a PHP associative array mapping from values to `true`.
*
* This constant should be treated as @internal until we expose
* alternative merge strategies for external use.
* @internal
* @since 1.38
*/
public const MW_MERGE_STRATEGY_UNION = 'union';
/**
* @var string|null The output text
*/
private $mRawText = null;
/**
* @var string[] List of the full text of language links, in the order they appear.
*/
private $mLanguageLinks;
/**
* @var array<string,string> Map of category names to sort keys
*/
private $mCategories;
/**
* @var array<string,string> Page status indicators, usually displayed in top-right corner.
*/
private $mIndicators = [];
/**
* @var string Title text of the chosen language variant, as HTML.
*/
private $mTitleText;
/**
* @var array<int,array<string,int>> 2-D map of NS/DBK to ID for the links in the document.
* ID=zero for broken.
*/
private $mLinks = [];
/**
* @var array<string,int> Keys are DBKs for the links to special pages in the document.
* @since 1.35
*/
private $mLinksSpecial = [];
/**
* @var array<int,array<string,int>> 2-D map of NS/DBK to ID for the template references.
* ID=zero for broken.
*/
private $mTemplates = [];
/**
* @var array<int,array<string,int>> 2-D map of NS/DBK to rev ID for the template references.
* ID=zero for broken.
*/
private $mTemplateIds = [];
/**
* @var array<string,int> DB keys of the images used, in the array key only
*/
private $mImages = [];
/**
* @var array<string,array<string,string>> DB keys of the images used mapped to sha1 and MW timestamp.
*/
private $mFileSearchOptions = [];
/**
* @var array<string,int> External link URLs, in the key only.
*/
private $mExternalLinks = [];
/**
* @var array<string,array<string,int>> 2-D map of prefix/DBK (in keys only)
* for the inline interwiki links in the document.
*/
private $mInterwikiLinks = [];
/**
* @var bool Show a new section link?
*/
private $mNewSection = false;
/**
* @var bool Hide the new section link?
*/
private $mHideNewSection = false;
/**
* @var bool No gallery on category page? (__NOGALLERY__).
*/
private $mNoGallery = false;
/**
* @var string[] Items to put in the <head> section
*/
private $mHeadItems = [];
/**
* @var array<string,true> Modules to be loaded by ResourceLoader
*/
private $mModuleSet = [];
/**
* @var array<string,true> Modules of which only the CSS will be loaded by ResourceLoader.
*/
private $mModuleStyleSet = [];
/**
* @var array JavaScript config variable for mw.config combined with this page.
*/
private $mJsConfigVars = [];
/**
* @var array<string,int> Warning text to be returned to the user.
* Wikitext formatted, in the key only.
*/
private $mWarnings = [];
/**
* @var array<string,array> *Unformatted* warning messages and
* arguments to be returned to the user. This is for internal use
* when merging ParserOutputs and are not serialized/deserialized.
*/
private $mWarningMsgs = [];
/**
* @var ?TOCData Table of contents data, or null if it hasn't been set.
*/
private $mTOCData;
/**
* @var array Name/value pairs to be cached in the DB.
*/
private $mProperties = [];
/**
* @var ?string Timestamp of the revision.
*/
private $mTimestamp;
/**
* @var bool Whether OOUI should be enabled.
*/
private $mEnableOOUI = false;
/**
* @var bool Whether the index policy has been set to 'index'.
*/
private $mIndexSet = false;
/**
* @var bool Whether the index policy has been set to 'noindex'.
*/
private $mNoIndexSet = false;
/**
* @var array extra data used by extensions.
*/
private $mExtensionData = [];
/**
* @var array Parser limit report data.
*/
private $mLimitReportData = [];
/** @var array Parser limit report data for JSON */
private $mLimitReportJSData = [];
/** @var string Debug message added by ParserCache */
private $mCacheMessage = '';
/**
* @var array Timestamps for getTimeSinceStart().
*/
private $mParseStartTime = [];
/**
* @var array Durations for getTimeProfile().
*/
private $mTimeProfile = [];
/**
* @var bool Whether to emit X-Frame-Options: DENY.
*/
private $mPreventClickjacking = false;
/**
* @var string[] Extra script-src for CSP
*/
private $mExtraScriptSrcs = [];
/**
* @var string[] Extra default-src for CSP [Everything but script and style]
*/
private $mExtraDefaultSrcs = [];
/**
* @var string[] Extra style-src for CSP
*/
private $mExtraStyleSrcs = [];
/**
* @var array<string,true> Generic flags.
*/
private $mFlags = [];
/** @var string[] */
private const SPECULATIVE_FIELDS = [
'speculativePageIdUsed',
'mSpeculativeRevId',
'revisionTimestampUsed',
];
/** @var int|null Assumed rev ID for {{REVISIONID}} if no revision is set */
private $mSpeculativeRevId;
/** @var int|null Assumed page ID for {{PAGEID}} if no revision is set */
private $speculativePageIdUsed;
/** @var string|null Assumed rev timestamp for {{REVISIONTIMESTAMP}} if no revision is set */
private $revisionTimestampUsed;
/** @var string|null SHA-1 base 36 hash of any self-transclusion */
private $revisionUsedSha1Base36;
/** string CSS classes to use for the wrapping div, stored in the array keys.
* If no class is given, no wrapper is added.
*/
private $mWrapperDivClasses = [];
/** @var int Upper bound of expiry based on parse duration */
private $mMaxAdaptiveExpiry = INF;
// finalizeAdaptiveCacheExpiry() uses TTL = MAX( m * PARSE_TIME + b, MIN_AR_TTL)
// Current values imply that m=3933.333333 and b=-333.333333
// See https://www.nngroup.com/articles/website-response-times/
private const PARSE_FAST_SEC = 0.100; // perceived "fast" page parse
private const PARSE_SLOW_SEC = 1.0; // perceived "slow" page parse
private const FAST_AR_TTL = 60; // adaptive TTL for "fast" pages
private const SLOW_AR_TTL = 3600; // adaptive TTL for "slow" pages
private const MIN_AR_TTL = 15; // min adaptive TTL (for pool counter, and edit stashing)
/**
* @param string|null $text HTML. Use null to indicate that this ParserOutput contains only
* meta-data, and the HTML output is undetermined, as opposed to empty. Passing null
* here causes hasText() to return false. In 1.39 the default value changed from ''
* to null.
* @param array $languageLinks
* @param array $categoryLinks
* @param bool $unused
* @param string $titletext
*/
public function __construct( $text = null, $languageLinks = [], $categoryLinks = [],
$unused = false, $titletext = ''
) {
$this->mRawText = $text;
$this->mLanguageLinks = $languageLinks;
$this->mCategories = $categoryLinks;
$this->mTitleText = $titletext;
}
/**
* Returns true if text was passed to the constructor, or set using setText(). Returns false
* if null was passed to the $text parameter of the constructor to indicate that this
* ParserOutput only contains meta-data, and the HTML output is undetermined.
*
* @since 1.32
*
* @return bool Whether this ParserOutput contains rendered text. If this returns false, the
* ParserOutput contains meta-data only.
*/
public function hasText(): bool {
return ( $this->mRawText !== null );
}
/**
* Get the cacheable text with <mw:editsection> markers still in it. The
* return value is suitable for writing back via setText() but is not valid
* for display to the user.
*
* @return string
* @since 1.27
*/
public function getRawText() {
if ( $this->mRawText === null ) {
throw new LogicException( 'This ParserOutput contains no text!' );
}
return $this->mRawText;
}
/**
* Get the output HTML
*
* T293512: in the future, ParserOutput::getText() will be deprecated in favor of invoking the
* ParserOutputTransform pipeline directly on a ParserOutput.
* @param array $options (since 1.31) Transformations to apply to the HTML
* - allowTOC: (bool) Show the TOC, assuming there were enough headings
* to generate one and `__NOTOC__` wasn't used. Default is true,
* but might be statefully overridden.
* - injectTOC: (bool) Replace the TOC_PLACEHOLDER with TOC contents;
* otherwise the marker will be left in the article (and the skin
* will be responsible for replacing or removing it). Default is
* true.
* - enableSectionEditLinks: (bool) Include section edit links, assuming
* section edit link tokens are present in the HTML. Default is true,
* but might be statefully overridden.
* - userLang: (Language) Language object used for localizing UX messages,
* for example the heading of the table of contents. If omitted, will
* use the language of the main request context.
* - skin: (Skin) Skin object used for transforming section edit links.
* - unwrap: (bool) Return text without a wrapper div. Default is false,
* meaning a wrapper div will be added if getWrapperDivClass() returns
* a non-empty string.
* - wrapperDivClass: (string) Wrap the output in a div and apply the given
* CSS class to that div. This overrides the output of getWrapperDivClass().
* Setting this to an empty string has the same effect as 'unwrap' => true.
* - deduplicateStyles: (bool) When true, which is the default, `<style>`
* tags with the `data-mw-deduplicate` attribute set are deduplicated by
* value of the attribute: all but the first will be replaced by `<link
* rel="mw-deduplicated-inline-style" href="mw-data:..."/>` tags, where
* the scheme-specific-part of the href is the (percent-encoded) value
* of the `data-mw-deduplicate` attribute.
* - absoluteURLs: (bool) use absolute URLs in all links. Default: false
* - includeDebugInfo: (bool) render PP limit report in HTML. Default: false
* @return string HTML
* @return-taint escaped
* @deprecated since 1.42, this method has side-effects on the ParserOutput
* (see T353257) and so should be avoided in favor of directly invoking
* the default output pipeline on a ParserOutput.
*/
public function getText( $options = [] ) {
$pipeline = MediaWikiServices::getInstance()->getDefaultOutputPipeline();
$oldText = $this->mRawText; // T353257
$options += [
'suppressClone' => true, // T353257
'allowTOC' => true,
'injectTOC' => true,
'enableSectionEditLinks' => !$this->getOutputFlag( ParserOutputFlags::NO_SECTION_EDIT_LINKS ),
'userLang' => null,
'skin' => null,
'unwrap' => false,
'wrapperDivClass' => $this->getWrapperDivClass(),
'deduplicateStyles' => true,
'absoluteURLs' => false,
'includeDebugInfo' => false,
'isParsoidContent' => PageBundleParserOutputConverter::hasPageBundle( $this ),
];
$po = $pipeline->run( $this, null, $options );
$newText = $po->getContentHolderText();
// T353257: for back-compat only mutations to metadata performed by
// the pipeline should be preserved; mutations to $mText should be
// discarded.
$this->setRawText( $oldText );
return $newText;
}
/**
* Adds a comment notice about cache state to the text of the page
* @param string $msg
* @internal used by ParserCache
*/
public function addCacheMessage( string $msg ): void {
$this->mCacheMessage .= $msg;
}
/**
* Add a CSS class to use for the wrapping div. If no class is given, no wrapper is added.
*
* @param string $class
*/
public function addWrapperDivClass( $class ): void {
$this->mWrapperDivClasses[$class] = true;
}
/**
* Clears the CSS class to use for the wrapping div, effectively disabling the wrapper div
* until addWrapperDivClass() is called.
*/
public function clearWrapperDivClass(): void {
$this->mWrapperDivClasses = [];
}
/**
* Returns the class (or classes) to be used with the wrapper div for this output.
* If there is no wrapper class given, no wrapper div should be added.
* The wrapper div is added automatically by getText().
*
* @return string
*/
public function getWrapperDivClass(): string {
return implode( ' ', array_keys( $this->mWrapperDivClasses ) );
}
/**
* @param int $id
* @since 1.28
*/
public function setSpeculativeRevIdUsed( $id ): void {
$this->mSpeculativeRevId = $id;
}
/**
* @return int|null
* @since 1.28
*/
public function getSpeculativeRevIdUsed(): ?int {
return $this->mSpeculativeRevId;
}
/**
* @param int $id
* @since 1.34
*/
public function setSpeculativePageIdUsed( $id ): void {
$this->speculativePageIdUsed = $id;
}
/**
* @return int|null
* @since 1.34
*/
public function getSpeculativePageIdUsed() {
return $this->speculativePageIdUsed;
}
/**
* @param string $timestamp TS_MW timestamp
* @since 1.34
*/
public function setRevisionTimestampUsed( $timestamp ): void {
$this->revisionTimestampUsed = $timestamp;
}
/**
* @return string|null TS_MW timestamp or null if not used
* @since 1.34
*/
public function getRevisionTimestampUsed() {
return $this->revisionTimestampUsed;
}
/**
* @param string $hash Lowercase SHA-1 base 36 hash
* @since 1.34
*/
public function setRevisionUsedSha1Base36( $hash ): void {
if ( $hash === null ) {
return; // e.g. RevisionRecord::getSha1() returned null
}
if (
$this->revisionUsedSha1Base36 !== null &&
$this->revisionUsedSha1Base36 !== $hash
) {
$this->revisionUsedSha1Base36 = ''; // mismatched
} else {
$this->revisionUsedSha1Base36 = $hash;
}
}
/**
* @return string|null Lowercase SHA-1 base 36 hash, null if unused, or "" on inconsistency
* @since 1.34
*/
public function getRevisionUsedSha1Base36() {
return $this->revisionUsedSha1Base36;
}
public function &getLanguageLinks() {
return $this->mLanguageLinks;
}
public function getInterwikiLinks() {
return $this->mInterwikiLinks;
}
/**
* Return the names of the categories on this page.
* Unlike ::getCategories(), sort keys are *not* included in the
* return value.
* @return array<string> The names of the categories
* @since 1.38
*/
public function getCategoryNames(): array {
# Note that numeric category names get converted to 'int' when
# stored as array keys; stringify the keys to ensure they
# return to original string form so as not to confuse callers.
return array_map( 'strval', array_keys( $this->mCategories ) );
}
/**
* Return category names and sort keys as a map.
*
* BEWARE that numeric category names get converted to 'int' when stored
* as array keys. Because of this, use of this method is not recommended
* in new code; using ::getCategoryNames() and ::getCategorySortKey() will
* be less error-prone.
*
* @return array<string|int,string>
* @internal
*/
public function getCategoryMap(): array {
return $this->mCategories;
}
/**
* Return the sort key for a given category name, or `null` if the
* category is not present in this ParserOutput. Returns the
* empty string if the category is to use the default sort key.
*
* @note The effective sort key in the database may vary from what
* is returned here; see note in ParserOutput::addCategory().
*
* @param string $name The category name
* @return ?string The sort key for the category, or `null` if the
* category is not present in this ParserOutput
* @since 1.40
*/
public function getCategorySortKey( string $name ): ?string {
// This API avoids exposing the fact that numeric string category
// names are going to be converted to 'int' when used as array
// keys for the `mCategories` field.
return $this->mCategories[$name] ?? null;
}
/**
* @return string[]
* @since 1.25
*/
public function getIndicators(): array {
return $this->mIndicators;
}
public function getTitleText() {
return $this->mTitleText;
}
/**
* @return ?TOCData the table of contents data, or null if it hasn't been
* set.
*/
public function getTOCData(): ?TOCData {
return $this->mTOCData;
}
/**
* @internal
* @return string
*/
public function getCacheMessage(): string {
return $this->mCacheMessage;
}
/**
* @internal
* @return array
*/
public function getSections(): array {
if ( $this->mTOCData !== null ) {
return $this->mTOCData->toLegacy();
}
// For compatibility
return [];
}
public function &getLinks() {
return $this->mLinks;
}
/**
* @return array Keys are DBKs for the links to special pages in the document
* @since 1.35
*/
public function &getLinksSpecial() {
return $this->mLinksSpecial;
}
public function &getTemplates() {
return $this->mTemplates;
}
public function &getTemplateIds() {
return $this->mTemplateIds;
}
public function &getImages() {
return $this->mImages;
}
public function &getFileSearchOptions() {
return $this->mFileSearchOptions;
}
public function &getExternalLinks() {
return $this->mExternalLinks;
}
public function setNoGallery( $value ): void {
$this->mNoGallery = (bool)$value;
}
public function getNoGallery() {
return $this->mNoGallery;
}
public function getHeadItems() {
return $this->mHeadItems;
}
public function getModules() {
return array_keys( $this->mModuleSet );
}
public function getModuleStyles() {
return array_keys( $this->mModuleStyleSet );
}
/**
* @param bool $showStrategyKeys Defaults to false; if set to true will
* expose the internal `MW_MERGE_STRATEGY_KEY` in the result. This
* should only be used internally to allow safe merge of config vars.
* @return array
* @since 1.23
*/
public function getJsConfigVars( bool $showStrategyKeys = false ) {
$result = $this->mJsConfigVars;
// Don't expose the internal strategy key
foreach ( $result as &$value ) {
if ( is_array( $value ) && !$showStrategyKeys ) {
unset( $value[self::MW_MERGE_STRATEGY_KEY] );
}
}
return $result;
}
public function getWarnings(): array {
return array_keys( $this->mWarnings );
}
public function getIndexPolicy(): string {
// 'noindex' wins if both are set. (T16899)
if ( $this->mNoIndexSet ) {
return 'noindex';
} elseif ( $this->mIndexSet ) {
return 'index';
}
return '';
}
/**
* @return string|null TS_MW timestamp of the revision content
*/
public function getRevisionTimestamp(): ?string {
return $this->mTimestamp;
}
/**
* @return string|null TS_MW timestamp of the revision content
* @deprecated since 1.42; use ::getRevisionTimestamp() instead
*/
public function getTimestamp() {
return $this->getRevisionTimestamp();
}
public function getLimitReportData() {
return $this->mLimitReportData;
}
public function getLimitReportJSData() {
return $this->mLimitReportJSData;
}
public function getEnableOOUI() {
return $this->mEnableOOUI;
}
/**
* Get extra Content-Security-Policy 'default-src' directives
* @since 1.35
* @return string[]
*/
public function getExtraCSPDefaultSrcs() {
return $this->mExtraDefaultSrcs;
}
/**
* Get extra Content-Security-Policy 'script-src' directives
* @since 1.35
* @return string[]
*/
public function getExtraCSPScriptSrcs() {
return $this->mExtraScriptSrcs;
}
/**
* Get extra Content-Security-Policy 'style-src' directives
* @since 1.35
* @return string[]
*/
public function getExtraCSPStyleSrcs() {
return $this->mExtraStyleSrcs;
}
/**
* Set the raw text of the ParserOutput.
*
* If you did not generate html, pass null to mark it as such.
*
* @since 1.42
* @param string|null $text HTML content of ParserOutput or null if not generated
* @param-taint $text exec_html
*/
public function setRawText( ?string $text ): void {
$this->mRawText = $text;
}
/**
* Set the raw text of the ParserOutput.
*
* If you did not generate html, pass null to mark it as such.
*
* @since 1.39 You can now pass null to this function
* @param string|null $text HTML content of ParserOutput or null if not generated
* @param-taint $text exec_html
* @return string|null Previous value of ParserOutput's raw text
* @deprecated since 1.42; use ::setRawText() which matches the getter ::getRawText()
*/
public function setText( $text ) {
return wfSetVar( $this->mRawText, $text, true );
}
/**
* @deprecated since 1.42, use ::addLanguageLink() instead.
*/
public function setLanguageLinks( $ll ) {
return wfSetVar( $this->mLanguageLinks, $ll );
}
public function setTitleText( $t ) {
return wfSetVar( $this->mTitleText, $t );
}
/**
* @param TOCData $tocData Table of contents data for the page
*/
public function setTOCData( TOCData $tocData ): void {
$this->mTOCData = $tocData;
}
/**
* @param array $sectionArray
* @return array Previous value of ::getSections()
*/
public function setSections( array $sectionArray ) {
$oldValue = $this->getSections();
$this->setTOCData( TOCData::fromLegacy( $sectionArray ) );
return $oldValue;
}
public function setIndexPolicy( $policy ): string {
$old = $this->getIndexPolicy();
if ( $policy === 'noindex' ) {
$this->mNoIndexSet = true;
} elseif ( $policy === 'index' ) {
$this->mIndexSet = true;
}
return $old;
}
/**
* @param ?string $timestamp TS_MW timestamp of the revision content
*/
public function setRevisionTimestamp( ?string $timestamp ): void {
$this->mTimestamp = $timestamp;
}
/**
* @param ?string $timestamp TS_MW timestamp of the revision content
*
* @return ?string The previous value of the timestamp
* @deprecated since 1.42; use ::setRevisionTimestamp() instead
*/
public function setTimestamp( $timestamp ) {
return wfSetVar( $this->mTimestamp, $timestamp );
}
/**
* Add a category.
*
* Although ParserOutput::getCategorySortKey() will return exactly
* the sort key you specify here, before storing in the database
* all sort keys will be language converted, HTML entities will be
* decoded, newlines stripped, and then they will be truncated to
* 255 bytes. Thus the "effective" sort key in the DB may be different
* from what is passed to `$sort` here and returned by
* ::getCategorySortKey().
*
* @param string|ParsoidLinkTarget $c The category name
* @param string $sort The sort key; an empty string indicates
* that the default sort key for the page should be used.
*/
public function addCategory( $c, $sort = '' ): void {
if ( $c instanceof ParsoidLinkTarget ) {
$c = $c->getDBkey();
}
$this->mCategories[$c] = $sort;
}
/**
* Overwrite the category map.
* @param array<string,string> $c Map of category names to sort keys
* @since 1.38
*/
public function setCategories( array $c ): void {
$this->mCategories = $c;
}
/**
* @param string $id
* @param string $content
* @param-taint $content exec_html
* @since 1.25
*/
public function setIndicator( $id, $content ): void {
$this->mIndicators[$id] = $content;
}
/**
* Enables OOUI, if true, in any OutputPage instance this ParserOutput
* object is added to.
*
* @since 1.26
* @param bool $enable If OOUI should be enabled or not
*/
public function setEnableOOUI( bool $enable = false ): void {
$this->mEnableOOUI = $enable;
}
/**
* Add a language link.
* @param ParsoidLinkTarget|string $t
*/
public function addLanguageLink( $t ): void {
if ( $t instanceof ParsoidLinkTarget ) {
// language links are unusual in using 'text' rather than 'db key'
// T296019: This should be made more efficient so we don't need
// a full title lookup.
$t = Title::newfromLinkTarget( $t )->getFullText();
}
$this->mLanguageLinks[] = $t;
}
/**
* Add a warning to the output for this page.
* @param MessageValue $mv Note that the parameters must be serializable/deserializable
* with JsonCodec; see the @note on ParserOutput::setExtensionData(). MessageValue guarantees
* that unless the deprecated ParamType::OBJECT or the ->objectParams() method is used.
* @since 1.43
*/
public function addWarningMsgVal( MessageValue $mv ) {
$m = ( new Converter() )->convertMessageValue( $mv );
// These can eventually be stored as MessageValue instead of converting to Message.
$this->addWarningMsg( $m->getKey(), ...$m->getParams() );
}
/**
* Add a warning to the output for this page.
* @param string $msg The localization message key for the warning
* @param mixed|JsonDeserializable ...$args Optional arguments for the
* message. These arguments must be serializable/deserializable with
* JsonCodec; see the @note on ParserOutput::setExtensionData()
* @since 1.38
*/