MediaWiki  1.23.2
AbstractContent.php
Go to the documentation of this file.
1 <?php
34 abstract class AbstractContent implements Content {
43  protected $model_id;
44 
50  public function __construct( $modelId = null ) {
51  $this->model_id = $modelId;
52  }
53 
59  public function getModel() {
60  return $this->model_id;
61  }
62 
71  protected function checkModelID( $modelId ) {
72  if ( $modelId !== $this->model_id ) {
73  throw new MWException(
74  "Bad content model: " .
75  "expected {$this->model_id} " .
76  "but got $modelId."
77  );
78  }
79  }
80 
86  public function getContentHandler() {
87  return ContentHandler::getForContent( $this );
88  }
89 
95  public function getDefaultFormat() {
96  return $this->getContentHandler()->getDefaultFormat();
97  }
98 
104  public function getSupportedFormats() {
105  return $this->getContentHandler()->getSupportedFormats();
106  }
107 
117  public function isSupportedFormat( $format ) {
118  if ( !$format ) {
119  return true; // this means "use the default"
120  }
121 
122  return $this->getContentHandler()->isSupportedFormat( $format );
123  }
124 
132  protected function checkFormat( $format ) {
133  if ( !$this->isSupportedFormat( $format ) ) {
134  throw new MWException(
135  "Format $format is not supported for content model " .
136  $this->getModel()
137  );
138  }
139  }
140 
150  public function serialize( $format = null ) {
151  return $this->getContentHandler()->serializeContent( $this, $format );
152  }
153 
161  public function isEmpty() {
162  return $this->getSize() === 0;
163  }
164 
174  public function isValid() {
175  return true;
176  }
177 
187  public function equals( Content $that = null ) {
188  if ( is_null( $that ) ) {
189  return false;
190  }
191 
192  if ( $that === $this ) {
193  return true;
194  }
195 
196  if ( $that->getModel() !== $this->getModel() ) {
197  return false;
198  }
199 
200  return $this->getNativeData() === $that->getNativeData();
201  }
202 
226  public function getSecondaryDataUpdates( Title $title, Content $old = null,
227  $recursive = true, ParserOutput $parserOutput = null ) {
228  if ( $parserOutput === null ) {
229  $parserOutput = $this->getParserOutput( $title, null, null, false );
230  }
231 
232  return $parserOutput->getSecondaryDataUpdates( $title, $recursive );
233  }
234 
242  public function getRedirectChain() {
243  global $wgMaxRedirects;
244  $title = $this->getRedirectTarget();
245  if ( is_null( $title ) ) {
246  return null;
247  }
248  // recursive check to follow double redirects
249  $recurse = $wgMaxRedirects;
250  $titles = array( $title );
251  while ( --$recurse > 0 ) {
252  if ( $title->isRedirect() ) {
253  $page = WikiPage::factory( $title );
254  $newtitle = $page->getRedirectTarget();
255  } else {
256  break;
257  }
258  // Redirects to some special pages are not permitted
259  if ( $newtitle instanceof Title && $newtitle->isValidRedirectTarget() ) {
260  // The new title passes the checks, so make that our current
261  // title so that further recursion can be checked
262  $title = $newtitle;
263  $titles[] = $newtitle;
264  } else {
265  break;
266  }
267  }
268 
269  return $titles;
270  }
271 
281  public function getRedirectTarget() {
282  return null;
283  }
284 
294  public function getUltimateRedirectTarget() {
295  $titles = $this->getRedirectChain();
296 
297  return $titles ? array_pop( $titles ) : null;
298  }
299 
307  public function isRedirect() {
308  return $this->getRedirectTarget() !== null;
309  }
310 
323  public function updateRedirect( Title $target ) {
324  return $this;
325  }
326 
334  public function getSection( $sectionId ) {
335  return null;
336  }
337 
345  public function replaceSection( $section, Content $with, $sectionTitle = '' ) {
346  return null;
347  }
348 
356  public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
357  return $this;
358  }
359 
367  public function addSectionHeader( $header ) {
368  return $this;
369  }
370 
378  public function preloadTransform( Title $title, ParserOptions $popts, $params = array() ) {
379  return $this;
380  }
381 
389  public function prepareSave( WikiPage $page, $flags, $baseRevId, User $user ) {
390  if ( $this->isValid() ) {
391  return Status::newGood();
392  } else {
393  return Status::newFatal( "invalid-content-data" );
394  }
395  }
396 
407  public function getDeletionUpdates( WikiPage $page, ParserOutput $parserOutput = null ) {
408  return array(
409  new LinksDeletionUpdate( $page ),
410  );
411  }
412 
425  public function matchMagicWord( MagicWord $word ) {
426  return false;
427  }
428 
440  public function convert( $toModel, $lossy = '' ) {
441  if ( $this->getModel() === $toModel ) {
442  //nothing to do, shorten out.
443  return $this;
444  }
445 
446  $lossy = ( $lossy === 'lossy' ); // string flag, convert to boolean for convenience
447  $result = false;
448 
449  wfRunHooks( 'ConvertContent', array( $this, $toModel, $lossy, &$result ) );
450 
451  return $result;
452  }
453 }
AbstractContent\getSecondaryDataUpdates
getSecondaryDataUpdates(Title $title, Content $old=null, $recursive=true, ParserOutput $parserOutput=null)
Returns a list of DataUpdate objects for recording information about this Content in some secondary d...
Definition: AbstractContent.php:225
ParserOptions
Set options of the Parser.
Definition: ParserOptions.php:31
AbstractContent\addSectionHeader
addSectionHeader( $header)
Definition: AbstractContent.php:366
$result
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. $reader:XMLReader object $logInfo:Array of information Return false to stop further processing of the tag 'ImportHandlePageXMLTag':When parsing a XML tag in a page. $reader:XMLReader object $pageInfo:Array of information Return false to stop further processing of the tag 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information Return false to stop further processing of the tag 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. $reader:XMLReader object Return false to stop further processing of the tag 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. $reader:XMLReader object $revisionInfo:Array of information Return false to stop further processing of the tag 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. $title:Title object for the current page $request:WebRequest $ignoreRedirect:boolean to skip redirect check $target:Title/string of redirect target $article:Article object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) $article:article(object) being checked 'IsTrustedProxy':Override the result of wfIsTrustedProxy() $ip:IP being check $result:Change this value to override the result of wfIsTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of User::isValidEmailAddr(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetMagic':DEPRECATED, use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetSpecialPageAliases':DEPRECATED, use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Associative array mapping language codes to prefixed links of the form "language:title". & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LinkBegin':Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1528
ParserOutput
Definition: ParserOutput.php:24
AbstractContent\isRedirect
isRedirect()
Definition: AbstractContent.php:306
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
AbstractContent\convert
convert( $toModel, $lossy='')
This base implementation calls the hook ConvertContent to enable custom conversions.
Definition: AbstractContent.php:439
AbstractContent\checkFormat
checkFormat( $format)
Definition: AbstractContent.php:131
AbstractContent\replaceSection
replaceSection( $section, Content $with, $sectionTitle='')
Definition: AbstractContent.php:344
AbstractContent\getRedirectTarget
getRedirectTarget()
Subclasses that implement redirects should override this.
Definition: AbstractContent.php:280
AbstractContent\updateRedirect
updateRedirect(Title $target)
This default implementation always returns $this.
Definition: AbstractContent.php:322
WikiPage
Class representing a MediaWiki article and history.
Definition: WikiPage.php:37
Status\newGood
static newGood( $value=null)
Factory function for good results.
Definition: Status.php:77
$params
$params
Definition: styleTest.css.php:40
AbstractContent\getRedirectChain
getRedirectChain()
Definition: AbstractContent.php:241
AbstractContent\equals
equals(Content $that=null)
Definition: AbstractContent.php:186
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2113
AbstractContent\isEmpty
isEmpty()
Definition: AbstractContent.php:160
AbstractContent\getUltimateRedirectTarget
getUltimateRedirectTarget()
Definition: AbstractContent.php:293
Content\getSize
getSize()
Returns the content's nominal size in bogo-bytes.
AbstractContent\matchMagicWord
matchMagicWord(MagicWord $word)
This default implementation always returns false.
Definition: AbstractContent.php:424
AbstractContent\preSaveTransform
preSaveTransform(Title $title, User $user, ParserOptions $popts)
Definition: AbstractContent.php:355
AbstractContent\getDefaultFormat
getDefaultFormat()
Definition: AbstractContent.php:94
MWException
MediaWiki exception.
Definition: MWException.php:26
AbstractContent\checkModelID
checkModelID( $modelId)
Definition: AbstractContent.php:70
AbstractContent\getContentHandler
getContentHandler()
Definition: AbstractContent.php:85
AbstractContent\preloadTransform
preloadTransform(Title $title, ParserOptions $popts, $params=array())
Definition: AbstractContent.php:377
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:103
$titles
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
AbstractContent\isSupportedFormat
isSupportedFormat( $format)
Definition: AbstractContent.php:116
AbstractContent\serialize
serialize( $format=null)
Definition: AbstractContent.php:149
Title\isValidRedirectTarget
isValidRedirectTarget()
Check if this Title is a valid redirect target.
Definition: Title.php:4789
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4001
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
AbstractContent\__construct
__construct( $modelId=null)
Definition: AbstractContent.php:49
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
MagicWord
This class encapsulates "magic words" such as "#redirect", NOTOC, etc.
Definition: MagicWord.php:61
$section
$section
Definition: Utf8Test.php:88
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
AbstractContent
Base implementation for content objects.
Definition: AbstractContent.php:34
AbstractContent\getSection
getSection( $sectionId)
Definition: AbstractContent.php:333
LinksDeletionUpdate
Update object handling the cleanup of links tables after a page was deleted.
Definition: LinksUpdate.php:871
Content\getNativeData
getNativeData()
Returns native representation of the data.
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
AbstractContent\getDeletionUpdates
getDeletionUpdates(WikiPage $page, ParserOutput $parserOutput=null)
Definition: AbstractContent.php:406
Content
Base interface for content objects.
Definition: Content.php:34
AbstractContent\getModel
getModel()
Definition: AbstractContent.php:58
AbstractContent\$model_id
string $model_id
Name of the content model this Content object represents.
Definition: AbstractContent.php:42
Title
Represents a title within MediaWiki.
Definition: Title.php:35
Content\getParserOutput
getParserOutput(Title $title, $revId=null, ParserOptions $options=null, $generateHtml=true)
Parse the Content object and generate a ParserOutput from the result.
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
AbstractContent\prepareSave
prepareSave(WikiPage $page, $flags, $baseRevId, User $user)
Definition: AbstractContent.php:388
ContentHandler\getForContent
static getForContent(Content $content)
Returns the appropriate ContentHandler singleton for the given Content object.
Definition: ContentHandler.php:275
AbstractContent\getSupportedFormats
getSupportedFormats()
Definition: AbstractContent.php:103
Status\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: Status.php:63
AbstractContent\isValid
isValid()
Subclasses may override this to implement (light weight) validation.
Definition: AbstractContent.php:173