Example #1
0
 /**
  * Check if a tool exist
  *
  * @param string $path path to the tool
  * @return bool
  */
 protected function checkIfToolExists($path)
 {
     wfSuppressWarnings();
     $result = file_exists($path);
     wfRestoreWarnings();
     return $result;
 }
 public function getBackgroundColor($subset, $total, $fuzzy = false)
 {
     wfSuppressWarnings();
     $v = round(255 * $subset / $total);
     wfRestoreWarnings();
     if ($fuzzy) {
         // Weigh fuzzy with factor 20.
         $v = $v * 20;
         if ($v > 255) {
             $v = 255;
         }
         $v = 255 - $v;
     }
     if ($v < 128) {
         // Red to Yellow
         $red = 'FF';
         $green = sprintf('%02X', 2 * $v);
     } else {
         // Yellow to Green
         $red = sprintf('%02X', 2 * (255 - $v));
         $green = 'FF';
     }
     $blue = '00';
     return $red . $green . $blue;
 }
 /**
  * @param $key
  * @return Status
  */
 function get($key)
 {
     $hashes = array();
     foreach ($this->hostNames as $hostName) {
         $hashes[$hostName] = md5($hostName . $key);
     }
     asort($hashes);
     $errno = $errstr = '';
     foreach ($hashes as $hostName => $hash) {
         if (isset($this->conns[$hostName])) {
             $this->refCounts[$hostName]++;
             return Status::newGood($this->conns[$hostName]);
         }
         $parts = explode(':', $hostName, 2);
         if (count($parts) < 2) {
             $parts[] = 7531;
         }
         wfProfileIn(__METHOD__ . '-connect');
         wfSuppressWarnings();
         $conn = fsockopen($parts[0], $parts[1], $errno, $errstr, $this->timeout);
         wfRestoreWarnings();
         wfProfileOut(__METHOD__ . '-connect');
         if ($conn) {
             break;
         }
     }
     if (!$conn) {
         return Status::newFatal('poolcounter-connection-error', $errstr);
     }
     wfDebug("Connected to pool counter server: {$hostName}\n");
     $this->conns[$hostName] = $conn;
     $this->refCounts[$hostName] = 1;
     return Status::newGood($conn);
 }
Example #4
0
 private function useMWlock()
 {
     global $wgReadOnlyFile, $wgContLang;
     wfSuppressWarnings();
     $fp = fopen($wgReadOnlyFile, 'w');
     wfRestoreWarnings();
     // wikia change start
     global $wgUser, $wgCityId;
     $reason = $this->reason . "\nby " . $wgUser->getName() . ' at ' . $wgContLang->timeanddate(wfTimestampNow());
     if (!WikiFactory::setVarByName('wgReadOnly', $wgCityId, $reason) || !WikiFactory::clearCache($wgCityId)) {
         return Status::newFatal('lockdb-wikifactory-error');
     }
     // wikia change end
     if (false === $fp) {
         # This used to show a file not found error, but the likeliest reason for fopen()
         # to fail at this point is insufficient permission to write to the file...good old
         # is_writable() is plain wrong in some cases, it seems...
         return false;
     }
     fwrite($fp, $data['Reason']);
     $timestamp = wfTimestampNow();
     fwrite($fp, "\n<p>" . wfMsgExt('lockedbyandtime', array('content', 'parsemag'), $this->getUser()->getName(), $wgContLang->date($timestamp), $wgContLang->time($timestamp)) . "</p>\n");
     fclose($fp);
     return true;
 }
