Merge "Perform a permission check on the title when changing the page language"
[lhc/web/wiklou.git] / includes / Title.php
index 6538538..05f85fa 100644 (file)
@@ -748,6 +748,8 @@ class Title implements LinkTarget {
        /**
         * Escape a text fragment, say from a link, for a URL
         *
+        * @deprecated since 1.30, use Sanitizer::escapeIdForLink() or escapeIdForExternalInterwiki()
+        *
         * @param string $fragment Containing a URL or link fragment (after the "#")
         * @return string Escaped string
         */
@@ -1316,6 +1318,23 @@ class Title implements LinkTarget {
                return self::makeTitle( MWNamespace::getTalk( $this->getNamespace() ), $this->getDBkey() );
        }
 
+       /**
+        * Get a Title object associated with the talk page of this article,
+        * if such a talk page can exist.
+        *
+        * @since 1.30
+        *
+        * @return Title The object for the talk page,
+        *         or null if no associated talk page can exist, according to canHaveTalkPage().
+        */
+       public function getTalkPageIfDefined() {
+               if ( !$this->canHaveTalkPage() ) {
+                       return null;
+               }
+
+               return $this->getTalkPage();
+       }
+
        /**
         * Get a title object associated with the subject page of this
         * talk page
@@ -1382,14 +1401,16 @@ class Title implements LinkTarget {
 
        /**
         * Get the fragment in URL form, including the "#" character if there is one
+        *
         * @return string Fragment in URL form
         */
        public function getFragmentForURL() {
                if ( !$this->hasFragment() ) {
                        return '';
-               } else {
-                       return '#' . self::escapeFragmentForURL( $this->getFragment() );
+               } elseif ( $this->isExternal() && !$this->getTransWikiID() ) {
+                       return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->getFragment() );
                }
+               return '#' . Sanitizer::escapeIdForLink( $this->getFragment() );
        }
 
        /**
@@ -1875,6 +1896,8 @@ class Title implements LinkTarget {
         * protocol-relative, the URL will be expanded to http://
         *
         * @see self::getLocalURL for the arguments.
+        * @param string $query
+        * @param string|bool $query2
         * @return string The URL
         */
        public function getInternalURL( $query = '', $query2 = false ) {
@@ -3172,7 +3195,7 @@ class Title implements LinkTarget {
                if ( $limit > -1 ) {
                        $options['LIMIT'] = $limit;
                }
-               $this->mSubpages = TitleArray::newFromResult(
+               return TitleArray::newFromResult(
                        $dbr->select( 'page',
                                [ 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ],
                                $conds,
@@ -3180,7 +3203,6 @@ class Title implements LinkTarget {
                                $options
                        )
                );
-               return $this->mSubpages;
        }
 
        /**
@@ -3673,7 +3695,7 @@ class Title implements LinkTarget {
         * Returns true if ok, or a getUserPermissionsErrors()-like array otherwise
         *
         * @deprecated since 1.25, use MovePage's methods instead
-        * @param Title $nt The new title
+        * @param Title &$nt The new title
         * @param bool $auth Whether to check user permissions (uses $wgUser)
         * @param string $reason Is the log summary of the move, used for spam checking
         * @return array|bool True on success, getUserPermissionsErrors()-like array on failure
@@ -3725,7 +3747,7 @@ class Title implements LinkTarget {
         * Move a title to a new location
         *
         * @deprecated since 1.25, use the MovePage class instead
-        * @param Title $nt The new title
+        * @param Title &$nt The new title
         * @param bool $auth Indicates whether $wgUser's permissions
         *  should be checked
         * @param string $reason The reason for the move