Add `actor` table and code to start using it
[lhc/web/wiklou.git] / includes / actions / InfoAction.php
index 62f7ddf..0988f73 100644 (file)
@@ -186,7 +186,7 @@ class InfoAction extends FormlessAction {
         * Adds a table to the content that will be added to the output.
         *
         * @param string $content The content that will be added to the output
-        * @param string $table The table
+        * @param string $table
         * @return string The content with the table added
         */
        protected function addTable( $content, $table ) {
@@ -437,6 +437,19 @@ class InfoAction extends FormlessAction {
                        ];
                }
 
+               // Display image SHA-1 value
+               if ( $title->inNamespace( NS_FILE ) ) {
+                       $fileObj = wfFindFile( $title );
+                       if ( $fileObj !== false ) {
+                               // Convert the base-36 sha1 value obtained from database to base-16
+                               $output = Wikimedia\base_convert( $fileObj->getSha1(), 36, 16, 40 );
+                               $pageInfo['header-basic'][] = [
+                                       $this->msg( 'pageinfo-file-hash' ),
+                                       $output
+                               ];
+                       }
+               }
+
                // Page protection
                $pageInfo['header-restrictions'] = [];
 
@@ -705,6 +718,8 @@ class InfoAction extends FormlessAction {
                        self::getCacheKey( $cache, $page->getTitle(), $page->getLatest() ),
                        WANObjectCache::TTL_WEEK,
                        function ( $oldValue, &$ttl, &$setOpts ) use ( $page, $config, $fname ) {
+                               global $wgActorTableSchemaMigrationStage;
+
                                $title = $page->getTitle();
                                $id = $title->getArticleID();
 
@@ -712,6 +727,29 @@ class InfoAction extends FormlessAction {
                                $dbrWatchlist = wfGetDB( DB_REPLICA, 'watchlist' );
                                $setOpts += Database::getCacheSetOptions( $dbr, $dbrWatchlist );
 
+                               if ( $wgActorTableSchemaMigrationStage === MIGRATION_NEW ) {
+                                       $tables = [ 'revision_actor_temp' ];
+                                       $field = 'revactor_actor';
+                                       $pageField = 'revactor_page';
+                                       $tsField = 'revactor_timestamp';
+                                       $joins = [];
+                               } elseif ( $wgActorTableSchemaMigrationStage === MIGRATION_OLD ) {
+                                       $tables = [ 'revision' ];
+                                       $field = 'rev_user_text';
+                                       $pageField = 'rev_page';
+                                       $tsField = 'rev_timestamp';
+                                       $joins = [];
+                               } else {
+                                       $tables = [ 'revision', 'revision_actor_temp', 'actor' ];
+                                       $field = 'COALESCE( actor_name, rev_user_text)';
+                                       $pageField = 'rev_page';
+                                       $tsField = 'rev_timestamp';
+                                       $joins = [
+                                               'revision_actor_temp' => [ 'LEFT JOIN', 'revactor_rev = rev_id' ],
+                                               'actor' => [ 'LEFT JOIN', 'revactor_actor = actor_id' ],
+                                       ];
+                               }
+
                                $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
 
                                $result = [];
@@ -739,10 +777,12 @@ class InfoAction extends FormlessAction {
                                        $result['authors'] = 0;
                                } else {
                                        $result['authors'] = (int)$dbr->selectField(
-                                               'revision',
-                                               'COUNT(DISTINCT rev_user_text)',
-                                               [ 'rev_page' => $id ],
-                                               $fname
+                                               $tables,
+                                               "COUNT(DISTINCT $field)",
+                                               [ $pageField => $id ],
+                                               $fname,
+                                               [],
+                                               $joins
                                        );
                                }
 
@@ -763,13 +803,15 @@ class InfoAction extends FormlessAction {
 
                                // Recent number of distinct authors
                                $result['recent_authors'] = (int)$dbr->selectField(
-                                       'revision',
-                                       'COUNT(DISTINCT rev_user_text)',
+                                       $tables,
+                                       "COUNT(DISTINCT $field)",
                                        [
-                                               'rev_page' => $id,
-                                               "rev_timestamp >= " . $dbr->addQuotes( $threshold )
+                                               $pageField => $id,
+                                               "$tsField >= " . $dbr->addQuotes( $threshold )
                                        ],
-                                       $fname
+                                       $fname,
+                                       [],
+                                       $joins
                                );
 
                                // Subpages (if enabled)