示例#1
0
 /**
  * Update a page
  *
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Entry identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "title",
  * 		"description": "Entry title",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "pagename",
  * 		"description": "Page name",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "pagetext",
  * 		"description": "Page content",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "created",
  * 		"description": "Created timestamp (YYYY-MM-DD HH:mm:ss)",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "now"
  * }
  * @apiParameter {
  * 		"name":        "created_by",
  * 		"description": "User ID of entry creator",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "state",
  * 		"description": "Published state (0 = unpublished, 1 = published)",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "access",
  * 		"description": "Access level (0 = public, 1 = registered users, 4 = private)",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @apiParameter {
  * 		"name":        "scope",
  * 		"description": "Page scope",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "group_cn",
  * 		"description": "Group name the wiki page belongs to",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     ""
  * }
  * @apiParameter {
  * 		"name":        "params",
  * 		"description": "Page options",
  * 		"type":        "array",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "summary",
  * 		"description": "Summary of changes made",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @return  void
  */
 public function updateTask()
 {
     $this->requiresAuthentication();
     $fields = array('title' => Request::getVar('title', null, '', 'none', 2), 'pagename' => Request::getVar('pagename', null), 'scope' => Request::getVar('scope', null), 'created' => Request::getVar('created', null), 'created_by' => Request::getInt('created_by', null), 'state' => Request::getInt('state', null), 'access' => Request::getInt('access', null), 'group_cn' => Request::getVar('group_cn', null));
     if (!$id) {
         throw new Exception(Lang::txt('COM_TAGS_ERROR_MISSING_DATA'), 422);
     }
     $page = new Page($id);
     if (!$page->exists()) {
         throw new Exception(Lang::txt('Specified page not found.'), 404);
     }
     $revision = $page->revision('current');
     if (!$revision->bind($rev)) {
         throw new Exception($revision->getError(), 500);
     }
     $params = new \Hubzero\Config\Registry($page->get('params', ''));
     $params->merge(Request::getVar('params', array(), 'post'));
     $page->set('params', $params->toString());
     foreach ($fields as $key => $value) {
         if (!is_null($value)) {
             $page->set($key, $value);
         }
     }
     $page->set('modified', Date::toSql());
     if (!$page->store(true)) {
         throw new Exception($page->getError(), 500);
     }
     if (!$page->updateAuthors(Request::getVar('authors', '', 'post'))) {
         throw new Exception($page->getError(), 500);
     }
     $revision->set('pagetext', Request::getVar('pagetext', '', '', 'none', 2));
     $revision->set('summary', Request::getVar('summary', null));
     if ($revision->get('pagetext') == '') {
         $revision->set('id', 0);
         $revision->set('pageid', $page->get('id'));
         $revision->set('pagename', $page->get('pagename'));
         $revision->set('scope', $page->get('scope'));
         $revision->set('group_cn', $page->get('group_cn'));
         $revision->set('version', $revision->get('version') + 1);
         if ($page->param('mode', 'wiki') == 'knol') {
             // Set revisions to NOT approved
             $revision->set('approved', 0);
             // If an author or the original page creator, set to approved
             if ($page->get('created_by') == User::get('id') || $page->isAuthor(User::get('id'))) {
                 $revision->set('approved', 1);
             }
         } else {
             // Wiki mode, approve revision
             $revision->set('approved', 1);
         }
         $revision->set('pagehtml', $revision->content('parsed'));
         if ($page->access('manage') || $page->access('edit')) {
             $revision->set('approved', 1);
         }
         // Store content
         if (!$revision->store(true)) {
             throw new Exception(Lang::txt('COM_WIKI_ERROR_SAVING_REVISION'), 500);
         }
         $page->set('version_id', $revision->get('id'));
         if (!$page->store(true)) {
             throw new Exception($page->getError(), 500);
         }
     }
     $page->tag(Request::getVar('tags', ''));
     $this->send($page->toObject());
 }