Return early when page id is less than 1
authorChad Horohoe <chadh@wikimedia.org>
Tue, 11 Feb 2014 05:52:01 +0000 (21:52 -0800)
committerChad Horohoe <chadh@wikimedia.org>
Tue, 11 Feb 2014 05:52:01 +0000 (21:52 -0800)
Wasteful DB query when we know the page won't exist.

Bug: 61166
Change-Id: I8943b4dec5088dadffefbd74f54653cb09043b7c

includes/WikiPage.php

index a191983..ee6f574 100644 (file)
@@ -142,6 +142,11 @@ class WikiPage implements Page, IDBAccessObject {
         * @return WikiPage|null
         */
        public static function newFromID( $id, $from = 'fromdb' ) {
+               // page id's are never 0 or negative, see bug 61166
+               if ( $id < 1 ) {
+                       return;
+               }
+
                $from = self::convertSelectType( $from );
                $db = wfGetDB( $from === self::READ_LATEST ? DB_MASTER : DB_SLAVE );
                $row = $db->selectRow( 'page', self::selectFields(), array( 'page_id' => $id ), __METHOD__ );