Merge "Decolonize 'viewsourcetext' and 'viewyourtext' messages"
[lhc/web/wiklou.git] / includes / cache / BacklinkCache.php
index c3aefc5..10b4fb0 100644 (file)
@@ -38,8 +38,6 @@
  * of memory.
  *
  * Introduced by r47317
- *
- * @internal documentation reviewed on 18 Mar 2011 by hashar
  */
 class BacklinkCache {
        /** @var ProcessCacheLRU */
@@ -495,13 +493,11 @@ class BacklinkCache {
         * @since 1.25
         */
        public function getCascadeProtectedLinks() {
-               // This method is used to make redudant jobs anyway, so its OK to use
-               // a slave. Also, the set of cascade protected pages tends to be stable.
                $dbr = $this->getDB();
 
-               $queries = array();
-               // @note: UNION filters any duplicate pages
-               $queries[] = $dbr->selectSQLText(
+               // @todo: use UNION without breaking tests that use temp tables
+               $resSets = array();
+               $resSets[] = $dbr->select(
                        array( 'templatelinks', 'page_restrictions', 'page' ),
                        array( 'page_namespace', 'page_title', 'page_id' ),
                        array(
@@ -510,22 +506,34 @@ class BacklinkCache {
                                'tl_from = pr_page',
                                'pr_cascade' => 1,
                                'page_id = tl_from'
-                       )
-               );
-               $queries[] = $dbr->selectSQLText(
-                       array( 'imagelinks', 'page_restrictions', 'page' ),
-                       array( 'page_namespace', 'page_title', 'page_id' ),
-                       array(
-                               'il_to' => $this->title->getDBkey(),
-                               'il_from = pr_page',
-                               'pr_cascade' => 1,
-                               'page_id = il_from'
-                       )
+                       ),
+                       __METHOD__,
+                       array( 'DISTINCT' )
                );
+               if ( $this->title->getNamespace() == NS_FILE ) {
+                       $resSets[] = $dbr->select(
+                               array( 'imagelinks', 'page_restrictions', 'page' ),
+                               array( 'page_namespace', 'page_title', 'page_id' ),
+                               array(
+                                       'il_to' => $this->title->getDBkey(),
+                                       'il_from = pr_page',
+                                       'pr_cascade' => 1,
+                                       'page_id = il_from'
+                               ),
+                               __METHOD__,
+                               array( 'DISTINCT' )
+                       );
+               }
+
+               // Combine and de-duplicate the results
+               $mergedRes = array();
+               foreach ( $resSets as $res ) {
+                       foreach ( $res as $row ) {
+                               $mergedRes[$row->page_id] = $row;
+                       }
+               }
 
-               return TitleArray::newFromResult( $dbr->query(
-                       $dbr->unionQueries( $queries, false ),
-                       __METHOD__
-               ) );
+               return TitleArray::newFromResult(
+                       new FakeResultWrapper( array_values( $mergedRes ) ) );
        }
 }