Movatterモバイル変換


[0]ホーム

URL:


MediaWiki master
TextContent.php
Go to the documentation of this file.
1<?php
21namespaceMediaWiki\Content;
22
23use InvalidArgumentException;
24useMediaWiki\Exception\MWUnknownContentModelException;
25useMediaWiki\Language\Language;
26useMediaWiki\MainConfigNames;
27useMediaWiki\MediaWikiServices;
28useWikimedia\Diff\Diff;
29
41classTextContentextendsAbstractContent {
42
46protected$mText;
47
53publicfunction__construct( $text,$model_id =CONTENT_MODEL_TEXT ) {
54 parent::__construct($model_id );
55
56if ( $text ===null || $text ===false ) {
57wfWarn("TextContent constructed with \$text = " . var_export( $text,true ) ."! "
58 ."This may indicate an error in the caller's scope.", 2 );
59
60 $text ='';
61 }
62
63if ( !is_string( $text ) ) {
64thrownew InvalidArgumentException("TextContent expects a string in the constructor." );
65 }
66
67 $this->mText = $text;
68 }
69
75publicfunctioncopy() {
76return $this; # NOTE:this is ok sinceTextContent are immutable.
77 }
78
86publicfunctiongetTextForSummary( $maxlength = 250 ) {
87 $text = $this->getText();
88
89 $truncatedtext =MediaWikiServices::getInstance()->getContentLanguage()->
90 truncateForDatabase( preg_replace("/[\n\r]/",' ', $text ), max( 0, $maxlength ) );
91
92return $truncatedtext;
93 }
94
102publicfunctiongetSize() {
103 $text = $this->getText();
104
105return strlen( $text );
106 }
107
119publicfunctionisCountable( $hasLinks =null ) {
120 $articleCountMethod =MediaWikiServices::getInstance()->getMainConfig()->get(
122
123if ( $this->isRedirect() ) {
124returnfalse;
125 }
126
127if ( $articleCountMethod ==='any' ) {
128returntrue;
129 }
130
131returnfalse;
132 }
133
141publicfunctiongetNativeData() {
142return $this->getText();
143 }
144
155publicfunctiongetText() {
156return$this->mText;
157 }
158
166publicfunctiongetTextForSearchIndex() {
167return $this->getText();
168 }
169
182 $wikitext = $this->convert(CONTENT_MODEL_WIKITEXT,'lossy' );
183'@phan-var WikitextContent $wikitext';
184
185if ( $wikitext ) {
186return $wikitext->getText();
187 }else {
188returnfalse;
189 }
190 }
191
205publicstaticfunctionnormalizeLineEndings( $text ) {
206return str_replace( ["\r\n","\r" ],"\n", rtrim( $text ) );
207 }
208
222publicfunctiondiff(Content $that, ?Language $lang =null ) {
223 $this->checkModelID( $that->getModel() );
225'@phan-var self $that';
226// @todo could implement this in DifferenceEngine and just delegate here?
227
228if ( !$lang ) {
229 $lang =MediaWikiServices::getInstance()->getContentLanguage();
230 }
231
232 $otext = $this->getText();
233 $ntext = $that->getText();
234
235 # Note: Use native PHP diff, external engines don't give us abstract output
236 $ota = explode("\n", $lang->segmentForDiff( $otext ) );
237 $nta = explode("\n", $lang->segmentForDiff( $ntext ) );
238
239 $diff =newDiff( $ota, $nta );
240
241return $diff;
242 }
243
260publicfunctionconvert( $toModel, $lossy ='' ) {
261 $converted = parent::convert( $toModel, $lossy );
262
263if ( $converted !==false ) {
264return $converted;
265 }
266
267 $toHandler = $this->getContentHandlerFactory()->getContentHandler( $toModel );
268
269if ( $toHandler instanceofTextContentHandler ) {
270// NOTE: ignore content serialization format - it's just text anyway.
271 $text = $this->getText();
272 $converted = $toHandler->unserializeContent( $text );
273 }
274
275return $converted;
276 }
277
278}
280class_alias( TextContent::class,'TextContent' );
CONTENT_MODEL_WIKITEXT
const CONTENT_MODEL_WIKITEXT
DefinitionDefines.php:249
CONTENT_MODEL_TEXT
const CONTENT_MODEL_TEXT
DefinitionDefines.php:252
wfWarn
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
DefinitionGlobalFunctions.php:820
MediaWiki\Content\AbstractContent
Base class for all Content objects.
DefinitionAbstractContent.php:38
MediaWiki\Content\AbstractContent\$model_id
string $model_id
DefinitionAbstractContent.php:43
MediaWiki\Content\AbstractContent\isRedirect
isRedirect()
DefinitionAbstractContent.php:251
MediaWiki\Content\AbstractContent\checkModelID
checkModelID( $modelId)
Helper for subclasses.
DefinitionAbstractContent.php:70
MediaWiki\Content\AbstractContent\getContentHandlerFactory
getContentHandlerFactory()
DefinitionAbstractContent.php:87
MediaWiki\Content\TextContentHandler
Base content handler implementation for flat text contents.
DefinitionTextContentHandler.php:40
MediaWiki\Content\TextContent
Content object implementation for representing flat text.
DefinitionTextContent.php:41
MediaWiki\Content\TextContent\normalizeLineEndings
static normalizeLineEndings( $text)
Do a "\\r\\n" -> "\\n" and "\\r" -> "\\n" transformation as well as trim trailing whitespace.
DefinitionTextContent.php:205
MediaWiki\Content\TextContent\$mText
string $mText
DefinitionTextContent.php:46
MediaWiki\Content\TextContent\__construct
__construct( $text, $model_id=CONTENT_MODEL_TEXT)
DefinitionTextContent.php:53
MediaWiki\Content\TextContent\getWikitextForTransclusion
getWikitextForTransclusion()
Returns attempts to convert this content object to wikitext, and then returns the text string.
DefinitionTextContent.php:180
MediaWiki\Content\TextContent\copy
copy()
DefinitionTextContent.php:75
MediaWiki\Content\TextContent\diff
diff(Content $that, ?Language $lang=null)
Diff this content object with another content object.
DefinitionTextContent.php:222
MediaWiki\Content\TextContent\getNativeData
getNativeData()
Returns the text represented by this Content object, as a string.
DefinitionTextContent.php:141
MediaWiki\Content\TextContent\getTextForSummary
getTextForSummary( $maxlength=250)
DefinitionTextContent.php:86
MediaWiki\Content\TextContent\getText
getText()
Returns the text represented by this Content object, as a string.
DefinitionTextContent.php:155
MediaWiki\Content\TextContent\getTextForSearchIndex
getTextForSearchIndex()
Returns the text represented by this Content object, as a string.
DefinitionTextContent.php:166
MediaWiki\Content\TextContent\getSize
getSize()
Returns the text's size in bytes.
DefinitionTextContent.php:102
MediaWiki\Content\TextContent\convert
convert( $toModel, $lossy='')
This implementation provides lossless conversion between content models based on TextContent.
DefinitionTextContent.php:260
MediaWiki\Content\TextContent\isCountable
isCountable( $hasLinks=null)
Returns true if this content is not a redirect, and $wgArticleCountMethod is "any".
DefinitionTextContent.php:119
MediaWiki\Exception\MWUnknownContentModelException
Exception thrown when an unregistered content model is requested.
DefinitionMWUnknownContentModelException.php:16
MediaWiki\Language\Language
Base class for language-specific code.
DefinitionLanguage.php:81
MediaWiki\MainConfigNames
A class containing constants representing the names of configuration variables.
DefinitionMainConfigNames.php:22
MediaWiki\MainConfigNames\ArticleCountMethod
const ArticleCountMethod
Name constant for the ArticleCountMethod setting, for use with Config::get()
DefinitionMainConfigNames.php:2467
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
DefinitionMediaWikiServices.php:250
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
DefinitionMediaWikiServices.php:338
Wikimedia\Diff\Diff
Class representing a 'diff' between two sequences of strings.
DefinitionDiff.php:34
MediaWiki\Content\Content
Content objects represent page content, e.g.
DefinitionContent.php:42
MediaWiki\Content\Content\getModel
getModel()
Get the content model ID.
MediaWiki\Content
DefinitionAbstractContent.php:22

[8]ページ先頭

©2009-2025 Movatter.jp