The followings are the available columns in table 'wiki_page':
Inheritance: extends CActiveRecord
/**
 * @param WikiPage $article
 * @param $user
 * @param $text
 * @param $summary
 * @param $minoredit
 * @param $watchthis
 * @param $sectionanchor
 * @param $flags
 * @param $revision
 * @param Status $status
 * @param $baseRevId
 * @return bool
 */
function efSharedHelpArticleCreation(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId)
{
    global $wgCityId, $wgHelpWikiId;
    // only run on help wikis
    if ($wgCityId !== $wgHelpWikiId) {
        return true;
    }
    // not likely if we got here, but... healthy paranoia ;)
    if (wfReadOnly()) {
        return true;
    }
    if ($article->mTitle->getNamespace() !== NS_HELP) {
        return true;
    }
    if (!$status->isOK()) {
        return true;
    }
    if (!($flags & EDIT_NEW)) {
        return true;
    }
    $talkTitle = Title::newFromText($article->mTitle->getText(), NS_HELP_TALK);
    if ($talkTitle->exists()) {
        return true;
    }
    $talkArticle = new Article($talkTitle);
    $redir = $article->getRedirectTarget();
    if ($redir) {
        $target = $redir->getTalkNsText() . ':' . $redir->getText();
        $talkArticle->doEdit("#REDIRECT [[{$target}]]", wfMsgForContent('sharedhelp-autotalkcreate-summary'));
    } else {
        $talkArticle->doEdit('{{talkheader}}', wfMsgForContent('sharedhelp-autotalkcreate-summary'));
    }
    return true;
}
 /**
  * @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;
 }
 function execute()
 {
     global $wgParser;
     $wgParser->parse(' ', Title::newMainPage(), new ParserOptions());
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('page', '*', array('page_namespace' => HACL_NS_ACL), __METHOD__);
     $titles = array();
     foreach ($res as $row) {
         $titles[] = Title::newFromRow($row);
     }
     $quiet = $this->hasOption('quiet');
     $seen = array();
     foreach ($titles as $title) {
         $page = new WikiPage($title);
         $pf = IACLParserFunctions::instance($title);
         IACLParserFunctions::parse($page->getText(), $title);
         $errors = $pf->consistencyCheckStatus(false);
         $errors = array_merge($errors, $pf->errors);
         if ($pf->def) {
             if (isset($seen[$pf->def['key']])) {
                 $errors[] = "Duplicate definition! Previous one is " . $seen[$pf->def['key']];
             }
             $seen[$pf->def['key']] = "{$title}";
         }
         IACLParserFunctions::destroyInstance($pf);
         if ($errors) {
             print "Errors on {$title}:\n";
             foreach ($errors as $e) {
                 print "\t{$e}\n";
             }
         } elseif (!$quiet) {
             print "OK {$title}\n";
         }
     }
 }
示例#4
0
function create_wiki($gid = false, $wikiName = 'New wiki')
{
    $creatorId = claro_get_current_user_id();
    $tblList = claro_sql_get_course_tbl();
    $config = array();
    $config["tbl_wiki_properties"] = $tblList["wiki_properties"];
    $config["tbl_wiki_pages"] = $tblList["wiki_pages"];
    $config["tbl_wiki_pages_content"] = $tblList["wiki_pages_content"];
    $config["tbl_wiki_acls"] = $tblList["wiki_acls"];
    $con = Claroline::getDatabase();
    $acl = array();
    if ($gid) {
        $acl = WikiAccessControl::defaultGroupWikiACL();
    } else {
        $acl = WikiAccessControl::defaultCourseWikiACL();
    }
    $wiki = new Wiki($con, $config);
    $wiki->setTitle($wikiName);
    $wiki->setDescription('This is a sample wiki');
    $wiki->setACL($acl);
    $wiki->setGroupId($gid);
    $wikiId = $wiki->save();
    $wikiTitle = $wiki->getTitle();
    $mainPageContent = sprintf("This is the main page of the Wiki %s. Click on edit to modify the content.", $wikiTitle);
    $wikiPage = new WikiPage($con, $config, $wikiId);
    $wikiPage->create($creatorId, '__MainPage__', $mainPageContent, date("Y-m-d H:i:s"), true);
}
 private function getTransformedContent(WikiPage $wiki_page, WikiPageVersion $version, WikiRequest $request)
 {
     $dbi = $request->_dbi;
     $page_db = $dbi->getPage($wiki_page->getPagename());
     $revision = $page_db->getRevision($version->getVersionId());
     return $revision->getTransformedContent();
 }
示例#6
0
 /**
  * Export a whole Wiki to a single HTML String
  * @return  string Wiki content in HTML
  */
 public function export()
 {
     $pageList = $this->wiki->allPagesByCreationDate();
     $result = $this->_htmlHeader();
     $result .= '<h1>' . $this->wiki->getTitle() . '</h1>' . "\n";
     foreach ($pageList as $page) {
         $wikiPage = new WikiPage($this->wiki->getDatabaseConnection(), $this->wiki->getConfig(), $this->wiki->getWikiId());
         $wikiPage->loadPage($page['title']);
         $this->setOpt('note_prefix', $page['title']);
         if ($wikiPage->hasError()) {
             $result .= '<h2><a name="' . $this->_makePageTitleAnchor($page['title']) . '">' . $page['title'] . '</a></h2>' . "\n";
             $result .= get_lang("Could not load page %page", array('%page' => $page['title'])) . "\n";
             $wikiPage = null;
         } else {
             $pgTitle = $wikiPage->getTitle();
             if ('__MainPage__' === $pgTitle) {
                 $pgTitle = get_lang('Main page');
             }
             $result .= '<h2><a name="' . $this->_makePageTitleAnchor($page['title']) . '">' . $pgTitle . '</a></h2>' . "\n";
             $content = $wikiPage->getContent();
             $result .= $this->render($content) . "\n";
             $wikiPage = null;
         }
     }
     $result .= $this->_htmlFooter();
     return $result;
 }
