+ /**
+ * Returns true if the title is valid, false if it is invalid.
+ *
+ * Valid titles can be round-tripped via makeTitleSafe() and newFromText().
+ * Invalid titles may get returned from makeTitle(), and it may be useful to
+ * allow them to exist, e.g. in order to process log entries about pages in
+ * namespaces that belong to extensions that are no longer installed.
+ *
+ * @note This method is relatively expensive. When constructing Title
+ * objects that need to be valid, use an instantiator method that is guaranteed
+ * to return valid titles, such as makeTitleSafe() or newFromText().
+ *
+ * @return bool
+ */
+ public function isValid() {
+ $ns = $this->getNamespace();
+
+ if ( !MWNamespace::exists( $ns ) ) {
+ return false;
+ }
+
+ try {
+ $parser = MediaWikiServices::getInstance()->getTitleParser();
+ $parser->parseTitle( $this->getDBkey(), $ns );
+ return true;
+ } catch ( MalformedTitleException $ex ) {
+ return false;
+ }
+ }
+