Merge "Make sure Parsoid doesn't get snobbish and treat non-html5 tags badly."
[lhc/web/wiklou.git] / includes / Title.php
index 957af2b..5d71251 100644 (file)
@@ -88,7 +88,6 @@ class Title {
        var $mHasSubpage;                 // /< Whether a page has any subpages
        // @}
 
-
        /**
         * Constructor
         */
@@ -149,7 +148,7 @@ class Title {
                $t->mDbkeyform = str_replace( ' ', '_', $filteredText );
                $t->mDefaultNamespace = $defaultNamespace;
 
-               static $cachedcount = 0 ;
+               static $cachedcount = 0;
                if ( $t->secureAndSplit() ) {
                        if ( $defaultNamespace == NS_MAIN ) {
                                if ( $cachedcount >= self::CACHE_MAX ) {
@@ -681,6 +680,7 @@ class Title {
        public function getContentModel() {
                if ( !$this->mContentModel ) {
                        $linkCache = LinkCache::singleton();
+                       $linkCache->addLinkObj( $this );
                        $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' );
                }
 
@@ -1296,6 +1296,7 @@ class Title {
         * Used for the title field in <a> tags.
         *
         * @return String the text, including any prefixes
+        * @deprecated since 1.19
         */
        public function getEscapedText() {
                wfDeprecated( __METHOD__, '1.19' );
@@ -1527,6 +1528,7 @@ class Title {
         * @param $query string
         * @param $query2 bool|string
         * @return String the URL
+        * @deprecated since 1.19
         */
        public function escapeLocalURL( $query = '', $query2 = false ) {
                wfDeprecated( __METHOD__, '1.19' );
@@ -1541,6 +1543,7 @@ class Title {
         *
         * @see self::getLocalURL
         * @return String the URL
+        * @deprecated since 1.19
         */
        public function escapeFullURL( $query = '', $query2 = false ) {
                wfDeprecated( __METHOD__, '1.19' );
@@ -1598,6 +1601,7 @@ class Title {
         * @see self::getLocalURL
         * @since 1.18
         * @return string
+        * @deprecated since 1.19
         */
        public function escapeCanonicalURL( $query = '', $query2 = false ) {
                wfDeprecated( __METHOD__, '1.19' );
@@ -1728,8 +1732,10 @@ class Title {
         */
        private function checkQuickPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) {
                if ( $action == 'create' ) {
-                       if ( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
-                                ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) {
+                       if (
+                               ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
+                               ( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) )
+                       ) {
                                $errors[] = $user->isAnon() ? array( 'nocreatetext' ) : array( 'nocreate-loggedin' );
                        }
                } elseif ( $action == 'move' ) {
@@ -1818,8 +1824,11 @@ class Title {
                        $errors = $this->resultToError( $errors, $result );
                }
                // Check getUserPermissionsErrorsExpensive hook
-               if ( $doExpensiveQueries && !( $short && count( $errors ) > 0 ) &&
-                        !wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) ) ) {
+               if (
+                       $doExpensiveQueries
+                       && !( $short && count( $errors ) > 0 )
+                       && !wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) )
+               ) {
                        $errors = $this->resultToError( $errors, $result );
                }
 
@@ -2146,7 +2155,7 @@ class Title {
                                # If it's a special page, ditch the subpage bit and check again
                                $name = $this->getDBkey();
                                list( $name, /* $subpage */ ) = SpecialPageFactory::resolveAlias( $name );
-                               if ( $name !== false ) {
+                               if ( $name ) {
                                        $pure = SpecialPage::getTitleFor( $name )->getPrefixedText();
                                        if ( in_array( $pure, $wgWhitelistRead, true ) ) {
                                                $whitelisted = true;
@@ -2274,8 +2283,10 @@ class Title {
        public function userCanEditJsSubpage() {
                global $wgUser;
                wfDeprecated( __METHOD__, '1.19' );
-               return ( ( $wgUser->isAllowedAll( 'editusercssjs', 'edituserjs' ) )
-                          || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
+               return (
+                       ( $wgUser->isAllowedAll( 'editusercssjs', 'edituserjs' ) )
+                       || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform )
+               );
        }
 
        /**
@@ -2525,7 +2536,7 @@ class Title {
 
                if ( $getPages ) {
                        $cols = array( 'pr_page', 'page_namespace', 'page_title',
-                                                  'pr_expiry', 'pr_type', 'pr_level' );
+                               'pr_expiry', 'pr_type', 'pr_level' );
                        $where_clauses[] = 'page_id=pr_page';
                        $tables[] = 'page';
                } else {
@@ -2553,8 +2564,10 @@ class Title {
                                                $pagerestrictions[$row->pr_type] = array();
                                        }
 
-                                       if ( isset( $pagerestrictions[$row->pr_type] ) &&
-                                                !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] ) ) {
+                                       if (
+                                               isset( $pagerestrictions[$row->pr_type] )
+                                               && !in_array( $row->pr_level, $pagerestrictions[$row->pr_type] )
+                                       ) {
                                                $pagerestrictions[$row->pr_type][] = $row->pr_level;
                                        }
                                } else {
@@ -2780,6 +2793,10 @@ class Title {
         * Purge expired restrictions from the page_restrictions table
         */
        static function purgeExpiredRestrictions() {
+               if ( wfReadOnly() ) {
+                       return;
+               }
+
                $dbw = wfGetDB( DB_MASTER );
                $dbw->delete(
                        'page_restrictions',
@@ -2931,22 +2948,21 @@ class Title {
         * @return Bool
         */
        public function isRedirect( $flags = 0 ) {
-               if ( !is_null( $this->mRedirect ) ) {
+               if ( !( $flags & Title::GAID_FOR_UPDATE ) && !is_null( $this->mRedirect ) ) {
                        return $this->mRedirect;
                }
-               # Calling getArticleID() loads the field from cache as needed
+
                if ( !$this->getArticleID( $flags ) ) {
                        return $this->mRedirect = false;
                }
 
                $linkCache = LinkCache::singleton();
+               $linkCache->addLinkObj( $this );
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
+
                if ( $cached === null ) {
-                       // TODO: check the assumption that the cache actually knows about this title
-                       // and handle this, such as get the title from the database.
-                       // See https://bugzilla.wikimedia.org/show_bug.cgi?id=37209
-                       wfDebug( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() );
-                       wfDebug( wfBacktrace() );
+                       // Should not happen
+                       throw new MWException( "LinkCache doesn't know redirect status of this title: " . $this->getPrefixedDBkey() );
                }
 
                $this->mRedirect = (bool)$cached;
@@ -2962,20 +2978,21 @@ class Title {
         * @return Int
         */
        public function getLength( $flags = 0 ) {
-               if ( $this->mLength != -1 ) {
+               if ( !( $flags & Title::GAID_FOR_UPDATE ) && $this->mLength != -1 ) {
                        return $this->mLength;
                }
-               # Calling getArticleID() loads the field from cache as needed
+
                if ( !$this->getArticleID( $flags ) ) {
                        return $this->mLength = 0;
                }
+
                $linkCache = LinkCache::singleton();
+               $linkCache->addLinkObj( $this );
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'length' );
-               if ( $cached === null ) { # check the assumption that the cache actually knows about this title
-                       # XXX: this does apparently happen, see https://bugzilla.wikimedia.org/show_bug.cgi?id=37209
-                       #      as a stop gap, perhaps log this, but don't throw an exception?
-                       wfDebug( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() );
-                       wfDebug( wfBacktrace() );
+
+               if ( $cached === null ) {
+                       // Should not happen
+                       throw new MWException( "LinkCache doesn't know redirect status of this title: " . $this->getPrefixedDBkey() );
                }
 
                $this->mLength = intval( $cached );
@@ -2994,17 +3011,18 @@ class Title {
                if ( !( $flags & Title::GAID_FOR_UPDATE ) && $this->mLatestID !== false ) {
                        return intval( $this->mLatestID );
                }
-               # Calling getArticleID() loads the field from cache as needed
+
                if ( !$this->getArticleID( $flags ) ) {
                        return $this->mLatestID = 0;
                }
+
                $linkCache = LinkCache::singleton();
                $linkCache->addLinkObj( $this );
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' );
-               if ( $cached === null ) { # check the assumption that the cache actually knows about this title
-                       # XXX: this does apparently happen, see https://bugzilla.wikimedia.org/show_bug.cgi?id=37209
-                       #      as a stop gap, perhaps log this, but don't throw an exception?
-                       throw new MWException( "LinkCache doesn't currently know about this title: " . $this->getPrefixedDBkey() );
+
+               if ( $cached === null ) {
+                       // Should not happen
+                       throw new MWException( "LinkCache doesn't know latest revision ID of this title: " . $this->getPrefixedDBkey() );
                }
 
                $this->mLatestID = intval( $cached );
@@ -3189,15 +3207,18 @@ class Title {
                # Pages with "/./" or "/../" appearing in the URLs will often be un-
                # reachable due to the way web browsers deal with 'relative' URLs.
                # Also, they conflict with subpage syntax.  Forbid them explicitly.
-               if ( strpos( $dbkey, '.' ) !== false &&
-                        ( $dbkey === '.' || $dbkey === '..' ||
-                          strpos( $dbkey, './' ) === 0  ||
-                          strpos( $dbkey, '../' ) === 0 ||
-                          strpos( $dbkey, '/./' ) !== false ||
-                          strpos( $dbkey, '/../' ) !== false  ||
-                          substr( $dbkey, -2 ) == '/.' ||
-                          substr( $dbkey, -3 ) == '/..' ) )
-               {
+               if (
+                       strpos( $dbkey, '.' ) !== false &&
+                       (
+                               $dbkey === '.' || $dbkey === '..' ||
+                               strpos( $dbkey, './' ) === 0 ||
+                               strpos( $dbkey, '../' ) === 0 ||
+                               strpos( $dbkey, '/./' ) !== false ||
+                               strpos( $dbkey, '/../' ) !== false ||
+                               substr( $dbkey, -2 ) == '/.' ||
+                               substr( $dbkey, -3 ) == '/..'
+                       )
+               ) {
                        return false;
                }
 
@@ -3210,9 +3231,10 @@ class Title {
                # underlying database field. We make an exception for special pages, which
                # don't need to be stored in the database, and may edge over 255 bytes due
                # to subpage syntax for long titles, e.g. [[Special:Block/Long name]]
-               if ( ( $this->mNamespace != NS_SPECIAL && strlen( $dbkey ) > 255 ) ||
-                 strlen( $dbkey ) > 512 )
-               {
+               if (
+                       ( $this->mNamespace != NS_SPECIAL && strlen( $dbkey ) > 255 )
+                       || strlen( $dbkey ) > 512
+               ) {
                        return false;
                }
 
@@ -3423,7 +3445,6 @@ class Title {
                return $retVal;
        }
 
-
        /**
         * Get a list of URLs to purge from the Squid cache when this
         * page changes
@@ -3507,9 +3528,11 @@ class Title {
                if ( strlen( $nt->getDBkey() ) < 1 ) {
                        $errors[] = array( 'articleexists' );
                }
-               if ( ( $this->getDBkey() == '' ) ||
-                        ( !$oldid ) ||
-                        ( $nt->getDBkey() == '' ) ) {
+               if (
+                       ( $this->getDBkey() == '' ) ||
+                       ( !$oldid ) ||
+                       ( $nt->getDBkey() == '' )
+               ) {
                        $errors[] = array( 'badarticleerror' );
                }
 
@@ -4282,7 +4305,7 @@ class Title {
                }
                $old_cmp = '>';
                $new_cmp = '<';
-               $options = (array) $options;
+               $options = (array)$options;
                if ( in_array( 'include_old', $options ) ) {
                        $old_cmp = '>=';
                }
@@ -4372,7 +4395,7 @@ class Title {
                $isKnown = null;
 
                /**
-                * Allows overriding default behaviour for determining if a page exists.
+                * Allows overriding default behavior for determining if a page exists.
                 * If $isKnown is kept as null, regular checks happen. If it's
                 * a boolean, this value is returned by the isKnown method.
                 *
@@ -4441,7 +4464,7 @@ class Title {
                        // Use always content language to avoid loading hundreds of languages
                        // to get the link color.
                        global $wgContLang;
-                       list( $name, $lang ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->getText() ) );
+                       list( $name, ) = MessageCache::singleton()->figureMessage( $wgContLang->lcfirst( $this->getText() ) );
                        $message = wfMessage( $name )->inLanguage( $wgContLang )->useDatabase( false );
                        return $message->exists();
                }