Merge "Use PHP_VERSION constant instead of phpversion() function call"
[lhc/web/wiklou.git] / includes / Title.php
index d8f6b75..a49d52f 100644 (file)
@@ -150,6 +150,9 @@ class Title {
        /** @var bool The (string) language code of the page's language and content code. */
        private $mPageLanguage = false;
 
+       /** @var string The page language code from the database */
+       private $mDbPageLanguage = null;
+
        /** @var TitleValue A corresponding TitleValue object */
        private $mTitleValue = null;
        // @}
@@ -439,6 +442,9 @@ class Title {
                        } else {
                                $this->mContentModel = false; # initialized lazily in getContentModel()
                        }
+                       if ( isset( $row->page_lang ) ) {
+                               $this->mDbPageLanguage = (string)$row->page_lang;
+                       }
                } else { // page not found
                        $this->mArticleID = 0;
                        $this->mLength = 0;
@@ -1365,7 +1371,6 @@ class Title {
         *
         * @param string $name The text
         * @return string The prefixed text
-        * @private
         */
        private function prefix( $name ) {
                $p = '';
@@ -1770,34 +1775,6 @@ class Title {
                return $ret;
        }
 
-       /**
-        * Get an HTML-escaped version of the URL form, suitable for
-        * using in a link, without a server name or fragment
-        *
-        * @see self::getLocalURL for the arguments.
-        * @param string $query
-        * @param bool|string $query2
-        * @return string The URL
-        * @deprecated since 1.19
-        */
-       public function escapeLocalURL( $query = '', $query2 = false ) {
-               wfDeprecated( __METHOD__, '1.19' );
-               return htmlspecialchars( $this->getLocalURL( $query, $query2 ) );
-       }
-
-       /**
-        * Get an HTML-escaped version of the URL form, suitable for
-        * using in a link, including the server name and fragment
-        *
-        * @see self::getLocalURL for the arguments.
-        * @return string The URL
-        * @deprecated since 1.19
-        */
-       public function escapeFullURL( $query = '', $query2 = false ) {
-               wfDeprecated( __METHOD__, '1.19' );
-               return htmlspecialchars( $this->getFullURL( $query, $query2 ) );
-       }
-
        /**
         * Get the URL form for an internal link.
         * - Used in various Squid-related code, in case we have a different
@@ -1837,19 +1814,6 @@ class Title {
                return $url;
        }
 
-       /**
-        * HTML-escaped version of getCanonicalURL()
-        *
-        * @see self::getLocalURL for the arguments.
-        * @since 1.18
-        * @return string
-        * @deprecated since 1.19
-        */
-       public function escapeCanonicalURL( $query = '', $query2 = false ) {
-               wfDeprecated( __METHOD__, '1.19' );
-               return htmlspecialchars( $this->getCanonicalURL( $query, $query2 ) );
-       }
-
        /**
         * Get the edit URL for this Title
         *
@@ -2563,7 +2527,7 @@ class Title {
                        return false;
                }
 
-               if ( !isset( $this->mTitleProtection ) ) {
+               if ( $this->mTitleProtection === null ) {
                        $dbr = wfGetDB( DB_SLAVE );
                        $res = $dbr->select(
                                'protected_titles',
@@ -2578,30 +2542,6 @@ class Title {
                return $this->mTitleProtection;
        }
 
-       /**
-        * Update the title protection status
-        *
-        * @deprecated since 1.19; use WikiPage::doUpdateRestrictions() instead.
-        * @param string $create_perm Permission required for creation
-        * @param string $reason Reason for protection
-        * @param string $expiry Expiry timestamp
-        * @return bool
-        */
-       public function updateTitleProtection( $create_perm, $reason, $expiry ) {
-               wfDeprecated( __METHOD__, '1.19' );
-
-               global $wgUser;
-
-               $limit = array( 'create' => $create_perm );
-               $expiry = array( 'create' => $expiry );
-
-               $page = WikiPage::factory( $this );
-               $cascade = false;
-               $status = $page->doUpdateRestrictions( $limit, $expiry, $cascade, $reason, $wgUser );
-
-               return $status->isOK();
-       }
-
        /**
         * Remove any title protection due to page existing
         */
@@ -2716,26 +2656,29 @@ class Title {
         * @since 1.23
         */
        public function areCascadeProtectionSourcesLoaded( $getPages = true ) {
-               return $getPages ? isset( $this->mCascadeSources ) : isset( $this->mHasCascadingRestrictions );
+               return $getPages ? $this->mCascadeSources !== null : $this->mHasCascadingRestrictions !== null;
        }
 
        /**
         * Cascading protection: Get the source of any cascading restrictions on this page.
         *
         * @param bool $getPages Whether or not to retrieve the actual pages
-        *        that the restrictions have come from.
-        * @return array|bool Array of Title objects of the pages from which cascading restrictions
-        *     have come, false for none, or true if such restrictions exist, but $getPages
-        *     was not set.  The restriction array is an array of each type, each of which
-        *     contains a array of unique groups.
+        *        that the restrictions have come from and the actual restrictions
+        *        themselves.
+        * @return array Two elements: First is an array of Title objects of the
+        *        pages from which cascading restrictions have come, false for
+        *        none, or true if such restrictions exist but $getPages was not
+        *        set. Second is an array like that returned by
+        *        Title::getAllRestrictions(), or an empty array if $getPages is
+        *        false.
         */
        public function getCascadeProtectionSources( $getPages = true ) {
                global $wgContLang;
                $pagerestrictions = array();
 
-               if ( isset( $this->mCascadeSources ) && $getPages ) {
+               if ( $this->mCascadeSources !== null && $getPages ) {
                        return array( $this->mCascadeSources, $this->mCascadingRestrictions );
-               } elseif ( isset( $this->mHasCascadingRestrictions ) && !$getPages ) {
+               } elseif ( $this->mHasCascadingRestrictions !== null && !$getPages ) {
                        return array( $this->mHasCascadingRestrictions, $pagerestrictions );
                }
 
@@ -2834,7 +2777,8 @@ class Title {
         * Accessor/initialisation for mRestrictions
         *
         * @param string $action Action that permission needs to be checked for
-        * @return array Array of Strings the array of groups allowed to edit this article
+        * @return array Restriction levels needed to take the action. All levels
+        *     are required.
         */
        public function getRestrictions( $action ) {
                if ( !$this->mRestrictionsLoaded ) {
@@ -2848,9 +2792,8 @@ class Title {
        /**
         * Accessor/initialisation for mRestrictions
         *
-        * @return array Array of Arrays of Strings the first level indexed by
-        * action, the second level containing the names of the groups
-        * allowed to perform each action
+        * @return array Keys are actions, values are arrays as returned by
+        *     Title::getRestrictions()
         * @since 1.23
         */
        public function getAllRestrictions() {
@@ -3081,7 +3024,7 @@ class Title {
                # alone to cache the result.  There's no point in having it hanging
                # around uninitialized in every Title object; therefore we only add it
                # if needed and don't declare it statically.
-               if ( !isset( $this->mHasSubpages ) ) {
+               if ( $this->mHasSubpages === null ) {
                        $this->mHasSubpages = false;
                        $subpages = $this->getSubpages( 1 );
                        if ( $subpages instanceof TitleArray ) {
@@ -3317,6 +3260,7 @@ class Title {
                $this->mContentModel = false;
                $this->mEstimateRevisions = null;
                $this->mPageLanguage = false;
+               $this->mDbPageLanguage = null;
        }
 
        /**
@@ -4769,7 +4713,9 @@ class Title {
         * @return string Last-touched timestamp
         */
        public function getTouched( $db = null ) {
-               $db = isset( $db ) ? $db : wfGetDB( DB_SLAVE );
+               if ( $db === null ) {
+                       $db = wfGetDB( DB_SLAVE );
+               }
                $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
                return $touched;
        }
@@ -4974,6 +4920,12 @@ class Title {
                        return $wgLang;
                }
 
+               // Checking if DB language is set
+               if ( $this->mDbPageLanguage ) {
+                       wfProfileOut( __METHOD__ );
+                       return wfGetLangObj( $this->mDbPageLanguage );
+               }
+
                if ( !$this->mPageLanguage || $this->mPageLanguage[1] !== $wgLanguageCode ) {
                        // Note that this may depend on user settings, so the cache should
                        // be only per-request.
@@ -4987,6 +4939,7 @@ class Title {
                } else {
                        $langObj = wfGetLangObj( $this->mPageLanguage[0] );
                }
+
                wfProfileOut( __METHOD__ );
                return $langObj;
        }