Esempio n. 1
0
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access.
defined('_HZEXEC_') or die;
Pathway::append(Lang::txt('COM_WIKI_SEARCH'), $this->page->link('base') . '&pagename=Special:Search');
$database = App::get('db');
$limit = Request::getInt('limit', Config::get('list_limit'));
$start = Request::getInt('limitstart', 0);
$term = Request::getVar('q', '');
$filters = array('state' => array(0, 1));
if ($space = Request::getVar('namespace', '')) {
    $filters['namespace'] = urldecode($space);
}
$pages = \Components\Wiki\Models\Page::blank()->getTableName();
$versions = \Components\Wiki\Models\Version::blank()->getTableName();
$weight = '(match(' . $pages . '.title) against (' . $database->Quote($term) . ') + match(' . $versions . '.pagetext) against (' . $database->Quote($term) . '))';
$rows = $this->book->pages($filters)->select($pages . '.*')->select($versions . '.created_by')->select($versions . '.summary')->select($weight, 'weight')->join($versions, $versions . '.id', $pages . '.version_id')->whereRaw($weight . ' > 0')->order('weight', 'desc')->paginated()->rows();
?>
<form action="<?php 
echo Route::url($this->page->link('base') . '&pagename=Special:Search');
?>
" method="get">
	<div class="container data-entry">
		<input class="entry-search-submit" type="submit" value="<?php 
echo Lang::txt('COM_WIKI_SEARCH');
?>
" />
		<fieldset class="entry-search">
			<legend><?php 
echo Lang::txt('COM_WIKI_SEARCH_LEGEND');
Esempio n. 2
0
 /**
  * Approve a revision
  *
  * @return  void
  */
 public function approveTask()
 {
     // Check if they are logged in
     if (User::isGuest()) {
         $url = Request::getVar('REQUEST_URI', '', 'server');
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url), false));
     }
     // Incoming
     $id = Request::getInt('oldid', 0);
     if (!$id || !$this->page->access('manage')) {
         App::redirect(Route::url($this->page->link()));
     }
     // Load the revision, approve it, and save
     $revision = Version::oneOrFail($id);
     $revision->set('approved', 1);
     if (!$revision->save()) {
         App::abort(500, $revision->getError());
     }
     // Get the most recent revision and compare to the set "current" version
     $last = $this->page->versions()->whereEquals('approved', 1)->order('version', 'desc')->row();
     if ($last->get('id') == $revision->get('id')) {
         // The newly approved revision is now the most current
         // So, we need to update the page's version_id
         $this->page->set('version_id', $last->get('id'));
         $this->page->save();
     }
     $this->page->log('revision_approved');
     // Log activity
     $recipients = array(['wiki.site', 1], ['user', $this->page->get('created_by')], ['user', $revision->get('created_by')]);
     if ($this->page->get('scope') != 'site') {
         $recipients[] = [$this->page->get('scope'), $this->page->get('scope_id')];
         $recipients[0] = ['wiki.' . $this->page->get('scope'), $this->page->get('scope_id')];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'approved', 'scope' => 'wiki.page.revision', 'scope_id' => $this->page->get('id'), 'description' => Lang::txt('COM_WIKI_ACTIVITY_REVISION_APPROVED', $revision->get('id'), '<a href="' . Route::url($this->page->link()) . '">' . $this->page->title . '</a>'), 'details' => array('title' => $this->page->title, 'url' => Route::url($this->page->link()), 'name' => $this->page->get('pagename'), 'revision' => $revision->get('id'))], 'recipients' => $recipients]);
     App::redirect(Route::url($this->page->link()));
 }