Example #5
0
 /**
  * Delete files in the deleted directory if they are not referenced in the
  * filearchive table. This needs to be done in the repo because it needs to
  * interleave database locks with file operations, which is potentially a
  * remote operation.
  *
  * @param $storageKeys array
  *
  * @return FileRepoStatus
  */
 function cleanupDeletedBatch($storageKeys)
 {
     $root = $this->getZonePath('deleted');
     $dbw = $this->getMasterDB();
     $status = $this->newGood();
     $storageKeys = array_unique($storageKeys);
     foreach ($storageKeys as $key) {
         $hashPath = $this->getDeletedHashPath($key);
         $path = "{$root}/{$hashPath}{$key}";
         $dbw->begin();
         $inuse = $dbw->selectField('filearchive', '1', array('fa_storage_group' => 'deleted', 'fa_storage_key' => $key), __METHOD__, array('FOR UPDATE'));
         if (!$inuse) {
             $sha1 = self::getHashFromKey($key);
             $ext = substr($key, strcspn($key, '.') + 1);
             $ext = File::normalizeExtension($ext);
             $inuse = $dbw->selectField('oldimage', '1', array('oi_sha1' => $sha1, 'oi_archive_name ' . $dbw->buildLike($dbw->anyString(), ".{$ext}"), $dbw->bitAnd('oi_deleted', File::DELETED_FILE) => File::DELETED_FILE), __METHOD__, array('FOR UPDATE'));
         }
         if (!$inuse) {
             wfDebug(__METHOD__ . ": deleting {$key}\n");
             wfSuppressWarnings();
             $unlink = unlink($path);
             wfRestoreWarnings();
             if (!$unlink) {
                 $status->error('undelete-cleanup-error', $path);
                 $status->failCount++;
             }
         } else {
             wfDebug(__METHOD__ . ": {$key} still in use\n");
             $status->successCount++;
         }
         $dbw->commit();
     }
     return $status;
 }
Example #6
0
 /**
  * Stream a file to the browser, adding all the headings and fun stuff.
  * Headers sent include: Content-type, Content-Length, Last-Modified,
  * and Content-Disposition.
  *
  * @param string $fname Full name and path of the file to stream
  * @param array $headers Any additional headers to send
  * @param bool $sendErrors Send error messages if errors occur (like 404)
  * @throws MWException
  * @return bool Success
  */
 public static function stream($fname, $headers = array(), $sendErrors = true)
 {
     wfProfileIn(__METHOD__);
     if (FileBackend::isStoragePath($fname)) {
         // sanity
         wfProfileOut(__METHOD__);
         throw new MWException(__FUNCTION__ . " given storage path '{$fname}'.");
     }
     wfSuppressWarnings();
     $stat = stat($fname);
     wfRestoreWarnings();
     $res = self::prepareForStream($fname, $stat, $headers, $sendErrors);
     if ($res == self::NOT_MODIFIED) {
         $ok = true;
         // use client cache
     } elseif ($res == self::READY_STREAM) {
         wfProfileIn(__METHOD__ . '-send');
         $ok = readfile($fname);
         wfProfileOut(__METHOD__ . '-send');
     } else {
         $ok = false;
         // failed
     }
     wfProfileOut(__METHOD__);
     return $ok;
 }
 /**
  * Parses given HTML into DOM tree (using XML/HTML parser)
  */
 private function parseToDOM($html, $parseAsXML = true)
 {
     wfProfileIn(__METHOD__);
     $ret = false;
     wfSuppressWarnings();
     if ($parseAsXML) {
         // form proper XML string
         $html = str_replace('&', '&amp;', $html);
         $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><body>{$html}</body>";
         // try to parse as XML
         if ($this->dom->loadXML($xml)) {
             // parsing successful
             $ret = $this->dom->getElementsByTagName('body')->item(0);
         } else {
             $this->handleParseErrors(__METHOD__);
         }
     } else {
         // form proper HTML string
         $html = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body>{$html}</body></html>";
         // try to parse as HTML
         if ($this->dom->loadHTML($html)) {
             $ret = $this->dom->getElementsByTagName('body')->item(0);
         }
     }
     wfRestoreWarnings();
     wfProfileOut(__METHOD__);
     // return <body> node or false if XML parsing failed
     return $ret;
 }
