| Index: trunk/phase3/includes/Revision.php |
| — | — | @@ -23,9 +23,7 @@ |
| 24 | 24 | * @return Revision or null |
| 25 | 25 | */ |
| 26 | 26 | public static function newFromId( $id ) { |
| 27 | | - return Revision::newFromConds( |
| 28 | | - array( 'page_id=rev_page', |
| 29 | | - 'rev_id' => intval( $id ) ) ); |
| | 27 | + return Revision::newFromConds( array( 'rev_id' => intval( $id ) ) ); |
| 30 | 28 | } |
| 31 | 29 | |
| 32 | 30 | /** |
| — | — | @@ -57,7 +55,6 @@ |
| 58 | 56 | // Use a join to get the latest revision |
| 59 | 57 | $conds[] = 'rev_id=page_latest'; |
| 60 | 58 | } |
| 61 | | - $conds[] = 'page_id=rev_page'; |
| 62 | 59 | return Revision::newFromConds( $conds ); |
| 63 | 60 | } |
| 64 | 61 | |
| — | — | @@ -85,7 +82,6 @@ |
| 86 | 83 | } else { |
| 87 | 84 | $conds[] = 'rev_id = page_latest'; |
| 88 | 85 | } |
| 89 | | - $conds[] = 'page_id=rev_page'; |
| 90 | 86 | return Revision::newFromConds( $conds ); |
| 91 | 87 | } |
| 92 | 88 | |
| — | — | @@ -141,9 +137,7 @@ |
| 142 | 138 | * @return Revision or null |
| 143 | 139 | */ |
| 144 | 140 | public static function loadFromId( $db, $id ) { |
| 145 | | - return Revision::loadFromConds( $db, |
| 146 | | - array( 'page_id=rev_page', |
| 147 | | - 'rev_id' => intval( $id ) ) ); |
| | 141 | + return Revision::loadFromConds( $db, array( 'rev_id' => intval( $id ) ) ); |
| 148 | 142 | } |
| 149 | 143 | |
| 150 | 144 | /** |
| — | — | @@ -157,7 +151,7 @@ |
| 158 | 152 | * @return Revision or null |
| 159 | 153 | */ |
| 160 | 154 | public static function loadFromPageId( $db, $pageid, $id = 0 ) { |
| 161 | | - $conds = array( 'page_id=rev_page','rev_page' => intval( $pageid ), 'page_id'=>intval( $pageid ) ); |
| | 155 | + $conds = array( 'rev_page' => intval( $pageid ), 'page_id' => intval( $pageid ) ); |
| 162 | 156 | if( $id ) { |
| 163 | 157 | $conds['rev_id'] = intval( $id ); |
| 164 | 158 | } else { |
| — | — | @@ -182,12 +176,11 @@ |
| 183 | 177 | } else { |
| 184 | 178 | $matchId = 'page_latest'; |
| 185 | 179 | } |
| 186 | | - return Revision::loadFromConds( |
| 187 | | - $db, |
| | 180 | + return Revision::loadFromConds( $db, |
| 188 | 181 | array( "rev_id=$matchId", |
| 189 | | - 'page_id=rev_page', |
| 190 | 182 | 'page_namespace' => $title->getNamespace(), |
| 191 | | - 'page_title' => $title->getDBkey() ) ); |
| | 183 | + 'page_title' => $title->getDBkey() ) |
| | 184 | + ); |
| 192 | 185 | } |
| 193 | 186 | |
| 194 | 187 | /** |
| — | — | @@ -201,12 +194,11 @@ |
| 202 | 195 | * @return Revision or null |
| 203 | 196 | */ |
| 204 | 197 | public static function loadFromTimestamp( $db, $title, $timestamp ) { |
| 205 | | - return Revision::loadFromConds( |
| 206 | | - $db, |
| | 198 | + return Revision::loadFromConds( $db, |
| 207 | 199 | array( 'rev_timestamp' => $db->timestamp( $timestamp ), |
| 208 | | - 'page_id=rev_page', |
| 209 | 200 | 'page_namespace' => $title->getNamespace(), |
| 210 | | - 'page_title' => $title->getDBkey() ) ); |
| | 201 | + 'page_title' => $title->getDBkey() ) |
| | 202 | + ); |
| 211 | 203 | } |
| 212 | 204 | |
| 213 | 205 | /** |
| — | — | @@ -217,12 +209,12 @@ |
| 218 | 210 | */ |
| 219 | 211 | public static function newFromConds( $conditions ) { |
| 220 | 212 | $db = wfGetDB( DB_SLAVE ); |
| 221 | | - $row = Revision::loadFromConds( $db, $conditions ); |
| 222 | | - if( is_null( $row ) && wfGetLB()->getServerCount() > 1 ) { |
| | 213 | + $rev = Revision::loadFromConds( $db, $conditions ); |
| | 214 | + if( is_null( $rev ) && wfGetLB()->getServerCount() > 1 ) { |
| 223 | 215 | $dbw = wfGetDB( DB_MASTER ); |
| 224 | | - $row = Revision::loadFromConds( $dbw, $conditions ); |
| | 216 | + $rev = Revision::loadFromConds( $dbw, $conditions ); |
| 225 | 217 | } |
| 226 | | - return $row; |
| | 218 | + return $rev; |
| 227 | 219 | } |
| 228 | 220 | |
| 229 | 221 | /** |
| — | — | @@ -237,7 +229,6 @@ |
| 238 | 230 | $res = Revision::fetchFromConds( $db, $conditions ); |
| 239 | 231 | if( $res ) { |
| 240 | 232 | $row = $res->fetchObject(); |
| 241 | | - $res->free(); |
| 242 | 233 | if( $row ) { |
| 243 | 234 | $ret = new Revision( $row ); |
| 244 | 235 | return $ret; |
| — | — | @@ -260,8 +251,8 @@ |
| 261 | 252 | wfGetDB( DB_SLAVE ), |
| 262 | 253 | array( 'rev_id=page_latest', |
| 263 | 254 | 'page_namespace' => $title->getNamespace(), |
| 264 | | - 'page_title' => $title->getDBkey(), |
| 265 | | - 'page_id=rev_page' ) ); |
| | 255 | + 'page_title' => $title->getDBkey() ) |
| | 256 | + ); |
| 266 | 257 | } |
| 267 | 258 | |
| 268 | 259 | /** |
| — | — | @@ -274,16 +265,20 @@ |
| 275 | 266 | * @return ResultWrapper |
| 276 | 267 | */ |
| 277 | 268 | private static function fetchFromConds( $db, $conditions ) { |
| 278 | | - $fields = self::selectFields(); |
| 279 | | - $fields[] = 'page_namespace'; |
| 280 | | - $fields[] = 'page_title'; |
| 281 | | - $fields[] = 'page_latest'; |
| | 269 | + $fields = array_merge( |
| | 270 | + self::selectFields(), |
| | 271 | + self::selectPageFields(), |
| | 272 | + self::selectUserFields() |
| | 273 | + ); |
| 282 | 274 | return $db->select( |
| 283 | | - array( 'page', 'revision' ), |
| | 275 | + array( 'revision', 'page', 'user' ), |
| 284 | 276 | $fields, |
| 285 | 277 | $conditions, |
| 286 | 278 | __METHOD__, |
| 287 | | - array( 'LIMIT' => 1 ) ); |
| | 279 | + array( 'LIMIT' => 1 ), |
| | 280 | + array( 'page' => array( 'INNER JOIN', 'page_id = rev_page' ), |
| | 281 | + 'user' => array( 'LEFT JOIN', 'user_id = rev_user' ) ) |
| | 282 | + ); |
| 288 | 283 | } |
| 289 | 284 | |
| 290 | 285 | /** |
| — | — | @@ -329,6 +324,13 @@ |
| 330 | 325 | } |
| 331 | 326 | |
| 332 | 327 | /** |
| | 328 | + * Return the list of user fields that should be selected from user table |
| | 329 | + */ |
| | 330 | + static function selectUserFields() { |
| | 331 | + return array( 'COALESCE(user_name,rev_user_text) AS rev_user_name' ); |
| | 332 | + } |
| | 333 | + |
| | 334 | + /** |
| 333 | 335 | * Constructor |
| 334 | 336 | * |
| 335 | 337 | * @param $row Mixed: either a database row or an array |
| — | — | @@ -340,7 +342,6 @@ |
| 341 | 343 | $this->mPage = intval( $row->rev_page ); |
| 342 | 344 | $this->mTextId = intval( $row->rev_text_id ); |
| 343 | 345 | $this->mComment = $row->rev_comment; |
| 344 | | - $this->mUserText = $row->rev_user_text; |
| 345 | 346 | $this->mUser = intval( $row->rev_user ); |
| 346 | 347 | $this->mMinorEdit = intval( $row->rev_minor_edit ); |
| 347 | 348 | $this->mTimestamp = $row->rev_timestamp; |
| — | — | @@ -374,6 +375,12 @@ |
| 375 | 376 | // 'text' table row entry will be lazy-loaded |
| 376 | 377 | $this->mTextRow = null; |
| 377 | 378 | } |
| | 379 | + |
| | 380 | + if ( isset( $row->rev_user_name ) ) { |
| | 381 | + $this->mUserText = $row->rev_user_name; // current user name |
| | 382 | + } else { // fallback to rev_user_text |
| | 383 | + $this->mUserText = $row->rev_user_text; // de-normalized |
| | 384 | + } |
| 378 | 385 | } elseif( is_array( $row ) ) { |
| 379 | 386 | // Build a new revision to be saved... |
| 380 | 387 | global $wgUser; |