示例#7
0
function do_sitemap($formatter, $options)
{
    global $DBInfo;
    # get page list
    if ($formater->group) {
        $group_pages = $DBInfo->getLikePages($formater->group);
        foreach ($group_pages as $page) {
            $all_pages[] = str_replace($formatter->group, '', $page);
        }
    } else {
        $all_pages = $DBInfo->getPageLists();
    }
    usort($all_pages, 'strcasecmp');
    $items = '';
    // empty string
    # process page list
    $zone = '+00:00';
    foreach ($all_pages as $page) {
        $url = qualifiedUrl($formatter->link_url(_rawurlencode($page)));
        $p = new WikiPage($page);
        $t = $p->mtime();
        $date = gmdate("Y-m-d\\TH:i:s", $t) . $zone;
        // W3C datetime format
        $item = "<url>\n";
        $item .= "  <loc>" . $url . "</loc>\n";
        $item .= "  <lastmod>" . $date . "</lastmod>\n";
        $item .= "</url>\n";
        $items .= $item;
    }
    # process output
    $out = $items;
    if ($options['oe'] and strtolower($options['oe']) != $DBInfo->charset) {
        $charset = $options['oe'];
        if (function_exists('iconv')) {
            $new = iconv($DBInfo->charset, $charset, $items);
            if (!$new) {
                $charset = $DBInfo->charset;
            }
            if ($new) {
                $out = $new;
            }
        }
    } else {
        $charset = $DBInfo->charset;
    }
    $head = <<<HEAD
<?xml version="1.0" encoding="{$charset}"?>
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9"
         url="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
         xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

HEAD;
    $foot = <<<FOOT
</urlset>
FOOT;
    # output
    header("Content-Type: text/xml");
    print $head . $out . $foot;
}
 /**
  * Assuming the user's interface language is fi. Given input Page, it
  * returns Page/fi if it exists, otherwise Page. Given input Page/de,
  * it returns Page/fi if it exists, otherwise Page/de if it exists,
  * otherwise Page.
  *
  * @param string $par
  * @return Title|null
  */
 public function findTitle($par)
 {
     // base = title without language code suffix
     // provided = the title as it was given
     $base = $provided = Title::newFromText($par);
     if ($base && strpos($par, '/') !== false) {
         $pos = strrpos($par, '/');
         $basepage = substr($par, 0, $pos);
         $code = substr($par, $pos + 1);
         if (strlen($code) && Language::isKnownLanguageTag($code)) {
             $base = Title::newFromText($basepage);
         }
     }
     if (!$base) {
         return null;
     }
     if ($base->isRedirect()) {
         $page = new WikiPage($base);
         $base = $page->getRedirectTarget();
     }
     $uiCode = $this->getLanguage()->getCode();
     $proposed = $base->getSubpage($uiCode);
     if ($uiCode !== $this->getConfig()->get('LanguageCode') && $proposed && $proposed->exists()) {
         return $proposed;
     } elseif ($provided && $provided->exists()) {
         return $provided;
     } else {
         return $base;
     }
 }
 public function getDefinitions()
 {
     $groups = MessageGroups::getAllGroups();
     $keys = array();
     /**
      * @var $g MessageGroup
      */
     foreach ($groups as $g) {
         $states = $g->getMessageGroupStates()->getStates();
         foreach (array_keys($states) as $state) {
             $keys["Translate-workflow-state-{$state}"] = $state;
         }
     }
     $defs = TranslateUtils::getContents(array_keys($keys), $this->getNamespace());
     foreach ($keys as $key => $state) {
         if (!isset($defs[$key])) {
             // @todo Use jobqueue
             $title = Title::makeTitleSafe($this->getNamespace(), $key);
             $page = new WikiPage($title);
             $content = ContentHandler::makeContent($state, $title);
             $page->doEditContent($content, wfMessage('translate-workflow-autocreated-summary', $state)->inContentLanguage()->text(), 0, false, FuzzyBot::getUser());
         } else {
             // Use the wiki translation as definition if available.
             // getContents returns array( content, last author )
             list($content, ) = $defs[$key];
             $keys[$key] = $content;
         }
     }
     return $keys;
 }
 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);
 }
 /**
  * @covers WikiPage::getContentHandler
  */
 public function testGetContentHandler()
 {
     $page = $this->createPage("WikiPageTest_testGetContentHandler", "some text", CONTENT_MODEL_JAVASCRIPT);
     // NOTE: since the content model is not recorded in the database,
     //       we expect to get the default, namely CONTENT_MODEL_WIKITEXT
     $page = new WikiPage($page->getTitle());
     $this->assertEquals('WikitextContentHandler', get_class($page->getContentHandler()));
 }
 protected function SaveWikiVersion()
 {
     $objWikiPage = new WikiPage();
     $objWikiPage->Content = trim($this->txtContent->Text);
     $objWikiPage->CompileHtml();
     $objWikiVersion = $this->objWikiItem->CreateNewVersion(trim($this->txtTitle->Text), $objWikiPage, 'Save', array(), QApplication::$Person, null);
     return $objWikiVersion;
 }
 public function saveWikiPage(WikiPage $wikiPage)
 {
     $wikiPagePath = $wikiPage->getPath();
     $wikiPageFilename = $this->getWikiPageFilename($wikiPagePath);
     $wikiPageSource = $wikiPage->getSource();
     $this->saveWikiPageSource($wikiPageFilename, $wikiPageSource);
     return $wikiPage;
 }
 /**
  * Protects a message entry in the PRAd namespace.
  * The protection lasts for infinity and acts for group
  * @ref $wgPromoterProtectGroup
  *
  * This really is intended only for use on the original source language
  * because those messages are set via the PR UI; not the translate UI.
  *
  * @param WikiPage $page Page containing the message to protect
  * @param User     $user User doing the protection (ie: the last one to edit the page)
  */
 protected function protectMessageInPrNamespaces($page, $user)
 {
     global $wgPromoterProtectGroup;
     if (!$page->getTitle()->getRestrictions('edit')) {
         $var = false;
         $page->doUpdateRestrictions(array('edit' => $wgPromoterProtectGroup, 'move' => $wgPromoterProtectGroup), array('edit' => 'infinity', 'move' => 'infinity'), $var, 'Auto protected by Promoter -- Only edit via Special:Promoter.', $user);
     }
 }
 /**
  * Constructor
  *
  * @param WikiPage $page Page we are updating
  * @throws MWException
  */
 function __construct(WikiPage $page)
 {
     parent::__construct(false);
     // no implicit transaction
     $this->mPage = $page;
     if (!$page->exists()) {
         throw new MWException("Page ID not known, perhaps the page doesn't exist?");
     }
 }