Example #8
0
 private static function dataDirOKmaybeCreate($dir, $create = false)
 {
     if (!is_dir($dir)) {
         if (!is_writable(dirname($dir))) {
             $webserverGroup = Installer::maybeGetWebserverPrimaryGroup();
             if ($webserverGroup !== null) {
                 return Status::newFatal('config-sqlite-parent-unwritable-group', $dir, dirname($dir), basename($dir), $webserverGroup);
             } else {
                 return Status::newFatal('config-sqlite-parent-unwritable-nogroup', $dir, dirname($dir), basename($dir));
             }
         }
         # Called early on in the installer, later we just want to sanity check
         # if it's still writable
         if ($create) {
             wfSuppressWarnings();
             $ok = wfMkdirParents($dir, 0700);
             wfRestoreWarnings();
             if (!$ok) {
                 return Status::newFatal('config-sqlite-mkdir-error', $dir);
             }
             # Put a .htaccess file in in case the user didn't take our advice
             file_put_contents("{$dir}/.htaccess", "Deny from all\n");
         }
     }
     if (!is_writable($dir)) {
         return Status::newFatal('config-sqlite-dir-unwritable', $dir);
     }
     # We haven't blown up yet, fall through
     return Status::newGood();
 }
 /**
  * Constructor
  *
  * Creates an SVGReader drawing from the source provided
  * @param $source String: URI from which to read
  */
 function __construct($source)
 {
     global $wgSVGMetadataCutoff;
     $this->reader = new XMLReader();
     // Don't use $file->getSize() since file object passed to SVGHandler::getMetadata is bogus.
     $size = filesize($source);
     if ($size === false) {
         throw new MWException("Error getting filesize of SVG.");
     }
     if ($size > $wgSVGMetadataCutoff) {
         $this->debug("SVG is {$size} bytes, which is bigger than {$wgSVGMetadataCutoff}. Truncating.");
         $contents = file_get_contents($source, false, null, -1, $wgSVGMetadataCutoff);
         if ($contents === false) {
             throw new MWException('Error reading SVG file.');
         }
         $this->reader->XML($contents, null, LIBXML_NOERROR | LIBXML_NOWARNING);
     } else {
         $this->reader->open($source, null, LIBXML_NOERROR | LIBXML_NOWARNING);
     }
     $this->metadata['width'] = self::DEFAULT_WIDTH;
     $this->metadata['height'] = self::DEFAULT_HEIGHT;
     // Because we cut off the end of the svg making an invalid one. Complicated
     // try catch thing to make sure warnings get restored. Seems like there should
     // be a better way.
     wfSuppressWarnings();
     try {
         $this->read();
     } catch (Exception $e) {
         wfRestoreWarnings();
         throw $e;
     }
     wfRestoreWarnings();
 }
Example #10
0
 function execute()
 {
     global $IP, $wgTitle;
     $siteName = isset($this->mArgs[0]) ? $this->mArgs[0] : "Don't care";
     // Will not be set if used with --env-checks
     $adminName = isset($this->mArgs[1]) ? $this->mArgs[1] : null;
     $wgTitle = Title::newFromText('Installer script');
     $dbpassfile = $this->getOption('dbpassfile', false);
     if ($dbpassfile !== false) {
         wfSuppressWarnings();
         $dbpass = file_get_contents($dbpassfile);
         wfRestoreWarnings();
         if ($dbpass === false) {
             $this->error("Couldn't open {$dbpassfile}", true);
         }
         $this->mOptions['dbpass'] = trim($dbpass, "\r\n");
     }
     $installer = InstallerOverrides::getCliInstaller($siteName, $adminName, $this->mOptions);
     $status = $installer->doEnvironmentChecks();
     if ($status->isGood()) {
         $installer->showMessage('config-env-good');
     } else {
         $installer->showStatusMessage($status);
         return;
     }
     if (!$this->hasOption('env-checks')) {
         $installer->execute();
         $installer->writeConfigurationFile($this->getOption('confpath', $IP));
     }
 }
 public function initialize()
 {
     $dbr = wfGetDB(DB_MASTER);
     $res = $dbr->select('categorylinks', array('cl_to', 'COUNT(*) AS count'), array(), __METHOD__, array('GROUP BY' => 'cl_to', 'ORDER BY' => 'count DESC', 'LIMIT' => $this->limit));
     wfSuppressWarnings();
     // prevent PHP from bitching about strtotime()
     foreach ($res as $row) {
         $tag_name = Title::makeTitle(NS_CATEGORY, $row->cl_to);
         $tag_text = $tag_name->getText();
         if (strtotime($tag_text) == '') {
             // don't want dates to show up
             if ($row->count > $this->tags_highest_count) {
                 $this->tags_highest_count = $row->count;
             }
             $this->tags[$tag_text] = array('count' => $row->count);
         }
     }
     wfRestoreWarnings();
     // sort tag array by key (tag name)
     if ($this->tags_highest_count == 0) {
         return;
     }
     ksort($this->tags);
     /* and what if we have _1_ category? like on a new wiki with nteen articles, mhm? */
     if ($this->tags_highest_count == 1) {
         $coef = $this->tags_max_pts - $this->tags_min_pts;
     } else {
         $coef = ($this->tags_max_pts - $this->tags_min_pts) / (($this->tags_highest_count - 1) * 2);
     }
     foreach ($this->tags as $tag => $att) {
         $this->tags[$tag]['size'] = $this->tags_min_pts + ($this->tags[$tag]['count'] - 1) * $coef;
     }
 }
