public function execute($sub) { global $wgOut, $wgScriptPath, $wgUser, $wgRequest; // Checks if the user is logged in if (!$wgUser->isLoggedIn()) { // Lets them know they need to $wgOut->loginToUse(); // Returns true so MediaWiki can move on return true; } // Gets user rights self::$rights = $wgUser->getRights(); if (!self::userCan('view')) { $wgOut->permissionRequired('datacenter-view'); return true; } // Keeps some state between pages self::loadState(); // Begins output $this->setHeaders(); // Checks if the path is empty if ($sub == '') { // Uses the first page in the array as a default $sub = current(array_keys(self::$pages)); } // Gets path from sub $path = self::subToPath($sub); // Verifies page name and parameters if (isset(self::$pages[$path['page']])) { // Makes shortcut to page classes $pageClasses = self::$pages[$path['page']]; // Makes shortcut to controller class $controllerClass = $pageClasses['controller']; // Verifies existence of page class if (class_exists($controllerClass)) { // Creates instance of page class $controller = new $controllerClass($path); // Checks if the view is empty if ($path['action'] === null) { // Uses default action $path['action'] = 'main'; } // Checks if the type is empty if ($path['type'] === null) { // Checks if default type is available if (isset(self::$pages[$path['page']]['default'])) { // Uses default type $path['type'] = self::$pages[$path['page']]['default']; } } // Verifies instance inherited the correct parent class if ($controller instanceof DataCenterController) { // Verifies the current edit token matches any passed token $token = $wgRequest->getText('token'); if ($wgUser->matchEditToken($token)) { // Gets the action to be performed $do = $wgRequest->getText('do'); // Verifies handler is not the instance's constructor and // that action exists in the instance if ($do !== '__constructor' && is_callable(array($controllerClass, $do))) { if ($wgRequest->getCheck('cancel')) { // Redirects to success URL without acting $wgOut->redirect($wgRequest->getText('cancellation')); } else { // Gets submitted data $data = array('row' => $wgRequest->getArray('row'), 'meta' => $wgRequest->getArray('meta'), 'change' => $wgRequest->getArray('change')); // Delegates handling of form submissions $status = $controller->{$do}($data, $path['type']); // Checks if status is not null if ($status !== null) { // Redirects to success or failure URL $wgOut->redirect($wgRequest->getText($status ? 'success' : 'failure')); } } } } // Sets destinations for menus DataCenterUI::setDestinations(self::$pages, $controller, $path); $viewClass = null; // Checks if specialized view exists if (isset($pageClasses['types'][$path['type']])) { // Uses specialized view $viewClass = $pageClasses['types'][$path['type']]; // Verifies specialized view can handle action $renderFunction = array($viewClass, $path['action']); if (!is_callable($renderFunction)) { $viewClass = null; } } // Checks if a view class has been not selected yet if (!$viewClass) { // Uses generic view $viewClass = $pageClasses['view']; // Verifies generic view can handle action $renderFunction = array($viewClass, $path['action']); if (!is_callable($renderFunction)) { $viewClass = null; } } // Verifies page user interface class exists if ($viewClass && class_exists($viewClass)) { // Creates instance of page user interface class $view = new $viewClass($controller); // Verifies the action is not the instance's constructor if ($path['action'] !== '__constructor') { // Renders view of instance $renderFunction = array($view, $path['action']); DataCenterUI::addContent(call_user_func($renderFunction, $path)); } } } } } DataCenterUI::render(); // Keeps some state between pages self::saveState(); }