示例#16
0
function RemovePage(&$request)
{
    global $WikiTheme;
    $page = $request->getPage();
    $pagelink = WikiLink($page);
    if ($request->getArg('cancel')) {
        $request->redirect(WikiURL($page));
        // noreturn
    }
    $current = $page->getCurrentRevision();
    if (!$current or !($version = $current->getVersion())) {
        $html = HTML(HTML::h2(_("Already deleted")), HTML::p(_("Sorry, this page is not in the database.")));
    } elseif (!$request->isPost() || !$request->getArg('verify')) {
        $removeB = Button('submit:verify', _("Remove Page"), 'wikiadmin');
        $cancelB = Button('submit:cancel', _("Cancel"), 'button');
        // use generic wiki button look
        $html = HTML(HTML::h2(fmt("You are about to remove '%s'!", $pagelink)), HTML::form(array('method' => 'post', 'action' => $request->getPostURL()), HiddenInputs(array('currentversion' => $version, 'pagename' => $page->getName(), 'action' => 'remove')), HTML::div(array('class' => 'toolbar'), $removeB, $WikiTheme->getButtonSeparator(), $cancelB)), HTML::hr());
        $sample = HTML::div(array('class' => 'transclusion'));
        // simple and fast preview expanding only newlines
        foreach (explode("\n", firstNWordsOfContent(100, $current->getPackedContent())) as $s) {
            $sample->pushContent($s, HTML::br());
        }
        $html->pushContent(HTML::div(array('class' => 'wikitext'), $sample));
    } elseif ($request->getArg('currentversion') != $version) {
        $html = HTML(HTML::h2(_("Someone has edited the page!")), HTML::p(fmt("Since you started the deletion process, someone has saved a new version of %s.  Please check to make sure you still want to permanently remove the page from the database.", $pagelink)));
    } else {
        // Codendi specific: remove the deleted wiki page from ProjectWantedPages
        $projectPageName = 'ProjectWantedPages';
        $pagename = $page->getName();
        $dbi = $request->getDbh();
        require_once PHPWIKI_DIR . "/lib/loadsave.php";
        $pagehandle = $dbi->getPage($projectPageName);
        if ($pagehandle->exists()) {
            // don't replace default contents
            $current = $pagehandle->getCurrentRevision();
            $version = $current->getVersion();
            $text = $current->getPackedContent();
            $meta = $current->_data;
        }
        $text = str_replace("* [{$pagename}]", "", $text);
        $meta['summary'] = $GLOBALS['Language']->getText('wiki_lib_wikipagewrap', 'page_added', array($pagename));
        $meta['author'] = user_getname();
        $pagehandle->save($text, $version + 1, $meta);
        //Codendi specific: remove permissions for this page @codenditodo: may be transferable otherwhere.
        require_once 'common/wiki/lib/WikiPage.class.php';
        $wiki_page = new WikiPage(GROUP_ID, $_REQUEST['pagename']);
        $wiki_page->resetPermissions();
        // Real delete.
        //$pagename = $page->getName();
        $dbi = $request->getDbh();
        $dbi->deletePage($pagename);
        $dbi->touch();
        $link = HTML::a(array('href' => 'javascript:history.go(-2)'), _("Back to the previous page."));
        $html = HTML(HTML::h2(fmt("Removed page '%s' successfully.", $pagename)), HTML::div($link), HTML::hr());
    }
    GeneratePage($html, _("Remove Page"));
}
    /**
     * Export a whole Wiki to a single HTML String
     * @return  string Wiki content in HTML
     */
    public function export()
    {
		global $langWikiMainPage, $langWikiPageNotLoaded;
		
        $pageList = $this->wiki->allPagesByCreationDate();

        $result = $this->_htmlHeader();

        $result .= '<h1>' . $this->wiki->getTitle() . '</h1>' . "\n";

        foreach ( $pageList as $page )
        {
            $wikiPage = new WikiPage($this->wiki->getWikiId());

            $wikiPage->loadPage($page->title);

            $this->setOpt('note_prefix', $page->title);

            if ( $wikiPage->hasError() )
            {
                $result .= '<h2><a name="'
                    . $this->_makePageTitleAnchor($page->title).'">'
                    . $page->title
                    . '</a></h2>'
                    . "\n"
                    ;

                $result .= sprintf($langWikiPageNotLoaded,$page->title);
                $wikiPage = null;
            }
            else
            {
                $pgTitle = $wikiPage->getTitle();

                if ( '__MainPage__' === $pgTitle )
                {
                    $pgTitle = $langWikiMainPage;
                }

                $result .= '<h2><a name="'
                    . $this->_makePageTitleAnchor($page->title) .'">'
                    . $pgTitle
                    .'</a></h2>'
                    . "\n"
                    ;

                $content = $wikiPage->getContent();
                $result .= $this->render($content) . "\n";

                $wikiPage = null;
            }
        }

        $result .= $this->_htmlFooter();

        return $result;
    }
 /**
  * @since 2.2
  */
 public function getEditInfo(Title $title)
 {
     $this->page = new \WikiPage($title);
     if (class_exists('WikitextContent')) {
         $content = $this->page->getRevision()->getContent();
         $format = $content->getContentHandler()->getDefaultFormat();
         return $this->page->prepareContentForEdit($content, null, null, $format);
     }
     return $this->page->prepareTextForEdit($this->page->getRevision()->getRawText(), null, null);
 }
 protected function performUpdate()
 {
     $applicationFactory = ApplicationFactory::getInstance();
     $parserData = $applicationFactory->newParserData($this->wikiPage->getTitle(), $this->parserOutput);
     $pageInfoProvider = $applicationFactory->newMwCollaboratorFactory()->newPageInfoProvider($this->wikiPage, $this->revision, $this->user);
     $propertyAnnotator = $applicationFactory->newPropertyAnnotatorFactory()->newPredefinedPropertyAnnotator($parserData->getSemanticData(), $pageInfoProvider);
     $propertyAnnotator->addAnnotation();
     $parserData->pushSemanticDataToParserOutput();
     return true;
 }
 /**
  * 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;
 }
 static function onPageContentSave(WikiPage &$wikiPage, User &$user, Content &$content, &$summary, $isMinor, $isWatch, $section, &$flags, Status &$status)
 {
     // get the current tags from the page
     /////////////////////////////////////
     $CurrentReferences;
     preg_match_all(self::GetLabelsRegex, $wikiPage->getText(), $matches);
     // build it as a "set"
     foreach (array_merge($matches[2], $matches[3]) as $toAdd) {
         if ($toAdd != '') {
             $CurrentReferences[$toAdd] = 1;
         }
     }
     // get the old tags from the database
     /////////////////////////////////////
     $OldReferences;
     if (($rev = $wikiPage->getRevision()) != null && ($prevRev = $rev->getPrevious()) != null) {
         preg_match_all(self::GetLabelsRegex, $prevRev->getText(), $matches);
         // build it as a "set"
         foreach (array_merge($matches[2], $matches[3]) as $toAdd) {
             if ($toAdd != '') {
                 $OldReferences[$toAdd] = 1;
             }
         }
     }
     // Resolve differences
     //////////////////////
     $DB = wfGetDB(DB_MASTER);
     $DB->begin();
     // start a transaction
     // start with the newOnes and make sure that the database is compatable, and remove them
     foreach (array_keys($CurrentReferences) as $RefToMakeSureExists) {
         if (isset($OldReferences[$RefToMakeSureExists])) {
             // if it is already in the array, then we don't have to worry about it; delete it
             unset($OldReferences[$RefToMakeSureExists]);
         } else {
             // if it doesn't exist, we need to add it
             try {
                 $DB->insert(ContentReferencerTableName, array('reference_name' => $RefToMakeSureExists, 'reference_page_name' => (string) $wikiPage->getTitle()));
             } catch (Exception $e) {
                 die($e->getMessage());
             }
         }
     }
     // now, anything left in $OldReferences has been deleted. Let's remove it from the database
     foreach (array_keys($OldReferences) as $RefToDelete) {
         try {
             $DB->delete(ContentReferencerTableName, "reference_name='{$RefToDelete}'");
         } catch (Exception $e) {
             die($e->getMessage());
         }
     }
     $DB->commit();
     // end the transaction
 }
示例#22
0
 public function createPage(Title $title)
 {
     $page = new \WikiPage($title);
     $pageContent = 'Content of ' . $title->getFullText();
     $editMessage = 'SPL system test: create page';
     if (class_exists('WikitextContent')) {
         $page->doEditContent(new \WikitextContent($pageContent), $editMessage);
     } else {
         $page->doEdit($pageContent, $editMessage);
     }
 }
示例#23
0
 /**
  * Hook: Clear cache (videos by category) when the category page is purged
  * @param WikiPage $page
  * @return true
  */
 public static function onArticlePurge(WikiPage &$page)
 {
     wfProfileIn(__METHOD__);
     $title = $page->getTitle();
     if ($title->getNamespace() == NS_CATEGORY) {
         $helper = new VideoPageToolHelper();
         $helper->invalidateCacheVideosByCategory($title->getDBkey());
     }
     wfProfileOut(__METHOD__);
     return true;
 }
 protected function getParserOutput(WikiPage $wp, ParserOptions $parserOptions)
 {
     $params = $this->extractRequestParams();
     if (!isset($params['text'])) {
         throw new Exception('Must specify page text');
     }
     $parser = new Parser();
     $po = $parser->parse($params['text'], $wp->getTitle(), $parserOptions);
     $po->setTOCEnabled(false);
     $po->setText(str_replace(array("\r", "\n"), '', $po->getText()));
     return $po;
 }
