X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/title/TitleValue.php diff --git a/includes/title/TitleValue.php b/includes/title/TitleValue.php new file mode 100644 index 00000000..7c370f1a --- /dev/null +++ b/includes/title/TitleValue.php @@ -0,0 +1,204 @@ +namespace = $namespace; + $this->dbkey = $dbkey; + $this->fragment = $fragment; + $this->interwiki = $interwiki; + } + + /** + * @return int + */ + public function getNamespace() { + return $this->namespace; + } + + /** + * @since 1.27 + * @param int $ns + * @return bool + */ + public function inNamespace( $ns ) { + return $this->namespace == $ns; + } + + /** + * @return string + */ + public function getFragment() { + return $this->fragment; + } + + /** + * @since 1.27 + * @return bool + */ + public function hasFragment() { + return $this->fragment !== ''; + } + + /** + * Returns the title's DB key, as supplied to the constructor, + * without namespace prefix or fragment. + * + * @return string + */ + public function getDBkey() { + return $this->dbkey; + } + + /** + * Returns the title in text form, + * without namespace prefix or fragment. + * + * This is computed from the DB key by replacing any underscores with spaces. + * + * @note To get a title string that includes the namespace and/or fragment, + * use a TitleFormatter. + * + * @return string + */ + public function getText() { + return str_replace( '_', ' ', $this->getDBkey() ); + } + + /** + * Creates a new TitleValue for a different fragment of the same page. + * + * @since 1.27 + * @param string $fragment The fragment name, or "" for the entire page. + * + * @return TitleValue + */ + public function createFragmentTarget( $fragment ) { + return new TitleValue( + $this->namespace, + $this->dbkey, + $fragment, + $this->interwiki + ); + } + + /** + * Whether it has an interwiki part + * + * @since 1.27 + * @return bool + */ + public function isExternal() { + return $this->interwiki !== ''; + } + + /** + * Returns the interwiki part + * + * @since 1.27 + * @return string + */ + public function getInterwiki() { + return $this->interwiki; + } + + /** + * Returns a string representation of the title, for logging. This is purely informative + * and must not be used programmatically. Use the appropriate TitleFormatter to generate + * the correct string representation for a given use. + * + * @return string + */ + public function __toString() { + $name = $this->namespace . ':' . $this->dbkey; + + if ( $this->fragment !== '' ) { + $name .= '#' . $this->fragment; + } + + if ( $this->interwiki !== '' ) { + $name = $this->interwiki . ':' . $name; + } + + return $name; + } +}