Fixed WCFSetup / ACP
authorAlexander Ebert <ebert@woltlab.com>
Tue, 24 Nov 2015 18:51:13 +0000 (19:51 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 24 Nov 2015 18:51:13 +0000 (19:51 +0100)
wcfsetup/install.php
wcfsetup/install/files/lib/system/WCFSetup.class.php
wcfsetup/install/files/lib/system/request/LinkHandler.class.php
wcfsetup/install/files/lib/system/request/RequestHandler.class.php
wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php

index db3b11b607e68494e016d22d6abc220f535f0cf0..de5a1789d39f5ec79a0cf868187b1b49cf90b21d 100644 (file)
@@ -158,7 +158,7 @@ class SystemException extends \Exception implements IPrintableException {
 /**
  * Loads the required classes automatically.
  */
-function __autoload($className) {
+spl_autoload_register(function($className) {
        $namespaces = explode('\\', $className);
        if (count($namespaces) > 1) {
                // remove 'wcf' component
@@ -170,7 +170,7 @@ function __autoload($className) {
                        require_once($classPath);
                }
        }
-}
+});
 
 /**
  * Escapes strings for execution in sql queries.
@@ -577,15 +577,33 @@ class Tar {
                $i = 0;
                
                // Read the 512 bytes header
+               $longFilename = null;
                while (strlen($binaryData = $this->file->read(512)) != 0) {
                        // read header
                        $header = $this->readHeader($binaryData);
                        if ($header === false) {
                                continue;
                        }
-                       $this->contentList[$i] = $header;
-                       $this->contentList[$i]['index'] = $i;
-                       $i++;
+                       
+                       // fixes a bug that files with long names aren't correctly
+                       // extracted
+                       if ($longFilename !== null) {
+                               $header['filename'] = $longFilename;
+                               $longFilename = null;
+                       }
+                       if ($header['typeflag'] == 'L') {
+                               $format = 'Z'.$header['size'].'filename';
+                               
+                               $fileData = unpack($format, $this->file->read(512));
+                               $longFilename = $fileData['filename'];
+                               $header['size'] = 0;
+                       }
+                       // don't include the @LongLink file in the content list
+                       else {
+                               $this->contentList[$i] = $header;
+                               $this->contentList[$i]['index'] = $i;
+                               $i++;
+                       }
                        
                        $this->file->seek($this->file->tell() + (512 * ceil(($header['size'] / 512))));
                }
@@ -593,7 +611,7 @@ class Tar {
        
        /**
         * Unpacks file header for one file entry.
-        *
+        * 
         * @param       string          $binaryData
         * @return      array           $fileheader
         */
@@ -618,14 +636,8 @@ class Tar {
                        $checksum += ord(substr($binaryData, $i, 1));
                }
                
-               // Extract the values
-               //$data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", $binaryData);
-               if (version_compare(PHP_VERSION, '5.5.0-dev', '>=')) {
-                       $format = 'Z100filename/Z8mode/Z8uid/Z8gid/Z12size/Z12mtime/Z8checksum/Z1typeflag/Z100link/Z6magic/Z2version/Z32uname/Z32gname/Z8devmajor/Z8devminor/Z155prefix';
-               }
-               else {
-                       $format = 'a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix';
-               }
+               // extract values
+               $format = 'Z100filename/Z8mode/Z8uid/Z8gid/Z12size/Z12mtime/Z8checksum/Z1typeflag/Z100link/Z6magic/Z2version/Z32uname/Z32gname/Z8devmajor/Z8devminor/Z155prefix';
                
                $data = unpack($format, $binaryData);
                
index b53cef6a3ae23e7d85432e794fc35fafeed3b43f..9e0b2c8bf32a90c24e9e1b07cf8237ce173c9652 100644 (file)
@@ -221,19 +221,15 @@ class WCFSetup extends WCF {
         * @return      array
         */
        protected static function getAvailableLanguages() {
-               $languages = $match = array();
-               $tar = new Tar(SETUP_FILE);
-               foreach ($tar->getContentList() as $file) {
-                       if (strpos($file['filename'], 'setup/lang/') === 0 && substr($file['filename'], -4) == '.xml') {
-                               $xml = new XML();
-                               $xml->load(TMP_DIR.$file['filename']);
-                               $languageCode = LanguageEditor::readLanguageCodeFromXML($xml);
-                               $languageName = LanguageEditor::readLanguageNameFromXML($xml);
-                               
-                               $languages[$languageCode] = $languageName;
-                       }
+               $languages = $match = [];
+               foreach (glob(TMP_DIR.'setup/lang/*.xml') as $file) {
+                       $xml = new XML();
+                       $xml->load($file);
+                       $languageCode = LanguageEditor::readLanguageCodeFromXML($xml);
+                       $languageName = LanguageEditor::readLanguageNameFromXML($xml);
+                       
+                       $languages[$languageCode] = $languageName;
                }
-               $tar->close();
                
                // sort languages by language name
                asort($languages);
@@ -1163,7 +1159,7 @@ class WCFSetup extends WCF {
                }
                
                // login as admin
-               $factory = new ACPSessionFactory();
+               $factory = WCF::getDIContainer()->make(ACPSessionFactory::class);
                $factory->load();
                
                SessionHandler::getInstance()->changeUser($admin);
index dbdfef6f376b8547549440a320b3f4b454deb643..808bae89387d57271e737112592876af88c28eef 100644 (file)
@@ -24,11 +24,6 @@ class LinkHandler extends SingletonFactory {
         */
        protected $applicationHandler;
        
-       /**
-        * @var PageMenu
-        */
-       protected $pageMenu;
-       
        /**
         * @var RequestHandler
         */
@@ -64,9 +59,8 @@ class LinkHandler extends SingletonFactory {
         * @param       RequestHandler          $requestHandler
         * @param       RouteHandler            $routeHandler
         */
-       public function __construct(ApplicationHandler $applicationHandler, PageMenu $pageMenu, RequestHandler $requestHandler, RouteHandler $routeHandler) {
+       public function __construct(ApplicationHandler $applicationHandler, RequestHandler $requestHandler, RouteHandler $routeHandler) {
                $this->applicationHandler = $applicationHandler;
-               $this->pageMenu = $pageMenu;
                $this->requestHandler = $requestHandler;
                $this->routeHandler = $routeHandler;
                
@@ -163,7 +157,8 @@ class LinkHandler extends SingletonFactory {
                                $controller = 'Index';
                        }
                        else {
-                               return $this->pageMenu->getLandingPage()->getProcessor()->getLink();
+                               // loading the PageMenu object as a dependency in ACP requests breaks everything
+                               return WCF::getDIContainer()->get(PageMenu::class)->getLandingPage()->getProcessor()->getLink();
                        }
                }
                
index 0e880d784b4244af7f35c2fc268695aaeaa65821..59ad080c40fd5a7035f0014b1037f06d89b14f92 100644 (file)
@@ -49,11 +49,6 @@ class RequestHandler extends SingletonFactory {
         */
        protected $isACPRequest = false;
        
-       /**
-        * @var PageMenu
-        */
-       protected $pageMenu;
-       
        /**
         * @var RouteHandler
         */
@@ -66,10 +61,9 @@ class RequestHandler extends SingletonFactory {
         * @param       ControllerMap           $controllerMap
         * @param       RouteHandler            $routeHandler
         */
-       public function __construct(ApplicationHandler $applicationHandler, ControllerMap $controllerMap, PageMenu $pageMenu, RouteHandler $routeHandler) {
+       public function __construct(ApplicationHandler $applicationHandler, ControllerMap $controllerMap, RouteHandler $routeHandler) {
                $this->applicationHandler = $applicationHandler;
                $this->controllerMap = $controllerMap;
-               $this->pageMenu = $pageMenu;
                $this->routeHandler = $routeHandler;
                
                parent::__construct();
@@ -273,7 +267,8 @@ class RequestHandler extends SingletonFactory {
                        return;
                }
                
-               $landingPage = $this->pageMenu->getLandingPage();
+               // loading the PageMenu object as a dependency in ACP requests breaks everything
+               $landingPage = WCF::getDIContainer()->get(PageMenu::class)->getLandingPage();
                if ($landingPage === null) {
                        return;
                }
index 7b20a0113a27d1b2db95ab2045e94584661ea625..d9b2bfb69867face4bb9731a770434ea710f2c89 100644 (file)
@@ -5,6 +5,7 @@ use wcf\system\menu\page\PageMenu;
 use wcf\system\request\ControllerMap;
 use wcf\system\request\RequestHandler;
 use wcf\system\request\RouteHandler;
+use wcf\system\WCF;
 
 /**
  * Dynamic route implementation to resolve HTTP requests, handling controllers using a distinct pattern.
@@ -39,11 +40,6 @@ class DynamicRequestRoute implements IRequestRoute {
         */
        protected $isACP = false;
        
-       /**
-        * @var PageMenu;
-        */
-       protected $pageMenu;
-       
        /**
         * pattern for incoming requests
         * @var string
@@ -83,14 +79,12 @@ class DynamicRequestRoute implements IRequestRoute {
         * 
         * @param       ApplicationHandler      $applicationHandler
         * @param       ControllerMap           $controllerMap
-        * @param       PageMenu                $pageMenu
         * @param       RequestHandler          $requestHandler
         * @param       RouteHandler            $routeHandler
         */
-       public function __construct(ApplicationHandler $applicationHandler, ControllerMap $controllerMap, PageMenu $pageMenu, RequestHandler $requestHandler, RouteHandler $routeHandler) {
+       public function __construct(ApplicationHandler $applicationHandler, ControllerMap $controllerMap, RequestHandler $requestHandler, RouteHandler $routeHandler) {
                $this->applicationHandler = $applicationHandler;
                $this->controllerMap = $controllerMap;
-               $this->pageMenu = $pageMenu;
                $this->requestHandler = $requestHandler;
                $this->routeHandler = $routeHandler;
                
@@ -185,15 +179,16 @@ class DynamicRequestRoute implements IRequestRoute {
                if (count($components) == 1 && isset($components['controller'])) {
                        $ignoreController = false;
                        
-                       if (!RequestHandler::getInstance()->isACPRequest()) {
-                               $landingPage = PageMenu::getInstance()->getLandingPage();
+                       if (!$this->requestHandler->isACPRequest()) {
+                               // loading the PageMenu object as a dependency in ACP requests breaks everything
+                               $landingPage = WCF::getDIContainer()->get(PageMenu::class)->getLandingPage();
                                if ($this->primaryApplication === '') {
-                                       $primaryApplication = ApplicationHandler::getInstance()->getPrimaryApplication();
-                                       $this->primaryApplication = ApplicationHandler::getInstance()->getAbbreviation($primaryApplication->packageID);
+                                       $primaryApplication = $this->applicationHandler->getPrimaryApplication();
+                                       $this->primaryApplication = $this->applicationHandler->getAbbreviation($primaryApplication->packageID);
                                }
                                
                                // check if this is the default controller
-                               if (strcasecmp(RouteHandler::getInstance()->getDefaultController($application), $components['controller']) === 0) {
+                               if (strcasecmp($this->routeHandler->getDefaultController($application), $components['controller']) === 0) {
                                        // check if this matches the primary application
                                        if ($this->primaryApplication === $application) {
                                                if (strcasecmp($landingPage->getController(), $components['controller']) === 0) {