示例#25
0
/**
 * create wiki MainPage
 * @param DatabaseConnection con database connection
 * @param int wikiId ID of the Wiki the page belongs to
 * @param int creatorId ID of the user who creates the page
 * @return boolean true if the creation succeeds, false if it fails
 */
function init_wiki_main_page($con, $wikiId, $creatorId, $wikiTitle)
{
    $tblList = claro_sql_get_course_tbl();
    $mainPageContent = get_lang("This is the main page of the Wiki %wikiTitle. Click on '''Edit''' to modify the content.", array('%wikiTitle' => $wikiTitle));
    $config = array();
    // use claro functions
    $config["tbl_wiki_pages"] = $tblList["wiki_pages"];
    $config["tbl_wiki_pages_content"] = $tblList["wiki_pages_content"];
    $wikiPage = new WikiPage($con, $config, $wikiId);
    $wikiPage->create($creatorId, '__MainPage__', $mainPageContent, date("Y-m-d H:i:s"), true);
    return !$wikiPage->hasError();
}
示例#26
0
function filter_antispam($formatter, $value, $options)
{
    global $Config;
    $blacklist_pages = array('BadContent', 'LocalBadContent');
    $whitelist_pages = array('GoodContent', 'LocalGoodContent');
    if (!in_array($formatter->page->name, $blacklist_pages) and !in_array($formatter->page->name, $whitelist_pages)) {
        $badcontents_file = !empty($options['.badcontents']) ? $options['.badcontents'] : $Config['badcontents'];
        if (!file_exists($badcontents_file)) {
            return $value;
        }
        $badcontent = file_get_contents($badcontents_file);
        foreach ($blacklist_pages as $list) {
            $p = new WikiPage($list);
            if ($p->exists()) {
                $badcontent .= $p->get_raw_body();
            }
        }
        if (!$badcontent) {
            return $value;
        }
        $badcontents = explode("\n", $badcontent);
        $pattern[0] = '';
        $i = 0;
        foreach ($badcontents as $line) {
            if (isset($line[0]) and $line[0] == '#') {
                continue;
            }
            $line = preg_replace('/[ ]*#.*$/', '', $line);
            $test = @preg_match("/{$line}/i", "");
            if ($test === false) {
                $line = preg_quote($line, '/');
            }
            if ($line) {
                $pattern[$i] .= $line . '|';
            }
            if (strlen($pattern[$i]) > 4000) {
                $i++;
                $pattern[$i] = '';
            }
        }
        for ($k = 0; $k <= $i; $k++) {
            $pattern[$k] = '/(' . substr($pattern[$k], 0, -1) . ')/i';
        }
        #foreach ($whitelist_pages as $list) {
        #    $p=new WikiPage($list);
        #    if ($p->exists()) $goodcontent.=$p->get_raw_body();
        #}
        #$goodcontents=explode("\n",$goodcontent);
        return preg_replace($pattern, "''''''[[HTML(<span class='blocked'>)]]\\1[[HTML(</span>)]]''''''", $value);
    }
    return $value;
}
示例#27
0
文件: install.php 项目: Jopperi/wiki
/**
 * Wiki for phpWebSite
 *
 * See docs/CREDITS for copyright information
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @package Wiki
 * @author Greg Meiste <*****@*****.**>
 */