Example #12
0
	protected function __construct() {
		$idFile = wfTempDir() . '/mw-' . __CLASS__ . '-UID-nodeid';
		$nodeId = is_file( $idFile ) ? file_get_contents( $idFile ) : '';
		// Try to get some ID that uniquely identifies this machine (RFC 4122)...
		if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) {
			wfSuppressWarnings();
			if ( wfIsWindows() ) {
				// http://technet.microsoft.com/en-us/library/bb490913.aspx
				$csv = trim( wfShellExec( 'getmac /NH /FO CSV' ) );
				$line = substr( $csv, 0, strcspn( $csv, "\n" ) );
				$info = str_getcsv( $line );
				$nodeId = isset( $info[0] ) ? str_replace( '-', '', $info[0] ) : '';
			} elseif ( is_executable( '/sbin/ifconfig' ) ) { // Linux/BSD/Solaris/OS X
				// See http://linux.die.net/man/8/ifconfig
				$m = array();
				preg_match( '/\s([0-9a-f]{2}(:[0-9a-f]{2}){5})\s/',
					wfShellExec( '/sbin/ifconfig -a' ), $m );
				$nodeId = isset( $m[1] ) ? str_replace( ':', '', $m[1] ) : '';
			}
			wfRestoreWarnings();
			if ( !preg_match( '/^[0-9a-f]{12}$/i', $nodeId ) ) {
				$nodeId = MWCryptRand::generateHex( 12, true );
				$nodeId[1] = dechex( hexdec( $nodeId[1] ) | 0x1 ); // set multicast bit
			}
			file_put_contents( $idFile, $nodeId ); // cache
		}
		$this->nodeId32 = wfBaseConvert( substr( sha1( $nodeId ), 0, 8 ), 16, 2, 32 );
		$this->nodeId48 = wfBaseConvert( $nodeId, 16, 2, 48 );
		// If different processes run as different users, they may have different temp dirs.
		// This is dealt with by initializing the clock sequence number and counters randomly.
		$this->lockFile88 = wfTempDir() . '/mw-' . __CLASS__ . '-UID-88';
		$this->lockFile128 = wfTempDir() . '/mw-' . __CLASS__ . '-UID-128';
	}
 /**
  * @access private
  * @static
  */
 function sendRPC($method, $params = array())
 {
     global $mwBlockerHost, $mwBlockerPort, $mwBlockerDebug;
     $client = new XML_RPC_Client('/Blocker', $mwBlockerHost, $mwBlockerPort);
     if ($mwBlockerDebug) {
         $client->debug = true;
     }
     $rpcParams = array_map(array('MWBlocker', 'outParam'), $params);
     $message = new XML_RPC_Message($method, $rpcParams);
     wfSuppressWarnings();
     $start = wfTime();
     $result = $client->send($message);
     $delta = wfTime() - $start;
     wfRestoreWarnings();
     $debug = sprintf("MWBlocker::sendRPC for %s took %0.2fms\n", $method, $delta * 1000.0);
     wfDebug($debug);
     if ($mwBlockerDebug) {
         echo $debug;
     }
     if (!is_object($result)) {
         throw new MWException("Unknown XML-RPC error");
     } elseif ($result->faultCode()) {
         throw new MWException($result->faultCode() . ': ' . $result->faultString());
     } else {
         $value = $result->value();
         return $value->getval();
     }
 }
 function extensionCredits()
 {
     global $wgExtensionCredits, $wgExtensionFunctions, $wgSkinExtensionFunction;
     if (!count($wgExtensionCredits) && !count($wgExtensionFunctions) && !count($wgSkinExtensionFunction)) {
         return '';
     }
     $extensionTypes = array('specialpage' => 'Special pages', 'parserhook' => 'Parser hooks', 'other' => 'Other');
     $out = "\n* Extensions:\n";
     foreach ($extensionTypes as $type => $text) {
         if (count(@$wgExtensionCredits[$type])) {
             $out .= "** {$text}:\n";
             foreach ($wgExtensionCredits[$type] as $extension) {
                 wfSuppressWarnings();
                 $out .= $this->formatCredits($extension['name'], $extension['version'], $extension['author'], $extension['url'], $extension['description']);
                 wfRestoreWarnings();
             }
         }
     }
     if (count($wgExtensionFunctions)) {
         $out .= "** Extension functions:\n";
         $out .= '***' . $this->langObj->listToText($wgExtensionFunctions) . "\n";
     }
     if (count($wgSkinExtensionFunction)) {
         $out .= "** Skin extension functions:\n";
         $out .= '***' . $this->langObj->listToText($wgSkinExtensionFunction) . "\n";
     }
     return $out;
 }
