/** * @desc Purge the contributors data to guarantee that it will be refreshed next time it is required * * @param WikiPage $wikiPage * @param User $user * @param $revision * @param $current * @return bool */ public static function onArticleRollbackComplete(WikiPage $wikiPage, User $user, $revision, $current) { $articleId = $wikiPage->getId(); $key = MercuryApi::getTopContributorsKey($articleId, MercuryApiController::NUMBER_CONTRIBUTORS); WikiaDataAccess::cachePurge($key); return true; }
/** * @covers Revision::getContent */ public function testGetContent_failure() { $rev = new Revision(['page' => $this->the_page->getId(), 'content_model' => $this->the_page->getContentModel(), 'text_id' => 123456789]); $this->assertNull($rev->getContent(), "getContent() should return null if the revision's text blob could not be loaded."); // NOTE: check this twice, once for lazy initialization, and once with the cached value. $this->assertNull($rev->getContent(), "getContent() should return null if the revision's text blob could not be loaded."); }
public function getFromattedUgroupsThatCanReadWikiPage(WikiPage $wiki_page) { $project = $this->project_manager->getProject($wiki_page->getGid()); $ugroup_ids = $this->permission_manager->getAuthorizedUgroupIds($wiki_page->getId(), self::WIKI_PERMISSION_READ); $ugroup_ids = $this->filterWikiPagePermissionsAccordingToService($project, $ugroup_ids); $ugroup_ids = $this->filterWikiPagePermissionsAccordingToProject($project, $ugroup_ids); return $this->literalizer->ugroupIdsToString($ugroup_ids, $project); }
protected function makeRevision($props = null) { if ($props === null) { $props = array(); } if (!isset($props['content']) && !isset($props['text'])) { $props['text'] = 'Lorem Ipsum'; } if (!isset($props['comment'])) { $props['comment'] = 'just a test'; } if (!isset($props['page'])) { $props['page'] = $this->the_page->getId(); } $rev = new Revision($props); $dbw = wfgetDB(DB_MASTER); $rev->insertOn($dbw); return $rev; }
/** * Delete $page */ protected function doDelete($page) { if ($page instanceof Title) { $page = new WikiPage($page); } if ($this->logActions) { print "Delete " . $page->getTitle() . " = " . $page->getId() . "\n"; } $page->doDeleteArticle('-'); }
/** * Refresh cache when article is edited * * @param WikiPage $article */ static function onArticleSaveComplete(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId) { wfProfileIn(__METHOD__); $articleId = $article->getId(); // tell service to invalidate cached data for edited page $service = new self($articleId); $service->regenerateData(); wfDebug(__METHOD__ . ": cache cleared for page #{$articleId}\n"); wfProfileOut(__METHOD__); return true; }
/** * @param WikiPage $page Page we are updating * @param integer|null $pageId ID of the page we are updating [optional] * @throws MWException */ function __construct(WikiPage $page, $pageId = null) { parent::__construct(false); // no implicit transaction $this->page = $page; if ($page->exists()) { $this->pageId = $page->getId(); } elseif ($pageId) { $this->pageId = $pageId; } else { throw new MWException("Page ID not known, perhaps the page doesn't exist?"); } }
/** * @param WikiPage $page Page we are updating * @param integer|null $pageId ID of the page we are updating [optional] * @param string|null $timestamp TS_MW timestamp of deletion * @throws MWException */ function __construct(WikiPage $page, $pageId = null, $timestamp = null) { parent::__construct(); $this->page = $page; if ($pageId) { $this->pageId = $pageId; // page ID at time of deletion } elseif ($page->exists()) { $this->pageId = $page->getId(); } else { throw new InvalidArgumentException("Page ID not known. Page doesn't exist?"); } $this->timestamp = $timestamp ?: wfTimestampNow(); }
/** * Get text of an article from database * Does *NOT* follow redirects. * * @param $oldid Int: 0 for whatever the latest revision is * @return mixed string containing article contents, or false if null */ function fetchContent($oldid = 0) { if ($this->mContentLoaded) { return $this->mContent; } # Pre-fill content with error message so that if something # fails we'll have something telling us what we intended. $t = $this->getTitle()->getPrefixedText(); $d = $oldid ? wfMsgExt('missingarticle-rev', array('escape'), $oldid) : ''; $this->mContent = wfMsgNoTrans('missing-article', $t, $d); if ($oldid) { $revision = Revision::newFromId($oldid); if (!$revision) { wfDebug(__METHOD__ . " failed to retrieve specified revision, id {$oldid}\n"); return false; } // Revision title doesn't match the page title given? if ($this->mPage->getID() != $revision->getPage()) { $function = array(get_class($this->mPage), 'newFromID'); $this->mPage = call_user_func($function, $revision->getPage()); if (!$this->mPage->getId()) { wfDebug(__METHOD__ . " failed to get page data linked to revision id {$oldid}\n"); return false; } } } else { if (!$this->mPage->getLatest()) { wfDebug(__METHOD__ . " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n"); return false; } $revision = $this->mPage->getRevision(); if (!$revision) { wfDebug(__METHOD__ . " failed to retrieve current page, rev_id " . $this->mPage->getLatest() . "\n"); return false; } } // @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks. // We should instead work with the Revision object when we need it... $this->mContent = $revision->getText(Revision::FOR_THIS_USER); // Loads if user is allowed $this->mRevIdFetched = $revision->getId(); $this->mContentLoaded = true; $this->mRevision =& $revision; wfRunHooks('ArticleAfterFetchContent', array(&$this, &$this->mContent)); return $this->mContent; }
/** * displayMenu - public */ function displayMenu() { print ' <table class="ServiceMenu"> <tr> <td>'; switch (DEFAULT_LANGUAGE) { case 'fr_FR': $attatch_page = "DéposerUnFichier"; $preferences_page = "PréférencesUtilisateurs"; break; case 'en_US': default: $attatch_page = 'UpLoad'; $preferences_page = 'UserPreferences'; break; } $attatch_menu = $GLOBALS['Language']->getText('wiki_views_wikiserviceviews', 'menuattch'); $preferences_menu = $GLOBALS['Language']->getText('wiki_views_wikiserviceviews', 'menuprefs'); $help_menu = $GLOBALS['Language']->getText('global', 'help'); print ' <ul class="ServiceMenu"> <li><a href="' . $this->wikiLink . '&view=browsePages">' . $GLOBALS['Language']->getText('wiki_views_wikiserviceviews', 'menupages') . '</a> | </li>'; if (UserManager::instance()->getCurrentUser()->isLoggedIn()) { print '<li><a href="javascript:help_window(\'' . $this->wikiLink . '&pagename=' . $attatch_page . '&pv=1\')">' . $attatch_menu . '</a> | </li>'; print '<li><a href="' . $this->wikiLink . '&pagename=' . $preferences_page . '">' . $preferences_menu . '</a> | </li>'; } if (user_ismember($this->gid, 'W2')) { print '<li><a href="' . $this->wikiAdminLink . '">' . $GLOBALS['Language']->getText('wiki_views_wikiserviceviews', 'menuadmin') . '</a> | </li>'; } print '<li>' . help_button('WikiService.html', false, $help_menu) . '</li> </ul>'; print ' </td> <td align="right" valign="top">'; if (user_ismember($this->gid, 'W2')) { $wiki = new Wiki($this->gid); $permInfo = ""; if ('wiki' == $this->view) { // User is browsing a wiki page $wp = new WikiPage($this->gid, $_REQUEST['pagename']); $permLink = $this->wikiAdminLink . '&view=pagePerms&id=' . $wp->getId(); if ($wp->permissionExist()) { $permInfo = '<a href="' . $permLink . '"> ' . '<img src="' . util_get_image_theme("ic/lock.png") . '" border="0" alt="' . $GLOBALS['Language']->getText('wiki_views_wikiserviceviews', 'lock_alt') . '" title="' . $GLOBALS['Language']->getText('wiki_views_wikiserviceviews', 'lock_title_spec') . '"/></a>'; } } if ($wiki->permissionExist()) { $permInfo .= '<a href="/wiki/admin/index.php?group_id=' . $this->gid . '&view=wikiPerms"> ' . '<img src="' . util_get_image_theme("ic/lock.png") . '" border="0" alt="' . $GLOBALS['Language']->getText('wiki_views_wikiserviceviews', 'lock_alt') . '" title="' . $GLOBALS['Language']->getText('wiki_views_wikiserviceviews', 'lock_title_set') . '"/>' . '</a>'; } if ($permInfo) { print $permInfo; } } //Display printer_version link only in wiki pages if (isset($_REQUEST['pagename'])) { print ' (<a href="' . $_SERVER['REQUEST_URI'] . '&pv=1" title="' . $GLOBALS['Language']->getText('wiki_views_wikiserviceviews', 'lighter_display') . '"> <img src="' . util_get_image_theme("msg.png") . '" border="0"> ' . $GLOBALS['Language']->getText('global', 'printer_version') . '</A> ) </li>'; } print ' </td> </tr> </table>'; }
/** * @todo FIXME: this is a better rollback test than the one below, but it * keeps failing in jenkins for some reason. */ public function broken_testDoRollback() { $admin = new User(); $admin->setName("Admin"); $text = "one"; $page = $this->newPage("WikiPageTest_testDoRollback"); $page->doEditContent(ContentHandler::makeContent($text, $page->getTitle()), "section one", EDIT_NEW, false, $admin); $user1 = new User(); $user1->setName("127.0.1.11"); $text .= "\n\ntwo"; $page = new WikiPage($page->getTitle()); $page->doEditContent(ContentHandler::makeContent($text, $page->getTitle()), "adding section two", 0, false, $user1); $user2 = new User(); $user2->setName("127.0.2.13"); $text .= "\n\nthree"; $page = new WikiPage($page->getTitle()); $page->doEditContent(ContentHandler::makeContent($text, $page->getTitle()), "adding section three", 0, false, $user2); # we are having issues with doRollback spuriously failing. Apparently # the last revision somehow goes missing or not committed under some # circumstances. So, make sure the last revision has the right user name. $dbr = wfGetDB(DB_SLAVE); $this->assertEquals(3, Revision::countByPageId($dbr, $page->getId())); $page = new WikiPage($page->getTitle()); $rev3 = $page->getRevision(); $this->assertEquals('127.0.2.13', $rev3->getUserText()); $rev2 = $rev3->getPrevious(); $this->assertEquals('127.0.1.11', $rev2->getUserText()); $rev1 = $rev2->getPrevious(); $this->assertEquals('Admin', $rev1->getUserText()); # now, try the actual rollback $admin->addGroup("sysop"); #XXX: make the test user a sysop... $token = $admin->getEditToken(array($page->getTitle()->getPrefixedText(), $user2->getName()), null); $errors = $page->doRollback($user2->getName(), "testing revert", $token, false, $details, $admin); if ($errors) { $this->fail("Rollback failed:\n" . print_r($errors, true) . ";\n" . print_r($details, true)); } $page = new WikiPage($page->getTitle()); $this->assertEquals($rev2->getSha1(), $page->getRevision()->getSha1(), "rollback did not revert to the correct revision"); $this->assertEquals("one\n\ntwo", $page->getContent()->getNativeData()); }
/** * Submit the form parameters for the page config to the DB. * * @return mixed (true on success, error string on failure) */ public function doSubmit() { # Double-check permissions if (!$this->isAllowed()) { return 'review_denied'; } # We can only approve actual revisions... if ($this->getAction() === 'approve') { $rev = Revision::newFromTitle($this->page, $this->oldid); # Check for archived/deleted revisions... if (!$rev || $rev->getVisibility()) { return 'review_bad_oldid'; } # Check for review conflicts... if ($this->lastChangeTime !== null) { // API uses null $lastChange = $this->oldFrev ? $this->oldFrev->getTimestamp() : ''; if ($lastChange !== $this->lastChangeTime) { return 'review_conflict_oldid'; } } $status = $this->approveRevision($rev, $this->oldFrev); # We can only unapprove approved revisions... } elseif ($this->getAction() === 'unapprove') { # Check for review conflicts... if ($this->lastChangeTime !== null) { // API uses null $lastChange = $this->oldFrev ? $this->oldFrev->getTimestamp() : ''; if ($lastChange !== $this->lastChangeTime) { return 'review_conflict_oldid'; } } # Check if we can find this flagged rev... if (!$this->oldFrev) { return 'review_not_flagged'; } $status = $this->unapproveRevision($this->oldFrev); } elseif ($this->getAction() === 'reject') { $newRev = Revision::newFromTitle($this->page, $this->oldid); $oldRev = Revision::newFromTitle($this->page, $this->refid); # Do not mess with archived/deleted revisions if (!$oldRev || $oldRev->isDeleted(Revision::DELETED_TEXT)) { return 'review_bad_oldid'; } elseif (!$newRev || $newRev->isDeleted(Revision::DELETED_TEXT)) { return 'review_bad_oldid'; } # Check that the revs are in order if ($oldRev->getTimestamp() > $newRev->getTimestamp()) { return 'review_cannot_undo'; } # Make sure we are only rejecting pending changes $srev = FlaggedRevision::newFromStable($this->page, FR_MASTER); if ($srev && $oldRev->getTimestamp() < $srev->getRevTimestamp()) { return 'review_cannot_reject'; // not really a use case } $article = new WikiPage($this->page); # Get text with changes after $oldRev up to and including $newRev removed $new_text = $article->getUndoText($newRev, $oldRev); if ($new_text === false) { return 'review_cannot_undo'; } $baseRevId = $newRev->isCurrent() ? $oldRev->getId() : 0; # Actually make the edit... $editStatus = $article->doEdit($new_text, $this->getComment(), 0, $baseRevId, $this->user); $status = $editStatus->isOK() ? true : 'review_cannot_undo'; if ($editStatus->isOK() && class_exists('EchoEvent') && $editStatus->value['revision']) { $affectedRevisions = array(); // revid -> userid $revisions = wfGetDB(DB_SLAVE)->select('revision', array('rev_id', 'rev_user'), array('rev_id <= ' . $newRev->getId(), 'rev_timestamp <= ' . $newRev->getTimestamp(), 'rev_id > ' . $oldRev->getId(), 'rev_timestamp > ' . $oldRev->getTimestamp(), 'rev_page' => $article->getId()), __METHOD__); foreach ($revisions as $row) { $affectedRevisions[$row->rev_id] = $row->rev_user; } EchoEvent::create(array('type' => 'reverted', 'title' => $this->page, 'extra' => array('revid' => $editStatus->value['revision']->getId(), 'reverted-users-ids' => array_values($affectedRevisions), 'reverted-revision-ids' => array_keys($affectedRevisions), 'method' => 'flaggedrevs-reject'), 'agent' => $this->user)); } # If this undid one edit by another logged-in user, update user tallies if ($status === true && $newRev->getParentId() == $oldRev->getId() && $newRev->getRawUser()) { if ($newRev->getRawUser() != $this->user->getId()) { // no self-reverts FRUserCounters::incCount($newRev->getRawUser(), 'revertedEdits'); } } } # Watch page if set to do so if ($status === true) { if ($this->user->getOption('flaggedrevswatch') && !$this->page->userIsWatching()) { $this->user->addWatch($this->page); } } return $status; }
/** * @param WikiPage $article * @return mixed|string */ protected function getOptionsKey($article) { $pageid = $article->getId(); return wfMemcKey('pcache', 'idoptions', "{$pageid}"); }
/** * pagePerms - public View */ function _pagePerms($postUrl = '') { $wp = new WikiPage($_REQUEST['id']); $pagename = $wp->getPagename(); $eM =& EventManager::instance(); $referenced = false; $eM->processEvent('isWikiPageReferenced', array('referenced' => &$referenced, 'wiki_page' => $pagename, 'group_id' => $this->gid)); if ($referenced) { $label = ''; $eM->processEvent('getPermsLabelForWiki', array('label' => &$label)); print '<p align="center"><br><b>' . $label . '</b></p>'; } else { print $GLOBALS['Language']->getText('wiki_views_wikiviews', 'set_perm_title'); if (empty($pagename)) { print $GLOBALS['Language']->getText('wiki_views_wikiviews', 'empty_page'); } else { print $GLOBALS['Language']->getText('wiki_views_wikiviews', 'not_empty_page', array($pagename)); permission_display_selection_form("WIKIPAGE_READ", $wp->getId(), $this->gid, $postUrl); } } }
/** * @param WikiPage $wikiPage * @param User $user * @param string $text * @param string $summary * @param $minoredit * @param $watchthis * @param $sectionanchor * @param $flags * @param $revision * @param $status * @param $baseRevId * @return bool */ public static function onArticleSaveComplete(WikiPage $wikiPage, User $user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId) { ArticlesApiController::purgeCache($wikiPage->getTitle()->getArticleID()); ArticlesApiController::purgeMethods([['getAsJson', ['id' => $wikiPage->getId()]], ['getAsJson', ['title' => $wikiPage->getTitle()->getPartialURL()]]]); return true; }
/** * @return RecentChange */ private function getCategorizationChange($timestamp, $thisId, $lastId) { $wikiPage = new WikiPage(Title::newFromText('Testpage')); $wikiPage->doEditContent(new WikitextContent('Some random text'), 'page created'); $wikiPage = new WikiPage(Title::newFromText('Category:Foo')); $wikiPage->doEditContent(new WikitextContent('Some random text'), 'category page created'); $user = $this->getTestUser(); $recentChange = $this->testRecentChangesHelper->makeCategorizationRecentChange($user, 'Category:Foo', $wikiPage->getId(), $thisId, $lastId, $timestamp); return $recentChange; }
/** * Clear the cache when the page is edited */ public static function onArticleSaveComplete(WikiPage &$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId) { /** * @var $service ArticleService */ $service = F::build('ArticleService', array($article->getId())); if (!is_null($service->mArticle)) { F::app()->wg->Memc->delete($service->getMemcKey()); } return true; }
/** * * @param WikiPage $wiki_page */ public function updatePermissions(WikiPage $wiki_page) { $this->logger->debug('[Wiki] ElasticSearch: update permissions of wiki page ' . $wiki_page->getPagename() . ' #' . $wiki_page->getId()); $update_data = array(); $this->request_data_factory->setUpdatedData($update_data, 'permissions', $this->request_data_factory->getCurrentPermissions($wiki_page)); $this->indexOrUpdate($wiki_page->getGid(), $wiki_page->getId(), $update_data); }
/** * Clear the cache when the page is edited */ public static function onArticleSaveComplete(WikiPage &$page, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId) { /** * @var $service ArticleService */ if ($page->exists()) { $id = $page->getId(); F::app()->wg->Memc->delete(self::getCacheKey($id)); if (array_key_exists($id, self::$localCache)) { unset(self::$localCache[$id]); } } return true; }
public function getIndexedWikiPageData(WikiPage $wiki_page) { $wiki_page_metadata = $wiki_page->getMetadata(); return array('id' => $wiki_page->getId(), 'group_id' => $wiki_page->getGid(), 'page_name' => $wiki_page->getPagename(), 'last_modified_date' => date('c', $wiki_page_metadata[self::PHPWIKI_METADATA_LAST_MODIFIED_DATE]), 'last_author' => $wiki_page_metadata[self::PHPWIKI_METADATA_AUTHOR_ID], 'last_summary' => isset($wiki_page_metadata[self::PHPWIKI_METADATA_SUMMARY]) ? $wiki_page_metadata[self::PHPWIKI_METADATA_SUMMARY] : '', 'content' => isset($wiki_page_metadata[self::PHPWIKI_METADATA_CONTENT]) ? $wiki_page_metadata[self::PHPWIKI_METADATA_CONTENT] : '', 'permissions' => $this->getCurrentPermissions($wiki_page)); }
/** * @param WikiPage $article * @return array */ static function getLinksFromDB($article) { // Stolen from ConfirmEdit $id = $article->getId(); if (!$id) { return array(); } $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('externallinks', array('el_to'), array('el_from' => $id), __METHOD__); $links = array(); foreach ($res as $row) { $links[] = $row->el_to; } return $links; }
/** * browsePages - private */ function _browsePages(&$pageList) { print html_build_list_table_top(array('Page', 'Permissions')); $purifier = Codendi_HTMLPurifier::instance(); sort($pageList); $i = 0; foreach ($pageList as $pagename) { print ' <tr class="' . html_get_alt_row_color($i) . '"> '; print '<td><a href="' . $this->wikiLink . '&pagename=' . urlencode($pagename) . '">' . $purifier->purify($pagename) . '</a></td>'; $page = new WikiPage($this->gid, $pagename); $status = $GLOBALS['Language']->getText('wiki_views_wkserviews', 'define_perms'); if (permission_exist('WIKIPAGE_READ', $page->getId())) { $status = $GLOBALS['Language']->getText('wiki_views_wkserviews', 'edit_perms'); } $eM =& EventManager::instance(); $referenced = false; $eM->processEvent('isWikiPageReferenced', array('referenced' => &$referenced, 'wiki_page' => $pagename, 'group_id' => $this->gid)); print '<td align="center">'; if ($referenced) { $label = ''; $eM->processEvent('getPermsLabelForWiki', array('label' => &$label)); print $purifier->purify($label); } else { print '<a href="' . $this->wikiAdminLink . '&view=pagePerms&id=' . urlencode($page->getId()) . '">[' . $purifier->purify($status) . ']</a>'; } print '</td>'; print ' </tr> '; $i++; } print '</TABLE>'; }
/** * Handles wiki page deletion with two different behaviors: * 1- User decides to keep wiki page in wiki service. In this case, we restrict access to that wiki page to wiki admins only. * 2- User decides to cascade deletion of the wiki page to wiki service too. In that case, we completely remove the wiki page from wiki service. * * @param Docman_Item $item * @param array $params params. * * @return boolean $deleted. True if there is no error. False otherwise. */ public function visitWiki(&$item, $params = array()) { // delete the document. $deleted = $this->visitDocument($item, $params); if ($deleted) { if (!$params['cascadeWikiPageDeletion']) { // grant a wiki permission only to wiki admins on the corresponding wiki page. $this->restrictAccess($item, $params); $wiki_page = new WikiPage($item->getGroupId(), $item->getPageName()); if ($wiki_page->getId()) { $event_manager = EventManager::instance(); $event_manager->processEvent("wiki_page_updated", array('group_id' => $item->getGroupId(), 'wiki_page' => $item->getPageName(), 'referenced' => false, 'user' => $params['user'])); } } else { // User have choosen to delete wiki page from wiki service too $dIF =& $this->_getItemFactory(); if ($dIF->deleteWikiPage($item->getPageName(), $item->getGroupId())) { $this->response->addFeedback('info', $GLOBALS['Language']->getText('plugin_docman', 'docman_wiki_delete_wiki_page_success')); } else { $this->response->addFeedback('error', $GLOBALS['Language']->getText('plugin_docman', 'docman_wiki_delete_wiki_page_failed')); } } } return $deleted; }
public function getAsJobSpecification() { return array('wiki' => $this->mDb->getWikiID(), 'job' => new JobSpecification('deleteLinks', array('pageId' => $this->page->getId()), array('removeDuplicates' => true), $this->page->getTitle())); }
/** * @param WikiPage $page * @return mixed|string */ protected function getOptionsKey($page) { return wfMemcKey('pcache', 'idoptions', $page->getId()); }
/** * Performs a page parse * @param WikiPage $wp * @param ParserOptions $parserOptions * @return ParserOutput */ protected function getParserOutput(WikiPage $wp, ParserOptions $parserOptions) { $time = microtime(true); $parserOutput = $wp->getParserOutput($parserOptions); $time = microtime(true) - $time; if (!$parserOutput) { wfDebugLog('mobile', "Empty parser output on '{$wp->getTitle()->getPrefixedText()}'" . ": rev {$wp->getId()}, time {$time}"); throw new Exception(__METHOD__ . ": PoolCounter didn't return parser output"); } $parserOutput->setTOCEnabled(false); return $parserOutput; }
/** * HomePage was not found so first-time install is supposed to run. * - import all pgsrc pages. * - Todo: installer interface to edit config/config.ini settings * - Todo: ask for existing old index.php to convert to config/config.ini * - Todo: theme-specific pages: * blog - HomePage, ADMIN_USER/Blogs */ function SetupWiki(&$request) { global $GenericPages, $LANG; //FIXME: This is a hack (err, "interim solution") // This is a bogo-bogo-login: Login without // saving login information in session state. // This avoids logging in the unsuspecting // visitor as "The PhpWiki programming team". // // This really needs to be cleaned up... // (I'm working on it.) $real_user = $request->_user; if (ENABLE_USER_NEW) { $request->_user = new _BogoUser(_("The PhpWiki programming team")); } else { $request->_user = new WikiUser($request, _("The PhpWiki programming team"), WIKIAUTH_BOGO); } // Get the localised wiki loading message $message = _("Loading up virgin wiki. Please wait until the end of the process, this will take few minutes."); StartLoadDump($request, $message); echo "<dl>\n"; $pgsrc = FindLocalizedFile(WIKI_PGSRC); $default_pgsrc = FindFile(DEFAULT_WIKI_PGSRC); $request->setArg('overwrite', true); if ($default_pgsrc != $pgsrc) { LoadAny($request, $default_pgsrc, $GenericPages); } // Codendi - Commented-out the following line to make sure that wiki pages are properly instanciated // If the line is not commented, we randomly run into error messages like this at wiki init: // "...pagename has edit conflicts - skipped (Merge Edit ) (Restore Anyway)" //$request->setArg('overwrite', false); LoadAny($request, $pgsrc); $dbi =& $request->_dbi; // Ensure that all mandatory pages are loaded $finder = new FileFinder(); foreach (array_merge(explode(':', 'OldTextFormattingRules:TextFormattingRules:PhpWikiAdministration'), $GLOBALS['AllActionPages'], array(constant('HOME_PAGE'))) as $f) { $page = gettext($f); $epage = urlencode($page); if (!$dbi->isWikiPage($page)) { // translated version provided? if ($lf = FindLocalizedFile($pgsrc . $finder->_pathsep . $epage, 1)) { LoadAny($request, $lf); } else { // load english version of required action page LoadAny($request, FindFile(DEFAULT_WIKI_PGSRC . $finder->_pathsep . urlencode($f))); $page = $f; } } if (!$dbi->isWikiPage($page)) { trigger_error(sprintf("Mandatory file %s couldn't be loaded!", $page), E_USER_WARNING); } //WARNING CODENDI CODE : give permissions to the administration pages of the wiki $pages = array("AdministrationDePhpWiki", "AdministrationDePhpWiki/Supprimer", "AdministrationDePhpWiki/Remplacer", "AdministrationDePhpWiki/Renommer", "PhpWikiAdministration", "PhpWikiAdministration/Replace", "PhpWikiAdministration/Remove", "PhpWikiAdministration/Rename"); if (in_array($page, $pages)) { $group_id = $request->getArg('group_id'); $wikiPage = new WikiPage($group_id, $page); $id = $wikiPage->getId(); $pm = PermissionsManager::instance(); $pm->addPermission('WIKIPAGE_READ', $id, $GLOBALS['UGROUP_PROJECT_ADMIN']); $pm->addPermission('WIKIPAGE_READ', $id, $GLOBALS['UGROUP_WIKI_ADMIN']); } //END WARNING } echo "</dl>\n"; EndLoadDump($request); }
/** * This method is called after an article has been saved. * This is the server side of IntraACL protection toolbar, * allowing to modify page SD together with article save. * * No modifications are made if either: * - Page namespace is ACL * - User is anonymous * - Users don't have the right to modify page SD * - 'haloacl_protect_with' request value is invalid * (valid are 'unprotected', or ID/name of predefined right or THIS page SD) * * @param WikiPage $article The article which was saved * @param User $user The user who saved the article * @param string $text The content of the article * * @return true */ public static function articleSaveComplete_SaveSD($article, User $user, $text) { global $wgUser, $wgRequest, $haclgContLang; if ($user->isAnon()) { // Don't handle protection toolbar for anonymous users return true; } if ($article->getTitle()->getNamespace() == HACL_NS_ACL) { // Don't use protection toolbar for articles in the namespace ACL. // Note that embedded content protection toolbar is handled nevertheless. return true; } // Obtain user selection // hacl_protected_with == '<peType>:<peID>' or 'unprotected' $selectedSD = $wgRequest->getVal('hacl_protected_with'); if ($selectedSD && $selectedSD != 'unprotected') { // Some SD is selected by the user // Ignore selection of invalid SDs $selectedSD = array_map('intval', explode('-', $selectedSD, 2)); if (count($selectedSD) != 2) { $selectedSD = NULL; } } if (!$selectedSD) { return true; } if ($selectedSD == 'unprotected') { $selectedSD = NULL; } // Check if current SD must be modified if ($article->exists()) { $pageSD = IACLDefinition::getSDForPE(IACL::PE_PAGE, $article->getId()); if ($pageSD && $selectedSD) { // Check if page's SD ID passed as selected if ($pageSD['pe_type'] == $selectedSD[0] && $pageSD['pe_id'] == $selectedSD[1]) { return true; } // Check if page's SD is single inclusion and it is passed as selected if ($pageSD['single_child'] == $selectedSD) { return true; } } } // Check if no protection selected and no protection exists if (!$selectedSD && !$pageSD) { return true; } // Check if other SD is a predefined right // FIXME Allow selecting non-PE_RIGHTs in quick acl toolbar? if ($selectedSD && $selectedSD[0] != IACL::PE_RIGHT) { return true; } // Check SD modification rights $pageSDName = IACLDefinition::nameOfSD(IACL::PE_PAGE, $article->getTitle()); $etc = haclfDisableTitlePatch(); $pageSDTitle = Title::newFromText($pageSDName); haclfRestoreTitlePatch($etc); if (!$pageSDTitle->userCan('edit')) { return true; } $newSDArticle = new WikiPage($pageSDTitle); if ($selectedSD) { // Create/modify page SD $selectedSDTitle = IACLDefinition::getSDTitle($selectedSD); $content = '{{#predefined right: ' . $selectedSDTitle->getText() . "}}\n" . '{{#manage rights: assigned to = User:'******'hacl_comment_protect_with', $selectedSDTitle->getFullText())); } else { // Remove page SD $newSDArticle->doDeleteArticle(wfMsg('hacl_comment_unprotect')); } // Continue hook processing return true; }
/** * Called when creating a new article, but after onArticleSave * @param WikiPage $wikipage the Article or WikiPage (object) saved. Article for MW < 1.18, WikiPage for MW >= 1.18 * @param User $user the user (object) who saved the article * @param type $text the new article content * @param type $summary the article summary (comment) * @param type $isMinor minor edit flag * @param type $isWatch watch the page if true, unwatch the page if false, do nothing if null (since 1.17.0) * @param type $section not used as of 1.8 (automatically set to "null") * @param type $flags bitfield, see source code for details; passed to Article::doedit() * @param type $revision The newly inserted revision object (as of 1.11.0) * @return boolean true to continue hook processing or false to abort */ public static function onArticleInsertComplete($wikipage, $user, $text, $summary, $isMinor, $isWatch, $section, $flags, $revision) { $title = $wikipage->getTitle(); $namespace = $title->getNamespace(); $db_key = $title->getDBkey(); if (!WpPage::isInWikiplace($namespace, $db_key)) { return true; // skip } $article_id = $wikipage->getId(); $user_id = $user->getId(); $wikiplace = null; $pdb_key = $title->getPrefixedDBkey(); // only used by log messages // currently, the page is already stored in 'page' db table if (WpPage::isHomepage($title)) { // create a wikiplace from this homepage $wikiplace = self::doCreateWikiplace($user_id, $article_id); if ($wikiplace === null) { wfDebugLog('wikiplaces', 'onArticleInsertComplete(): ERROR while creating wikiplace "' . $pdb_key . '" for user[' . $user_id . ']'); // throw new MWException('Error while creating wikiplace.'); return true; } } else { // this is a subpage, searching existing container wikiplace $wikiplace = WpWikiplace::getBySubpage($db_key, $namespace); if ($wikiplace === null) { wfDebugLog('wikiplaces', 'onArticleInsertComplete(): ERROR cannot identify container wikiplace "' . $pdb_key . '" for user[' . $user_id . ']'); // throw new MWException('Cannot identify the container wikiplace.'); return true; } } $new_wp_page = WpPage::create($article_id, $wikiplace->getId()); if ($new_wp_page === null) { wfDebugLog('wikiplaces', 'onArticleInsertComplete(): ERROR while associating new page to its container wikiplace "' . $pdb_key . '" for user[' . $user_id . ']'); // throw new MWException('Error while associating new page to its container wikiplace.'); return true; } if (in_array($namespace, array(NS_MAIN, NS_FILE, NS_WIKIPLACE))) { // restrict applicable actions to owner, except for read $actions_to_rectrict = array_diff($title->getRestrictionTypes(), array('read')); $restrictions = array(); foreach ($actions_to_rectrict as $action) { $restrictions[$action] = WP_DEFAULT_RESTRICTION_LEVEL; } $ok = false; wfRunHooks('POSetProtection', array($wikipage, $restrictions, &$ok)); if (!$ok) { wfDebugLog('wikiplaces', 'onArticleInsertComplete(): WARNING Wikiplace proccess OK but ERROR while setting default restrictions to new page, article=[' . $article_id . ']"' . $pdb_key . '" for user[' . $user_id . ']'); } else { wfDebugLog('wikiplaces-debug', 'onArticleInsertComplete(): OK, article=[' . $article_id . ']"' . $pdb_key . '" for user[' . $user_id . ']'); } } else { wfDebugLog('wikiplaces-debug', 'onArticleInsertComplete(): OK, no default restrictions to set, article=[' . $article_id . ']"' . $pdb_key . '" for user[' . $user_id . ']'); } return true; }