function wiki_install(&$content)
{
    PHPWS_Core::initModClass('wiki', 'WikiManager.php');
    PHPWS_Core::initModClass('wiki', 'WikiPage.php');
    PHPWS_Core::initModClass('version', 'Version.php');
    // Adding pages that ship with the module
    if (file_exists(PHPWS_SOURCE_DIR . 'mod/wiki/boost/frontpage.txt')) {
        $frontpage = new WikiPage('FrontPage');
        $frontpage->setPagetext(implode('', file(PHPWS_SOURCE_DIR . 'mod/wiki/boost/frontpage.txt')));
        $frontpage->setOwnerId(Current_User::getId());
        $frontpage->setEditorId(Current_User::getId());
        $frontpage->setCreated(mktime());
        $frontpage->setUpdated(mktime());
        $frontpage->setComment('Provided by Wiki install');
        $frontpage->save();
        $version1 = new Version('wiki_pages');
        $version1->setSource($frontpage);
        $version1->setApproved(1);
        $version1->save();
    }
    if (file_exists(PHPWS_SOURCE_DIR . 'mod/wiki/boost/samplepage.txt')) {
        $samplepage = new WikiPage('SamplePage');
        $samplepage->setPagetext(implode('', file(PHPWS_SOURCE_DIR . 'mod/wiki/boost/samplepage.txt')));
        $samplepage->setOwnerId(Current_User::getId());
        $samplepage->setEditorId(Current_User::getId());
        $samplepage->setCreated(mktime());
        $samplepage->setUpdated(mktime());
        $samplepage->setComment('Provided by Wiki install');
        $samplepage->allow_edit = 0;
        $samplepage->save();
        $version2 = new Version('wiki_pages');
        $version2->setSource($samplepage);
        $version2->setApproved(1);
        $version2->save();
    }
    if (file_exists(PHPWS_SOURCE_DIR . 'mod/wiki/boost/sandbox.txt')) {
        $sandbox = new WikiPage('WikiSandBox');
        $sandbox->setPagetext(implode('', file(PHPWS_SOURCE_DIR . 'mod/wiki/boost/sandbox.txt')));
        $sandbox->setOwnerId(Current_User::getId());
        $sandbox->setEditorId(Current_User::getId());
        $sandbox->setCreated(mktime());
        $sandbox->setUpdated(mktime());
        $sandbox->setComment('Provided by Wiki install');
        $sandbox->save();
        $version3 = new Version('wiki_pages');
        $version3->setSource($sandbox);
        $version3->setApproved(1);
        $version3->save();
    }
    // Adding first interwiki link
    PHPWS_Core::initModClass('wiki', 'InterWiki.php');
    $interwiki = new InterWiki();
    $interwiki->setLabel('Wikipedia');
    $interwiki->setUrl('http://en.wikipedia.org/wiki/%s');
    $interwiki->save(FALSE);
    return TRUE;
}
 public function testImportForImportSource()
 {
     $this->doImport($this->importStreamSource);
     // Imported title
     $loremIpsum = Title::newFromText('Lorem ipsum');
     $this->assertSame($loremIpsum->getArticleID(), $loremIpsum->getArticleID(Title::GAID_FOR_UPDATE));
     $categoryLoremIpsum = Title::newFromText('Category:Lorem ipsum');
     $this->assertSame($categoryLoremIpsum->getArticleID(), $categoryLoremIpsum->getArticleID(Title::GAID_FOR_UPDATE));
     $page = new WikiPage($loremIpsum);
     $page->doDeleteArticle('import test: delete page');
     $page = new WikiPage($categoryLoremIpsum);
     $page->doDeleteArticle('import test: delete page');
 }
示例#29
0
 /**
  * @since 2.1
  *
  * @param Title $title
  *
  * @return text
  */
 public function getContentAsText(Title $title)
 {
     $this->page = new \WikiPage($title);
     if (method_exists($this->page, 'getContent')) {
         $content = $this->page->getContent();
         if ($content instanceof TextContent) {
             return $content->getNativeData();
         } else {
             return '';
         }
     }
     return $this->page->getText();
 }
示例#30
0
 /**
  * Helper function for addDBData -- adds a simple page to the database
  *
  * @param string $title Title of page to be created
  * @param string $lang Language and content of the created page
  * @param string|null $content Content of the created page, or null for a generic string
  */
 protected function makePage($title, $lang, $content = null)
 {
     global $wgContLang;
     if ($content === null) {
         $content = $lang;
     }
     if ($lang !== $wgContLang->getCode()) {
         $title = "{$title}/{$lang}";
     }
     $title = Title::newFromText($title, NS_MEDIAWIKI);
     $wikiPage = new WikiPage($title);
     $contentHandler = ContentHandler::makeContent($content, $title);
     $wikiPage->doEditContent($contentHandler, "{$lang} translation test case");
 }