Example #15
0
 function getLongDesc($image)
 {
     global $wgLang;
     $original = parent::getLongDesc($image);
     wfSuppressWarnings();
     $metadata = unserialize($image->getMetadata());
     wfRestoreWarnings();
     if (!$metadata || $metadata['frameCount'] <= 0) {
         return $original;
     }
     $info = array();
     $info[] = $original;
     if ($metadata['loopCount'] == 0) {
         $info[] = wfMsgExt('file-info-png-looped', 'parseinline');
     } elseif ($metadata['loopCount'] > 1) {
         $info[] = wfMsgExt('file-info-png-repeat', 'parseinline', $metadata['loopCount']);
     }
     if ($metadata['frameCount'] > 0) {
         $info[] = wfMsgExt('file-info-png-frames', 'parseinline', $metadata['frameCount']);
     }
     if ($metadata['duration']) {
         $info[] = $wgLang->formatTimePeriod($metadata['duration']);
     }
     return $wgLang->commaList($info);
 }
Example #16
0
 public function execute()
 {
     if ($this->hasArg()) {
         $files = $this->mArgs;
     } else {
         $this->maybeHelp(true);
         // @todo fixme this is a lame API :)
         exit(1);
         // it should exit from the above first...
     }
     $parser = new JSParser();
     foreach ($files as $filename) {
         wfSuppressWarnings();
         $js = file_get_contents($filename);
         wfRestoreWarnings();
         if ($js === false) {
             $this->output("{$filename} ERROR: could not read file\n");
             $this->errs++;
             continue;
         }
         try {
             $parser->parse($js, $filename, 1);
         } catch (Exception $e) {
             $this->errs++;
             $this->output("{$filename} ERROR: " . $e->getMessage() . "\n");
             continue;
         }
         $this->output("{$filename} OK\n");
     }
     if ($this->errs > 0) {
         exit(1);
     }
 }
 public function execute()
 {
     global $wgRequest, $wgUser, $wgSitename, $wgSitenameshort, $wgCopyrightLink;
     global $wgCopyright, $wgBootstrap, $wgArticlePath, $wgGoogleAnalyticsID;
     global $wgSiteCSS;
     global $wgEnableUploads;
     global $wgLogo;
     global $wgTOCLocation;
     global $wgNavBarClasses;
     global $wgSubnavBarClasses;
     $this->skin = $this->data['skin'];
     $action = $wgRequest->getText('action');
     $url_prefix = str_replace('$1', '', $wgArticlePath);
     // Suppress warnings to prevent notices about missing indexes in $this->data
     wfSuppressWarnings();
     $this->html('headelement');
     ?>
   <div class="ololo-wiki">
   <?php 
     $this->header($wgUser);
     $this->body();
     $this->footer();
     $this->html('bottomscripts');
     /* JS call to runBodyOnloadHook */
     $this->html('reporttime');
     ?>
   </div>
 <?php 
     echo Html::closeElement('body');
     echo Html::closeElement('html');
     wfRestoreWarnings();
 }
