MediaWiki
REL1_22
|
00001 <?php 00034 abstract class AbstractContent implements Content { 00035 00044 protected $model_id; 00045 00051 public function __construct( $modelId = null ) { 00052 $this->model_id = $modelId; 00053 } 00054 00060 public function getModel() { 00061 return $this->model_id; 00062 } 00063 00074 protected function checkModelID( $modelId ) { 00075 if ( $modelId !== $this->model_id ) { 00076 throw new MWException( 00077 "Bad content model: " . 00078 "expected {$this->model_id} " . 00079 "but got $modelId." 00080 ); 00081 } 00082 } 00083 00089 public function getContentHandler() { 00090 return ContentHandler::getForContent( $this ); 00091 } 00092 00098 public function getDefaultFormat() { 00099 return $this->getContentHandler()->getDefaultFormat(); 00100 } 00101 00107 public function getSupportedFormats() { 00108 return $this->getContentHandler()->getSupportedFormats(); 00109 } 00110 00120 public function isSupportedFormat( $format ) { 00121 if ( !$format ) { 00122 return true; // this means "use the default" 00123 } 00124 00125 return $this->getContentHandler()->isSupportedFormat( $format ); 00126 } 00127 00137 protected function checkFormat( $format ) { 00138 if ( !$this->isSupportedFormat( $format ) ) { 00139 throw new MWException( 00140 "Format $format is not supported for content model " . 00141 $this->getModel() 00142 ); 00143 } 00144 } 00145 00155 public function serialize( $format = null ) { 00156 return $this->getContentHandler()->serializeContent( $this, $format ); 00157 } 00158 00166 public function isEmpty() { 00167 return $this->getSize() === 0; 00168 } 00169 00177 public function isValid() { 00178 return true; 00179 } 00180 00190 public function equals( Content $that = null ) { 00191 if ( is_null( $that ) ) { 00192 return false; 00193 } 00194 00195 if ( $that === $this ) { 00196 return true; 00197 } 00198 00199 if ( $that->getModel() !== $this->getModel() ) { 00200 return false; 00201 } 00202 00203 return $this->getNativeData() === $that->getNativeData(); 00204 } 00205 00234 public function getSecondaryDataUpdates( Title $title, 00235 Content $old = null, 00236 $recursive = true, ParserOutput $parserOutput = null 00237 ) { 00238 if ( $parserOutput === null ) { 00239 $parserOutput = $this->getParserOutput( $title, null, null, false ); 00240 } 00241 00242 return $parserOutput->getSecondaryDataUpdates( $title, $recursive ); 00243 } 00244 00250 public function getRedirectChain() { 00251 global $wgMaxRedirects; 00252 $title = $this->getRedirectTarget(); 00253 if ( is_null( $title ) ) { 00254 return null; 00255 } 00256 // recursive check to follow double redirects 00257 $recurse = $wgMaxRedirects; 00258 $titles = array( $title ); 00259 while ( --$recurse > 0 ) { 00260 if ( $title->isRedirect() ) { 00261 $page = WikiPage::factory( $title ); 00262 $newtitle = $page->getRedirectTarget(); 00263 } else { 00264 break; 00265 } 00266 // Redirects to some special pages are not permitted 00267 if ( $newtitle instanceOf Title && $newtitle->isValidRedirectTarget() ) { 00268 // The new title passes the checks, so make that our current 00269 // title so that further recursion can be checked 00270 $title = $newtitle; 00271 $titles[] = $newtitle; 00272 } else { 00273 break; 00274 } 00275 } 00276 return $titles; 00277 } 00278 00284 public function getRedirectTarget() { 00285 return null; 00286 } 00287 00294 public function getUltimateRedirectTarget() { 00295 $titles = $this->getRedirectChain(); 00296 return $titles ? array_pop( $titles ) : null; 00297 } 00298 00306 public function isRedirect() { 00307 return $this->getRedirectTarget() !== null; 00308 } 00309 00321 public function updateRedirect( Title $target ) { 00322 return $this; 00323 } 00324 00330 public function getSection( $sectionId ) { 00331 return null; 00332 } 00333 00339 public function replaceSection( $section, Content $with, $sectionTitle = '' ) { 00340 return null; 00341 } 00342 00348 public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) { 00349 return $this; 00350 } 00351 00357 public function addSectionHeader( $header ) { 00358 return $this; 00359 } 00360 00366 public function preloadTransform( Title $title, ParserOptions $popts ) { 00367 return $this; 00368 } 00369 00375 public function prepareSave( WikiPage $page, $flags, $baseRevId, User $user ) { 00376 if ( $this->isValid() ) { 00377 return Status::newGood(); 00378 } else { 00379 return Status::newFatal( "invalid-content-data" ); 00380 } 00381 } 00382 00396 public function getDeletionUpdates( WikiPage $page, 00397 ParserOutput $parserOutput = null ) 00398 { 00399 return array( 00400 new LinksDeletionUpdate( $page ), 00401 ); 00402 } 00403 00415 public function matchMagicWord( MagicWord $word ) { 00416 return false; 00417 } 00418 00432 public function convert( $toModel, $lossy = '' ) { 00433 if ( $this->getModel() === $toModel ) { 00434 //nothing to do, shorten out. 00435 return $this; 00436 } 00437 00438 $lossy = ( $lossy === 'lossy' ); // string flag, convert to boolean for convenience 00439 $result = false; 00440 00441 wfRunHooks( 'ConvertContent', array( $this, $toModel, $lossy, &$result ) ); 00442 return $result; 00443 } 00444 }