Add QueryPage::delete method
authorGergő Tisza <tgr.huwiki@gmail.com>
Fri, 26 Jul 2019 14:47:09 +0000 (16:47 +0200)
committerGergő Tisza <tgr.huwiki@gmail.com>
Fri, 26 Jul 2019 21:22:30 +0000 (23:22 +0200)
Add a method for delete the cached result for a page. This is
useful for backlog-type query pages which provide some interface
for fixing the problem in-place.

Change-Id: I36b750d71b6551bb5c662e82c24f029db01acd3b

includes/specialpage/QueryPage.php

index eb179bf..1977af0 100644 (file)
@@ -21,6 +21,7 @@
  * @ingroup SpecialPage
  */
 
+use MediaWiki\Linker\LinkTarget;
 use MediaWiki\MediaWikiServices;
 use Wikimedia\Rdbms\IResultWrapper;
 use Wikimedia\Rdbms\IDatabase;
@@ -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