Example #18
0
 /**
  * Establish conncetion
  *
  * @access private
  *
  * @return bool
  */
 function connect()
 {
     wfSuppressWarnings();
     $errno = $errstr = '';
     $this->mFP = fsockopen($this->mHost, $this->mPort, $errno, $errstr, 30);
     wfRestoreWarnings();
     return !$this->mFP;
 }
 function startSessionIfNotStarted()
 {
     \wfSuppressWarnings();
     if (!isset($_SESSION)) {
         session_start();
     }
     \wfRestoreWarnings();
 }
 /**
  * Generates a notification that can be easily interpreted by a machine.
  * @see RCFeedFormatter::getLine
  */
 public function getLine(array $feed, RecentChange $rc, $actionComment)
 {
     global $wgCanonicalServer, $wgServerName, $wgScriptPath;
     $packet = array('id' => $rc->getAttribute('rc_id'), 'type' => RecentChange::parseFromRCType($rc->getAttribute('rc_type')), 'namespace' => $rc->getTitle()->getNamespace(), 'title' => $rc->getTitle()->getPrefixedText(), 'comment' => $rc->getAttribute('rc_comment'), 'timestamp' => (int) wfTimestamp(TS_UNIX, $rc->getAttribute('rc_timestamp')), 'user' => $rc->getAttribute('rc_user_text'), 'bot' => (bool) $rc->getAttribute('rc_bot'));
     if (isset($feed['channel'])) {
         $packet['channel'] = $feed['channel'];
     }
     $type = $rc->getAttribute('rc_type');
     if ($type == RC_EDIT || $type == RC_NEW) {
         global $wgUseRCPatrol, $wgUseNPPatrol;
         $packet['minor'] = (bool) $rc->getAttribute('rc_minor');
         if ($wgUseRCPatrol || $type == RC_NEW && $wgUseNPPatrol) {
             $packet['patrolled'] = (bool) $rc->getAttribute('rc_patrolled');
         }
     }
     switch ($type) {
         case RC_EDIT:
             $packet['length'] = array('old' => $rc->getAttribute('rc_old_len'), 'new' => $rc->getAttribute('rc_new_len'));
             $packet['revision'] = array('old' => $rc->getAttribute('rc_last_oldid'), 'new' => $rc->getAttribute('rc_this_oldid'));
             break;
         case RC_NEW:
             $packet['length'] = array('old' => null, 'new' => $rc->getAttribute('rc_new_len'));
             $packet['revision'] = array('old' => null, 'new' => $rc->getAttribute('rc_this_oldid'));
             break;
         case RC_LOG:
             $packet['log_id'] = $rc->getAttribute('rc_logid');
             $packet['log_type'] = $rc->getAttribute('rc_log_type');
             $packet['log_action'] = $rc->getAttribute('rc_log_action');
             if ($rc->getAttribute('rc_params')) {
                 wfSuppressWarnings();
                 $params = unserialize($rc->getAttribute('rc_params'));
                 wfRestoreWarnings();
                 if ($rc->getAttribute('rc_params') == serialize(false) || $params !== false) {
                     // From ApiQueryLogEvents::addLogParams
                     $logParams = array();
                     // Keys like "4::paramname" can't be used for output so we change them to "paramname"
                     foreach ($params as $key => $value) {
                         if (strpos($key, ':') === false) {
                             $logParams[$key] = $value;
                             continue;
                         }
                         $logParam = explode(':', $key, 3);
                         $logParams[$logParam[2]] = $value;
                     }
                     $packet['log_params'] = $logParams;
                 } else {
                     $packet['log_params'] = explode("\n", $rc->getAttribute('rc_params'));
                 }
             }
             $packet['log_action_comment'] = $actionComment;
             break;
     }
     $packet['server_url'] = $wgCanonicalServer;
     $packet['server_name'] = $wgServerName;
     $packet['server_script_path'] = $wgScriptPath ?: '/';
     $packet['wiki'] = wfWikiID();
     return $this->formatArray($packet);
 }
