Merge "Database: Cast to int in estimateRowCount(), selectRowCount()"
[lhc/web/wiklou.git] / includes / Title.php
index 0cac64a..9a7cd04 100644 (file)
@@ -942,9 +942,9 @@ class Title {
         * @return string Content model id
         */
        public function getContentModel( $flags = 0 ) {
-               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->mContentModel && $this->getArticleID( $flags ) ) {
                        $linkCache = LinkCache::singleton();
+                       $linkCache->addLinkObj( $this ); # in case we already had an article ID
                        $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' );
                }
 
@@ -3185,13 +3185,13 @@ class Title {
                if ( !is_null( $this->mRedirect ) ) {
                        return $this->mRedirect;
                }
-               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
                        $this->mRedirect = false;
                        return $this->mRedirect;
                }
 
                $linkCache = LinkCache::singleton();
+               $linkCache->addLinkObj( $this ); # in case we already had an article ID
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' );
                if ( $cached === null ) {
                        # Trust LinkCache's state over our own
@@ -3220,12 +3220,12 @@ class Title {
                if ( $this->mLength != -1 ) {
                        return $this->mLength;
                }
-               # Calling getArticleID() loads the field from cache as needed
                if ( !$this->getArticleID( $flags ) ) {
                        $this->mLength = 0;
                        return $this->mLength;
                }
                $linkCache = LinkCache::singleton();
+               $linkCache->addLinkObj( $this ); # in case we already had an article ID
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'length' );
                if ( $cached === null ) {
                        # Trust LinkCache's state over our own, as for isRedirect()
@@ -3248,13 +3248,12 @@ 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 ) ) {
                        $this->mLatestID = 0;
                        return $this->mLatestID;
                }
                $linkCache = LinkCache::singleton();
-               $linkCache->addLinkObj( $this );
+               $linkCache->addLinkObj( $this ); # in case we already had an article ID
                $cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' );
                if ( $cached === null ) {
                        # Trust LinkCache's state over our own, as for isRedirect()
@@ -3608,7 +3607,7 @@ class Title {
         *
         * @deprecated since 1.25, use MovePage's methods instead
         * @param Title $nt The new title
-        * @param bool $auth Ignored
+        * @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
         */
@@ -3622,10 +3621,13 @@ class Title {
                }
 
                $mp = new MovePage( $this, $nt );
-               $errors = wfMergeErrorArrays(
-                       $mp->isValidMove()->getErrorsArray(),
-                       $mp->checkPermissions( $wgUser, $reason )->getErrorsArray()
-               );
+               $errors = $mp->isValidMove()->getErrorsArray();
+               if ( $auth ) {
+                       $errors = wfMergeErrorArrays(
+                               $errors,
+                               $mp->checkPermissions( $wgUser, $reason )->getErrorsArray()
+                       );
+               }
 
                return $errors ? : true;
        }
@@ -4098,12 +4100,11 @@ class Title {
                        'rev_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( $new->getTimestamp() ) )
                );
                if ( $max !== null ) {
-                       $res = $dbr->select( 'revision', '1',
+                       return $dbr->selectRowCount( 'revision', '1',
                                $conds,
                                __METHOD__,
                                array( 'LIMIT' => $max + 1 ) // extra to detect truncation
                        );
-                       return $res->numRows();
                } else {
                        return (int)$dbr->selectField( 'revision', 'count(*)', $conds, __METHOD__ );
                }
@@ -4154,17 +4155,19 @@ class Title {
                }
                // No DB query needed if $old and $new are the same or successive revisions:
                if ( $old->getId() === $new->getId() ) {
-                       return ( $old_cmp === '>' && $new_cmp === '<' ) ? array() : array( $old->getRawUserText() );
+                       return ( $old_cmp === '>' && $new_cmp === '<' ) ?
+                               array() :
+                               array( $old->getUserText( Revision::RAW ) );
                } elseif ( $old->getId() === $new->getParentId() ) {
                        if ( $old_cmp === '>=' && $new_cmp === '<=' ) {
-                               $authors[] = $old->getRawUserText();
-                               if ( $old->getRawUserText() != $new->getRawUserText() ) {
-                                       $authors[] = $new->getRawUserText();
+                               $authors[] = $old->getUserText( Revision::RAW );
+                               if ( $old->getUserText( Revision::RAW ) != $new->getUserText( Revision::RAW ) ) {
+                                       $authors[] = $new->getUserText( Revision::RAW );
                                }
                        } elseif ( $old_cmp === '>=' ) {
-                               $authors[] = $old->getRawUserText();
+                               $authors[] = $old->getUserText( Revision::RAW );
                        } elseif ( $new_cmp === '<=' ) {
-                               $authors[] = $new->getRawUserText();
+                               $authors[] = $new->getUserText( Revision::RAW );
                        }
                        return $authors;
                }
@@ -4690,7 +4693,9 @@ class Title {
                $editnotice_ns = 'editnotice-' . $this->getNamespace();
                $editnotice_ns_message = wfMessage( $editnotice_ns );
                if ( $editnotice_ns_message->exists() ) {
-                       $notices[$editnotice_ns] = $editnotice_ns_message->parseAsBlock();
+                       $notices[$editnotice_ns] = '<div class="mw-editnotice mw-editnotice-namespace ' .
+                               Sanitizer::escapeClass( "mw-$editnotice_ns" ) . '">' .
+                               $editnotice_ns_message->parseAsBlock() . '</div>';
                }
                if ( MWNamespace::hasSubpages( $this->getNamespace() ) ) {
                        $parts = explode( '/', $this->getDBkey() );
@@ -4699,7 +4704,9 @@ class Title {
                                $editnotice_base .= '-' . array_shift( $parts );
                                $editnotice_base_msg = wfMessage( $editnotice_base );
                                if ( $editnotice_base_msg->exists() ) {
-                                       $notices[$editnotice_base] = $editnotice_base_msg->parseAsBlock();
+                                       $notices[$editnotice_base] = '<div class="mw-editnotice mw-editnotice-base ' .
+                                               Sanitizer::escapeClass( "mw-$editnotice_base" ) . '">' .
+                                               $editnotice_base_msg->parseAsBlock() . '</div>';
                                }
                        }
                } else {
@@ -4707,7 +4714,9 @@ class Title {
                        $editnoticeText = $editnotice_ns . '-' . str_replace( '/', '-', $this->getDBkey() );
                        $editnoticeMsg = wfMessage( $editnoticeText );
                        if ( $editnoticeMsg->exists() ) {
-                               $notices[$editnoticeText] = $editnoticeMsg->parseAsBlock();
+                               $notices[$editnoticeText] = '<div class="mw-editnotice mw-editnotice-page ' .
+                                       Sanitizer::escapeClass( "mw-$editnoticeText" ) . '">' .
+                                       $editnoticeMsg->parseAsBlock() . '</div>';
                        }
                }