Merge "resourceloader: Move mw.user skeleton from startup to base"
[lhc/web/wiklou.git] / includes / specialpage / QueryPage.php
index eb179bf..6cc6e4e 100644 (file)
@@ -21,6 +21,7 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\Linker\LinkTarget;
 use MediaWiki\MediaWikiServices;
 use Wikimedia\Rdbms\IResultWrapper;
 use Wikimedia\Rdbms\IDatabase;
@@ -312,7 +313,7 @@ abstract class QueryPage extends SpecialPage {
                                $num = $res->numRows();
                                # Fetch results
                                $vals = [];
-                               foreach ( $res as $row ) {
+                               foreach ( $res as $i => $row ) {
                                        if ( isset( $row->value ) ) {
                                                if ( $this->usesTimestamps() ) {
                                                        $value = wfTimestamp( TS_UNIX,
@@ -321,7 +322,7 @@ abstract class QueryPage extends SpecialPage {
                                                        $value = intval( $row->value ); // T16414
                                                }
                                        } else {
-                                               $value = 0;
+                                               $value = $i;
                                        }
 
                                        $vals[] = [
@@ -375,6 +376,23 @@ abstract class QueryPage extends SpecialPage {
                return wfGetDB( DB_REPLICA, [ $this->getName(), 'QueryPage::recache', 'vslow' ] );
        }
 
+       /**
+        * Remove a cached result.
+        * Useful for interactive backlogs where the user can fix problems in-place.
+        * @param LinkTarget $title The page to remove.
+        * @since 1.34
+        */
+       public function delete( LinkTarget $title ) {
+               if ( $this->isCached() ) {
+                       $dbw = wfGetDB( DB_MASTER );
+                       $dbw->delete( 'querycache', [
+                               'qc_type' => $this->getName(),
+                               'qc_namespace' => $title->getNamespace(),
+                               'qc_title' => $title->getDBkey(),
+                       ], __METHOD__ );
+               }
+       }
+
        /**
         * Run the query and return the result
         * @param int|bool $limit Numerical limit or false for no limit