Example #21
0
 /**
  * Build the list of files we'll check for syntax errors
  */
 private function buildFileList()
 {
     global $IP;
     $this->mIgnorePaths = array("includes/NamespaceCompat.php\$");
     $this->mNoStyleCheckPaths = array("/activemq_stomp/", "EmailPage/PHPMailer", "FCKeditor/fckeditor/", '\\bphplot-', "/svggraph/", "\\bjsmin.php\$", "PEAR/File_Ogg/", "QPoll/Excel/", "/geshi/", "/smarty/");
     if ($this->hasOption('path')) {
         $path = $this->getOption('path');
         if (!$this->addPath($path)) {
             $this->error("Error: can't find file or directory {$path}\n", true);
         }
         return;
         // process only this path
     } elseif ($this->hasOption('list-file')) {
         $file = $this->getOption('list-file');
         wfSuppressWarnings();
         $f = fopen($file, 'r');
         wfRestoreWarnings();
         if (!$f) {
             $this->error("Can't open file {$file}\n", true);
         }
         $path = trim(fgets($f));
         while ($path) {
             $this->addPath($path);
         }
         fclose($f);
         return;
     } elseif ($this->hasOption('modified')) {
         $this->output("Retrieving list from Git... ");
         $files = $this->getGitModifiedFiles($IP);
         $this->output("done\n");
         foreach ($files as $file) {
             if ($this->isSuitableFile($file) && !is_dir($file)) {
                 $this->mFiles[] = $file;
             }
         }
         return;
     }
     $this->output('Building file list...', 'listfiles');
     // Only check files in these directories.
     // Don't just put $IP, because the recursive dir thingie goes into all subdirs
     $dirs = array($IP . '/includes', $IP . '/mw-config', $IP . '/languages', $IP . '/maintenance', $IP . '/skins');
     if ($this->hasOption('with-extensions')) {
         $dirs[] = $IP . '/extensions';
     }
     foreach ($dirs as $d) {
         $this->addDirectoryContent($d);
     }
     // Manually add two user-editable files that are usually sources of problems
     if (file_exists("{$IP}/LocalSettings.php")) {
         $this->mFiles[] = "{$IP}/LocalSettings.php";
     }
     if (file_exists("{$IP}/AdminSettings.php")) {
         $this->mFiles[] = "{$IP}/AdminSettings.php";
     }
     $this->output('done.', 'listfiles');
 }
Example #22
0
 function trimStars($str)
 {
     $i = $count = 0;
     wfSuppressWarnings();
     while ($str[$i++] == '*') {
         ++$count;
     }
     wfRestoreWarnings();
     return array($count, ltrim($str, '* '));
 }
Example #23
0
 private static function validateRegex($regex)
 {
     wfSuppressWarnings();
     $ok = preg_match($regex, '');
     wfRestoreWarnings();
     if ($ok === false) {
         return false;
     }
     return true;
 }
