From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- includes/title/TitleValue.php | 161 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 includes/title/TitleValue.php (limited to 'includes/title/TitleValue.php') diff --git a/includes/title/TitleValue.php b/includes/title/TitleValue.php new file mode 100644 index 00000000..402247c2 --- /dev/null +++ b/includes/title/TitleValue.php @@ -0,0 +1,161 @@ +namespace = $namespace; + $this->dbkey = $dbkey; + $this->fragment = $fragment; + } + + /** + * @return int + */ + public function getNamespace() { + return $this->namespace; + } + + /** + * @return string + */ + public function getFragment() { + 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. + * + * @param string $fragment The fragment name, or "" for the entire page. + * + * @return TitleValue + */ + public function createFragmentTitle( $fragment ) { + return new TitleValue( $this->namespace, $this->dbkey, $fragment ); + } + + /** + * 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; + } + + return $name; + } +} -- cgit v1.2.2