Fixed redirect status codes
authorMarcel Werk <burntime@woltlab.com>
Thu, 14 Jul 2016 12:13:43 +0000 (14:13 +0200)
committerMarcel Werk <burntime@woltlab.com>
Thu, 14 Jul 2016 12:13:43 +0000 (14:13 +0200)
wcfsetup/install/files/lib/page/AbstractPage.class.php
wcfsetup/install/files/lib/system/package/plugin/AbstractOptionPackageInstallationPlugin.class.php
wcfsetup/install/files/lib/system/request/RequestHandler.class.php
wcfsetup/install/files/lib/util/HeaderUtil.class.php

index 4eb1f0d31f960971d78f5b4547a70ed5b366cfd7..f6a29484791e7edb43deda5dde97ed34e756e538 100644 (file)
@@ -255,8 +255,7 @@ abstract class AbstractPage implements IPage {
                                
                                // force a permanent redirect as recommended by Google
                                // https://support.google.com/webmasters/answer/6033086?hl=en#a_note_about_redirects
-                               @header('HTTP/1.0 301 Moved Permanently');
-                               HeaderUtil::redirect($redirectURL, false);
+                               HeaderUtil::redirect($redirectURL, true, false);
                                exit;
                        }
                }
index 8b60ba775a0a632b2818267c1dc5062319805457..3c34e482fd82402b39254341564d4cc1bc86c9ac 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\package\plugin;
+use wcf\data\package\Package;
 use wcf\system\exception\SystemException;
 use wcf\system\WCF;
 
@@ -167,12 +168,7 @@ abstract class AbstractOptionPackageInstallationPlugin extends AbstractXMLPackag
                        
                        $data['name'] = $element->getAttribute('name');
                        
-                       if (!preg_match("/^[\w-\.]+$/", $data['name'])) {
-                               $matches = [];
-                               preg_match_all("/(\W)/", $data['name'], $matches);
-                               throw new SystemException("The option '".$data['name']."' has at least one non-alphanumeric character (underscore is permitted): (".implode("), ( ", $matches[1]).").");
-                       }
-                       
+                       $this->validateOption($data);
                        $this->saveOption($data, $data['categoryname']);
                }
        }
@@ -275,6 +271,31 @@ abstract class AbstractOptionPackageInstallationPlugin extends AbstractXMLPackag
         */
        abstract protected function saveOption($option, $categoryName, $existingOptionID = 0);
        
+       /**
+        * @inheritDoc
+        */
+       protected function validateOption(array $data) {
+               if (!preg_match("/^[\w-\.]+$/", $data['name'])) {
+                       $matches = [];
+                       preg_match_all("/(\W)/", $data['name'], $matches);
+                       throw new SystemException("The option '".$data['name']."' has at least one non-alphanumeric character (underscore is permitted): (".implode("), ( ", $matches[1]).").");
+               }
+               
+               // check if option already exists
+               $sql = "SELECT  *
+                       FROM    wcf".WCF_N."_".$this->tableName."
+                       WHERE   optionName = ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute([
+                       $data['name']
+               ]);
+               $row = $statement->fetchArray();
+               if ($row && $row['packageID'] != $this->installation->getPackageID()) {
+                       $package = new Package($row['packageID']);
+                       throw new SystemException($this->tableName . " '" . $data['name'] . "' is already provided by '" . $package . "' ('" . $package->package . "').");
+               }
+       }
+       
        /**
         * @inheritDoc
         */
index e3abf75b2d180f43e173b9043f08ca215defe03f..f8446989550c24d354b3258e75a69588d25787fe 100644 (file)
@@ -123,7 +123,7 @@ class RequestHandler extends SingletonFactory {
                                                        $url .= '?' . $_SERVER['QUERY_STRING'];
                                                }
                                                
-                                               HeaderUtil::redirect($url, true);
+                                               HeaderUtil::redirect($url, true, false);
                                                exit;
                                        }
                                }
@@ -197,7 +197,7 @@ class RequestHandler extends SingletonFactory {
                }
                
                $redirectURL = LinkHandler::getInstance()->getLink($routeData['controller'], $routeData);
-               HeaderUtil::redirect($redirectURL, true);
+               HeaderUtil::redirect($redirectURL, true, false);
                exit;
        }
        
@@ -220,7 +220,7 @@ class RequestHandler extends SingletonFactory {
                }
                else if (!empty($data['redirect'])) {
                        // force a redirect
-                       HeaderUtil::redirect($data['redirect'], true);
+                       HeaderUtil::redirect($data['redirect'], true, false);
                }
                
                // copy route data
index e576f7dff523a13ec2f8e8f3494b57164e0cd050..ab3c53c286a77671a3a7cb9e1d4f3267d50ce316 100644 (file)
@@ -141,14 +141,18 @@ final class HeaderUtil {
        }
        
        /**
-        * Redirects the user agent.
+        * Redirects the user agent to given location.
         * 
         * @param       string          $location
         * @param       boolean         $sendStatusCode
+        * @param       boolean         $temporaryRedirect 
         */
-       public static function redirect($location, $sendStatusCode = false) {
-               //if ($sendStatusCode) @header('HTTP/1.0 301 Moved Permanently');
-               if ($sendStatusCode) @header('HTTP/1.1 307 Temporary Redirect');
+       public static function redirect($location, $sendStatusCode = false, $temporaryRedirect = true) {
+               if ($sendStatusCode) {
+                       if ($temporaryRedirect) @header('HTTP/1.1 307 Temporary Redirect');
+                       else @header('HTTP/1.0 301 Moved Permanently');
+               }
+               
                header('Location: '.$location);
        }