Example #24
0
 /**
  * Establish conncetion
  *
  * @access private
  */
 function connect()
 {
     wfSuppressWarnings();
     $this->mFP = fsockopen($this->mHost, $this->mPort, $errno, $errstr, 30);
     wfRestoreWarnings();
     if (!$this->mFP) {
         return false;
     }
     return true;
 }
 /**
  * @dataProvider provideCases
  * @covers JavaScriptMinifier::minify
  */
 public function testJavaScriptMinifierOutput($code, $expectedOutput)
 {
     $minified = JavaScriptMinifier::minify($code);
     // JSMin+'s parser will throw an exception if output is not valid JS.
     // suppression of warnings needed for stupid crap
     wfSuppressWarnings();
     $parser = new JSParser();
     wfRestoreWarnings();
     $parser->parse($minified, 'minify-test.js', 1);
     $this->assertEquals($expectedOutput, $minified, "Minified output should be in the form expected.");
 }
Example #26
0
 private static function parseLine($g, $line, $lnum)
 {
     $i = 0;
     wfSuppressWarnings();
     // @ doesn't help to supress "uninitialized string offset" warning
     self::skipWhitespace($line, $i);
     if ($line[$i] != '<') {
         die("Invalid BNF at line {$lnum}");
     }
     $i++;
     $end = strpos($line, '>', $i);
     if ($end === false) {
         die("Invalid BNF at line {$lnum}");
     }
     $name = $g->getNonterminalID(substr($line, $i, $end - $i));
     $i = $end + 1;
     self::skipWhitespace($line, $i);
     if (substr($line, $i, 3) != '::=') {
         die("Invalid BNF at line {$lnum}");
     }
     $i += 3;
     $prods = array();
     $curProd = array();
     while ($i + 1 < strlen($line)) {
         self::skipWhitespace($line, $i);
         if ($line[$i] == '|') {
             $prods[] = $curProd;
             $curProd = array();
             $i++;
         } else {
             if ($line[$i] == '<') {
                 $i++;
                 $end = strpos($line, '>', $i);
                 if ($end === false) {
                     die("Invalid BNF at line {$lnum}");
                 }
                 $curProd[] = $g->getNonterminalID(substr($line, $i, $end - $i));
                 $i = $end + 1;
             } else {
                 for ($termName = ''; ctype_alnum($line[$i]); $i++) {
                     $termName .= $line[$i];
                 }
                 if (!$termName) {
                     die("Invalid BNF at line {$lnum}");
                 }
                 $curProd[] = $termName;
             }
         }
     }
     $prods[] = $curProd;
     wfRestoreWarnings();
     return array($name, $prods);
 }
 /**
  * @return mixed
  */
 function getClockTick()
 {
     if (self::$clockTick === null) {
         wfSuppressWarnings();
         self::$clockTick = intval(shell_exec('getconf CLK_TCK'));
         wfRestoreWarnings();
         if (!self::$clockTick) {
             self::$clockTick = 100;
         }
     }
     return self::$clockTick;
 }
 function setUp()
 {
     // Make sure MWDebug class is enabled
     static $MWDebugEnabled = false;
     if (!$MWDebugEnabled) {
         MWDebug::init();
         $MWDebugEnabled = true;
     }
     /** Clear log before each test */
     MWDebug::clearLog();
     wfSuppressWarnings();
 }
 public static function isValid($data)
 {
     $conf = array('BASIC' => array('class' => 'FileBasedMessageGroup', 'namespace' => 8));
     /**
      * @var FileBasedMessageGroup $group
      */
     $group = MessageGroupBase::factory($conf);
     wfSuppressWarnings();
     $ffs = new IniFFS($group);
     $parsed = $ffs->readFromVariable($data);
     wfRestoreWarnings();
     return !!count($parsed['MESSAGES']);
 }
Example #30
0
 public function testSchemaNotAvailableReturnValue()
 {
     $formatter = new AvroFormatter(array());
     $noticeEnabled = PHPUnit_Framework_Error_Notice::$enabled;
     // disable conversion of notices
     PHPUnit_Framework_Error_Notice::$enabled = false;
     // have to keep the user notice from being output
     wfSuppressWarnings();
     $res = $formatter->format(array('channel' => 'marty'));
     wfRestoreWarnings();
     PHPUnit_Framework_Error_Notice::$enabled = $noticeEnabled;
     $this->assertNull($res);
 }