Esempio n. 3
0
 /**
  * Set the approval state for a revision
  *
  * @return  void
  */
 public function approveTask()
 {
     // Check for request forgeries
     Request::checkToken('get');
     if (!User::authorise('core.edit.state', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $id = Request::getInt('id', 0);
     if ($id) {
         // Load the revision, approve it, and save
         $version = Version::oneOrFail($id);
         $version->set('approved', Request::getInt('approve', 0));
         if (!$version->save()) {
             Notify::error($version->getError());
         }
     }
     $this->cancelTask();
 }
Esempio n. 4
0
 /**
  * Return either a count or an array of the member's contributions
  *
  * @param   object   $member      Current member
  * @param   string   $option      Component name
  * @param   string   $authorized  Authorization level
  * @param   integer  $limit       Number of record to return
  * @param   integer  $limitstart  Record return start
  * @param   string   $sort        Field to sort records on
  * @param   array    $areas       Areas to return data for
  * @return  array
  */
 public function onMembersContributions($member, $option, $limit = 0, $limitstart = 0, $sort, $areas = null)
 {
     if (is_array($areas) && $limit) {
         if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas) && !array_intersect($areas, array_keys($this->onMembersContributionsAreas()))) {
             return array();
         }
     }
     // Do we have a member ID?
     if ($member instanceof \Hubzero\User\User) {
         if (!$member->get('id')) {
             return array();
         } else {
             $uidNumber = $member->get('id');
             $username = $member->get('username');
         }
     } else {
         if (!$member->uidNumber) {
             return array();
         } else {
             $uidNumber = $member->uidNumber;
             $username = $member->username;
         }
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
     $versions = \Components\Wiki\Models\Version::all()->whereEquals('created_by', $uidNumber)->whereEquals('approved', 1)->group('page_id')->rows();
     $ids = array();
     foreach ($versions as $version) {
         $ids[] = $version->get('page_id');
     }
     $rows = \Components\Wiki\Models\Page::all()->whereEquals('state', \Components\Wiki\Models\Page::STATE_PUBLISHED)->whereEquals('scope', 'site')->whereIn('id', $ids)->limit($limit)->start($limitstart);
     if (!$limit) {
         return $rows->count();
     } else {
         return $rows->rows();
     }
 }
Esempio n. 5
0
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access.
defined('_HZEXEC_') or die;
Pathway::append(Lang::txt('COM_WIKI_SPECIAL_FIX_LENGTH'), $this->page->link());
$rows = \Components\Wiki\Models\Version::all()->whereEquals('length', 0)->whereEquals('scope', $this->page->get('scope'))->whereEquals('scope_id', $this->page->get('scope_id'))->rows();
?>
<form method="get" action="<?php 
echo Route::url($this->page->link());
?>
">
	<p>
		<?php 
echo Lang::txt('COM_WIKI_SPECIAL_FIX_LENGTH_ABOUT');
?>
	</p>
	<div class="container">
		<table class="entries">
			<thead>
				<tr>
					<th scope="col">
Esempio n. 6
0
 /**
  * Save a wiki page
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Check if they are logged in
     if (User::isGuest()) {
         $url = Request::getVar('REQUEST_URI', '', 'server');
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url), false));
     }
     // Incoming revision
     $revision = $this->page->version;
     $revision->set('version', $revision->get('version') + 1);
     $revision->set(Request::getVar('revision', array(), 'post', 'none', 2));
     $revision->set('id', 0);
     // Incoming page
     $page = Request::getVar('page', array(), 'post', 'none', 2);
     if (!isset($page['protected']) || !$page['protected']) {
         $page['protected'] = 0;
     }
     $this->page = Page::oneOrNew(intval($revision->get('page_id')));
     $this->page->set($page);
     $this->page->set('pagename', trim(Request::getVar('pagename', '', 'post')));
     // Get parameters
     $params = new \Hubzero\Config\Registry($this->page->get('params', ''));
     $params->merge(Request::getVar('params', array(), 'post'));
     $this->page->set('params', $params->toString());
     // Get the previous version to compare against
     if (!$revision->get('page_id')) {
         // New page - save it to the database
         $this->page->set('created_by', User::get('id'));
         $old = Version::blank();
     } else {
         // Get the revision before changes
         $old = $this->page->version;
     }
     // Was the preview button pushed?
     $this->preview = trim(Request::getVar('preview', ''));
     if ($this->preview) {
         // Set the component task
         if (!$page['id']) {
             Request::setVar('task', 'new');
             $this->_task = 'new';
         } else {
             Request::setVar('task', 'edit');
             $this->_task = 'edit';
         }
         // Push on through to the edit form
         return $this->editTask($revision);
     }
     // Check content
     // First, make sure the pagetext isn't empty
     if ($revision->get('pagetext') == '') {
         $this->setError(Lang::txt('COM_WIKI_ERROR_MISSING_PAGETEXT'));
         return $this->editTask($revision);
     }
     // Store new content
     if (!$this->page->save()) {
         $this->setError($this->page->getError());
         return $this->editTask($revision);
     }
     // Get allowed authors
     if (!Author::setForPage(Request::getVar('authors', '', 'post'), $this->page->get('id'))) {
         $this->setError(Lang::txt('COM_WIKI_ERROR_SAVING_AUTHORS'));
         return $this->editTask($revision);
     }
     // Get the upload path
     $path = Attachment::blank()->filespace();
     // Rename the temporary upload directory if it exist
     $lid = Request::getInt('lid', 0, 'post');
     if ($lid != $this->page->get('id')) {
         if (is_dir($path . DS . $lid)) {
             if (!\Filesystem::move($path . DS . $lid, $path . DS . $this->page->get('id'))) {
                 $this->setError(\Filesystem::move($path . DS . $lid, $path . DS . $this->page->get('id')));
             }
         }
         foreach (Attachment::all()->whereEquals('page_id', $lid)->rows() as $attachment) {
             $attachment->set('page_id', $this->page->get('id'));
             if (!$attachment->save()) {
                 $this->setError($attachment->getError());
             }
         }
     }
     $revision->set('page_id', $this->page->get('id'));
     $revision->set('version', $revision->get('version') + 1);
     if ($this->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 ($this->page->get('created_by') == User::get('id') || $this->page->isAuthor(User::get('id'))) {
             $revision->set('approved', 1);
         }
     } else {
         // Wiki mode, approve revision
         $revision->set('approved', 1);
     }
     // Compare against previous revision
     // We don't want to create a whole new revision if just the tags were changed
     if (rtrim($old->get('pagetext')) != rtrim($revision->get('pagetext'))) {
         // Transform the wikitext to HTML
         $revision->set('pagehtml', '');
         $revision->set('pagehtml', $revision->content($this->page));
         if ($this->page->access('manage') || $this->page->access('edit')) {
             $revision->set('approved', 1);
         }
         // Store content
         if (!$revision->save()) {
             $this->setError(Lang::txt('COM_WIKI_ERROR_SAVING_REVISION'));
             return $this->editTask($revision);
         }
         $this->page->set('version_id', $revision->get('id'));
         $this->page->set('modified', $revision->get('created'));
     } else {
         $this->page->set('modified', Date::toSql());
     }
     if (!$this->page->save()) {
         // This really shouldn't happen.
         $this->setError(Lang::txt('COM_WIKI_ERROR_SAVING_PAGE'));
         return $this->editTask($revision);
     }
     // Process tags
     $this->page->tag(Request::getVar('tags', ''));
     // Log activity
     $recipients = array(['wiki.site', 1], ['user', $this->page->get('created_by')], ['user', $revision->get('created_by')]);
     if ($this->page->get('scope') != 'site') {
         $recipients[] = [$this->page->get('scope'), $this->page->get('scope_id')];
         $recipients[0] = ['wiki.' . $this->page->get('scope'), $this->page->get('scope_id')];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => $page['id'] ? 'updated' : 'created', 'scope' => 'wiki.page', 'scope_id' => $this->page->get('id'), 'description' => Lang::txt('COM_WIKI_ACTIVITY_PAGE_' . ($page['id'] ? 'UPDATED' : 'CREATED'), '<a href="' . Route::url($this->page->link()) . '">' . $this->page->title . '</a>'), 'details' => array('title' => $this->page->title, 'url' => Route::url($this->page->link()), 'name' => $this->page->get('pagename'), 'revision' => $revision->get('id'))], 'recipients' => $recipients]);
     // Redirect
     App::redirect(Route::url($this->page->link()));
 }