jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/403416 )

Change subject: Implement robot-policy
......................................................................


Implement robot-policy

* Actions other than 'view' have 'noindex,nofollow'

* Hidden topics have 'noindex,nofollow'

* View board and view (visible) topic use the
  Article getRobotPolicy algorithm using the board
  title. It respects $wgArticleRobotPolicies,
  $wgNamespaceRobotPolicies and $wgDefaultRobotPolicy.

* Magic words are not currently supported.

Bug: T122119
Bug: T184185
Change-Id: Idefb5ee59e809a0e11edc1948295405ac57fea42
---
M includes/View.php
1 file changed, 33 insertions(+), 2 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/View.php b/includes/View.php
index dbb547e..f1284e8 100644
--- a/includes/View.php
+++ b/includes/View.php
@@ -2,8 +2,10 @@
 
 namespace Flow;
 
+use Article;
 use ContextSource;
 use Flow\Block\AbstractBlock;
+use Flow\Block\TopicBlock;
 use Flow\Exception\InvalidActionException;
 use Flow\Model\Anchor;
 use Flow\Model\HtmlRenderingInformation;
@@ -75,7 +77,33 @@
                        $block->setPageTitle( $output );
                }
 
-               $this->renderApiResponse( $apiResponse );
+               $robotPolicy = $this->getRobotPolicy( $action, 
$loader->getWorkflow(), $blocks );
+               $this->renderApiResponse( $apiResponse, $robotPolicy );
+       }
+
+       private function getRobotPolicy( $action, $workflow, $blocks ) {
+               if ( $action !== 'view' ) {
+                       // consistent with 'edit' and other action pages in Core
+                       return [
+                               'index' => 'noindex',
+                               'follow' => 'nofollow',
+                       ];
+               }
+
+               if ( $workflow->getType() === 'topic' ) {
+                       /** @var TopicBlock $topic */
+                       $topic = $blocks[ 'topic' ];
+                       if ( $topic->loadTopicTitle()->isHidden() ) {
+                               return [
+                                       'index' => 'noindex',
+                                       'follow' => 'nofollow',
+                               ];
+                       }
+               }
+
+               $boardTitle = $workflow->getOwnerTitle();
+               $article = Article::newFromTitle( $boardTitle, 
$this->getContext() );
+               return $article->getRobotPolicy( /* unused $action parameter */ 
null );
        }
 
        protected function addModules( OutputPage $out, $action ) {
@@ -241,7 +269,7 @@
                return $apiResponse;
        }
 
-       protected function renderApiResponse( array $apiResponse ) {
+       protected function renderApiResponse( array $apiResponse, array 
$robotPolicy ) {
                // Render the flow-component wrapper
                if ( empty( $apiResponse['blocks'] ) ) {
                        return [];
@@ -325,6 +353,9 @@
                                ],
                                $template( $apiResponse )
                        ) );
+
+                       $out->setIndexPolicy( $robotPolicy[ 'index' ] );
+                       $out->setFollowPolicy( $robotPolicy[ 'follow' ] );
                }
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/403416
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Idefb5ee59e809a0e11edc1948295405ac57fea42
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Sbisson <sbis...@wikimedia.org>
Gerrit-Reviewer: Catrope <r...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to