コード例 #1
0
 /**
  * Starts the log for an evaluation. The log string is assembled in self::mLog.
  *
  * @param Title $title
  * @param User $user
  * @param string $action
  */
 static function startLog($title, $user, $action)
 {
     global $wgRequest, $haclgEvaluatorLog, $haclgCombineMode;
     self::$mLogEnabled = $haclgEvaluatorLog && $wgRequest->getVal('hacllog', 'false') == 'true';
     if (!self::$mLogEnabled) {
         // Logging is disabled
         return;
     }
     self::$mLog = "";
     self::$mLog .= "IntraACL Evaluation Log\n";
     self::$mLog .= "======================\n\n";
     self::$mLog .= "Title: " . (is_null($title) ? "null" : $title->getFullText()) . "\n";
     self::$mLog .= "User: "******"\n";
     self::$mLog .= "Action: {$action}; mode: {$haclgCombineMode}\n";
 }
コード例 #2
0
 /**
  * Run a single test - assert $user can/cannot do $action on (depending on $can)
  * by $user, report status and failure details, if any.
  */
 protected function assertCan($user, $can, $action)
 {
     global $haclgCombineMode, $haclgOpenWikiAccess;
     $info = array_merge(array($haclgOpenWikiAccess ? 'OPEN' : 'CLOSED', $haclgCombineMode), array_keys($this->acls));
     $result = false;
     if (class_exists('IACLEvaluator')) {
         IACLEvaluator::userCan($this->title, $user, $action, $result);
     } else {
         HACLEvaluator::userCan($this->title, $user, $action, $result);
     }
     $ok = $can == $result;
     if ($ok) {
         $str = "[OK] ";
         $this->numOk++;
     } else {
         $str = "[FAILED] ";
         $this->numFailed++;
     }
     $str = $this->pfx . sprintf("%5d ", $this->numFailed + $this->numOk) . $str . '[' . implode(' ', $info) . '] ' . $user->getName() . ($can ? " can " : " cannot ") . $action . ' ' . $this->title . ($ok ? $this->newline : "\n");
     if (!$ok || !$this->onlyFailures) {
         print $str;
     }
     if (!$ok) {
         global $haclgCombineMode, $haclgOpenWikiAccess;
         $art = new WikiPage($this->title);
         print "  Details:\n    Open Wiki Access = " . ($haclgOpenWikiAccess ? 'true' : 'false') . "\n";
         print "    Combine Mode = {$haclgCombineMode}\n";
         print "    Article content = " . trim($art->getText()) . "\n";
         if ($this->acls) {
             print "  Applied ACLs:\n";
             foreach ($this->acls as $key => $info) {
                 print '    ' . $info['title'] . ' ' . trim((new WikiPage($info['title']))->getText()) . "\n";
             }
         } else {
             print "  No applied ACLs\n";
         }
         wfGetDB(DB_MASTER)->commit();
         if ($this->stopOnFailure) {
             exit;
         }
     }
 }