示例#1
0
 /**
  * Get the robot policy to be used for the current view
  * @param $action String the action= GET parameter
  * @return Array the policy that should be set
  * TODO: actions other than 'view'
  */
 public function getRobotPolicy($action)
 {
     global $wgOut, $wgArticleRobotPolicies, $wgNamespaceRobotPolicies;
     global $wgDefaultRobotPolicy, $wgRequest;
     $ns = $this->getTitle()->getNamespace();
     if ($ns == NS_USER || $ns == NS_USER_TALK) {
         # Don't index user and user talk pages for blocked users (bug 11443)
         if (!$this->getTitle()->isSubpage()) {
             if (Block::newFromTarget(null, $this->getTitle()->getText()) instanceof Block) {
                 return array('index' => 'noindex', 'follow' => 'nofollow');
             }
         }
     }
     if ($this->mPage->getID() === 0 || $this->getOldID()) {
         # Non-articles (special pages etc), and old revisions
         return array('index' => 'noindex', 'follow' => 'nofollow');
     } elseif ($wgOut->isPrintable()) {
         # Discourage indexing of printable versions, but encourage following
         return array('index' => 'noindex', 'follow' => 'follow');
     } elseif ($wgRequest->getInt('curid')) {
         # For ?curid=x urls, disallow indexing
         return array('index' => 'noindex', 'follow' => 'follow');
     }
     # Otherwise, construct the policy based on the various config variables.
     $policy = self::formatRobotPolicy($wgDefaultRobotPolicy);
     if (isset($wgNamespaceRobotPolicies[$ns])) {
         # Honour customised robot policies for this namespace
         $policy = array_merge($policy, self::formatRobotPolicy($wgNamespaceRobotPolicies[$ns]));
     }
     if ($this->getTitle()->canUseNoindex() && is_object($this->mParserOutput) && $this->mParserOutput->getIndexPolicy()) {
         # __INDEX__ and __NOINDEX__ magic words, if allowed. Incorporates
         # a final sanity check that we have really got the parser output.
         $policy = array_merge($policy, array('index' => $this->mParserOutput->getIndexPolicy()));
     }
     if (isset($wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()])) {
         # (bug 14900) site config can override user-defined __INDEX__ or __NOINDEX__
         $policy = array_merge($policy, self::formatRobotPolicy($wgArticleRobotPolicies[$this->getTitle()->getPrefixedText()]));
     }
     return $policy;
 }