MediaWiki
REL1_23
|
00001 <?php 00036 class TitleValue { 00037 00041 protected $namespace; 00042 00046 protected $dbkey; 00047 00051 protected $fragment; 00052 00069 public function __construct( $namespace, $dbkey, $fragment = '' ) { 00070 if ( !is_int( $namespace ) ) { 00071 throw new InvalidArgumentException( '$namespace must be an integer' ); 00072 } 00073 00074 if ( !is_string( $dbkey ) ) { 00075 throw new InvalidArgumentException( '$dbkey must be a string' ); 00076 } 00077 00078 // Sanity check, no full validation or normalization applied here! 00079 if ( preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ) ) { 00080 throw new InvalidArgumentException( '$dbkey must be a valid DB key: ' . $dbkey ); 00081 } 00082 00083 if ( !is_string( $fragment ) ) { 00084 throw new InvalidArgumentException( '$fragment must be a string' ); 00085 } 00086 00087 if ( $dbkey === '' ) { 00088 throw new InvalidArgumentException( '$dbkey must not be empty' ); 00089 } 00090 00091 $this->namespace = $namespace; 00092 $this->dbkey = $dbkey; 00093 $this->fragment = $fragment; 00094 } 00095 00099 public function getNamespace() { 00100 return $this->namespace; 00101 } 00102 00106 public function getFragment() { 00107 return $this->fragment; 00108 } 00109 00116 public function getDBkey() { 00117 return $this->dbkey; 00118 } 00119 00131 public function getText() { 00132 return str_replace( '_', ' ', $this->getDBkey() ); 00133 } 00134 00142 public function createFragmentTitle( $fragment ) { 00143 return new TitleValue( $this->namespace, $this->dbkey, $fragment ); 00144 } 00145 00153 public function __toString() { 00154 $name = $this->namespace . ':' . $this->dbkey; 00155 00156 if ( $this->fragment !== '' ) { 00157 $name .= '#' . $this->fragment; 00158 } 00159 00160 return $name; 00161 } 00162 }