Avoid using raw sql in SpecialUndelete.php
authorumherirrender <umherirrender_de.wp@web.de>
Tue, 8 Apr 2014 18:18:11 +0000 (20:18 +0200)
committerUmherirrender <umherirrender_de.wp@web.de>
Sat, 31 May 2014 07:07:24 +0000 (07:07 +0000)
The where part for the ar_timestamp was raw sql.
Refactored to avoid this. Now the IN-List is created by the database
abstraction layer. The addQuotes and implode with comma is done there.
Just the call to Database::timestamp is still needed.

This also avoids a '1 = 1' in sql.

Change-Id: I1deb055a1437ae84fc8a4e8cf2976e18c15bda39

includes/specials/SpecialUndelete.php

index 51235ee..04b36c7 100644 (file)
@@ -492,15 +492,12 @@ class PageArchive {
                        $previousTimestamp = 0;
                }
 
-               if ( $restoreAll ) {
-                       $oldones = '1 = 1'; # All revisions...
-               } else {
-                       $oldts = implode( ',',
-                               array_map( array( &$dbw, 'addQuotes' ),
-                                       array_map( array( &$dbw, 'timestamp' ),
-                                               $timestamps ) ) );
-
-                       $oldones = "ar_timestamp IN ( {$oldts} )";
+               $oldWhere = array(
+                       'ar_namespace' => $this->title->getNamespace(),
+                       'ar_title' => $this->title->getDBkey(),
+               );
+               if ( !$restoreAll ) {
+                       $oldWhere['ar_timestamp'] = array_map( array( &$dbw, 'timestamp' ), $timestamps );
                }
 
                $fields = array(
@@ -529,10 +526,7 @@ class PageArchive {
                 */
                $result = $dbw->select( 'archive',
                        $fields,
-                       /* WHERE */ array(
-                               'ar_namespace' => $this->title->getNamespace(),
-                               'ar_title' => $this->title->getDBkey(),
-                               $oldones ),
+                       $oldWhere,
                        __METHOD__,
                        /* options */ array( 'ORDER BY' => 'ar_timestamp' )
                );
@@ -618,10 +612,7 @@ class PageArchive {
                }
                # Now that it's safely stored, take it out of the archive
                $dbw->delete( 'archive',
-                       /* WHERE */ array(
-                               'ar_namespace' => $this->title->getNamespace(),
-                               'ar_title' => $this->title->getDBkey(),
-                               $oldones ),
+                       $oldWhere,
                        __METHOD__ );
 
                // Was anything restored at all?