/** * * Add/update a page to wiki * @param string $pagename * @param string $text * @param boolean $hasSemanticInternal whether this text contains semanticInternal Object. * SemanticInternal Object needs some special handling. First there is a bug in current * SemanticInternal Object implemenattion: the semantic internal properties can not be * saved in the very first time. Second, if the semantic internal object saving is not from * a special page action, but a regular page saving action, the semantic internal object * is confused about the "CURRENT" page. So asynchronous saving through a task is needed. * * @param $summary */ public static function addPage($pagename, $text, $force = true, $astask = false, $hasSemanticInternal = false, $summary = "Auto generation") { global $wgUser; $title = str_replace(' ', '_', $pagename); $t = Title::makeTitleSafe(NS_MAIN, $title); $article = new Article($t); if ($article->exists() && !$force) { return false; } if (!$astask) { $e = $article->exists(); //do adding inline $article->doEdit($text, $summary); if ($hasSemanticInternal && !$e) { //one more time $article->doEdit($text, $summary); } return true; } else { //add article asynchronously. $jobs = array(); $job_params = array(); $job_params['user_id'] = $wgUser->getId(); $job_params['edit_summary'] = $summary; $job_params['text'] = $text; $jobs[] = new DTImportJob($t, $job_params); if ($hasSemanticInternal && !$article->exists()) { $jobs[] = new DTImportJob($t, $job_params); } Job::batchInsert($jobs); } }
public static function GetURI($p_publicationId, $p_languageId, $p_issueNo = null, $p_sectionNo = null, $p_articleNo = null) { $translator = \Zend_Registry::get('container')->getService('translator'); $languageObj = new Language($p_languageId); if (!$languageObj->exists()) { return new PEAR_Error($translator->trans('Language does not exist.')); } $uri = '/' . $languageObj->getCode() . '/'; if (!is_null($p_issueNo) && is_null($p_articleNo)) { $issueObj = new Issue($p_publicationId, $p_languageId, $p_issueNo); if (!$issueObj->exists()) { return new PEAR_Error($translator->trans('Issue does not exist.')); } $uri .= $issueObj->getUrlName() . '/'; } if (!is_null($p_sectionNo) && is_null($p_articleNo)) { $sectionObj = new Section($p_publicationId, $p_issueNo, $p_languageId, $p_sectionNo); if (!$sectionObj->exists()) { return new PEAR_Error($translator->trans('Section does not exist.')); } $uri .= $sectionObj->getUrlName() . '/'; } if (!is_null($p_articleNo)) { $articleObj = new Article($p_languageId, $p_articleNo); if (!$articleObj->exists()) { return new PEAR_Error($translator->trans('Article does not exist.')); } $issueObj = new Issue($p_publicationId, $p_languageId, $articleObj->getIssueNumber()); $sectionObj = new Section($p_publicationId, $articleObj->getIssueNumber(), $p_languageId, $articleObj->getSectionNumber()); $uri .= $issueObj->getUrlName() . '/'; $uri .= $sectionObj->getUrlName() . '/'; $uri .= $articleObj->getUrlName() . '/'; } return $uri; }
function execute($par) { global $wgOut, $wgRequest, $wgUseTidy; wfLoadExtensionMessages('SpecialCite'); // Having tidy on causes whitespace and <pre> tags to // be generated around the output of the CiteOutput // class TODO FIXME. $wgUseTidy = false; $this->setHeaders(); $this->outputHeader(); $page = isset($par) ? $par : $wgRequest->getText('page'); $id = $wgRequest->getInt('id'); $title = Title::newFromText($page); if ($title) { $article = new Article($title); } $cform = new CiteForm($title); if (!$title || !$article->exists()) { $cform->execute(); } else { $cform->execute(); $cout = new CiteOutput($title, $article, $id); $cout->execute(); } }
function detail($title_none = NULL) { $title_none = $this->uri->segment(3); $arrTitle = explode('.', $title_none); if ($arrTitle[1] == '' || $arrTitle[1] != 'html') { redirect(''); } $title_none = $arrTitle[0]; $news = new Article(); $news->where('title_none', $title_none); $news->get(); //print_r($this->db->last_query());exit(); if (!$news->exists()) { show_404(); } $dis['news'] = $news; //related news $related_news = new Article(); $related_news->where('recycle', 0); $related_news->where('newscatalogue_id', $news->newscatalogue_id); $related_news->where("id !=", $news->id); $related_news->order_by('created', 'DESC'); $related_news->get_paged(0, 10, TRUE); $dis['related_news'] = $related_news; $category = new Newscatalogue($news->newscatalogue_id); $dis['category'] = $category; $this->page_title = $news->{'title_vietnamese'}; $this->page_description = $news->short_vietnamese; $this->page_keyword = $news->tag; $dis['base_url'] = base_url(); $dis['link'] = base_url() . $_SERVER['REQUEST_URI']; $dis['view'] = 'front/services/news_de'; $this->viewfront($dis); }
function execute() { global $wgRequest, $wgOut, $wgUser, $wgArticle; $sitting_of = $wgRequest->getVal('sitting_of'); $session_number = $wgRequest->getVal('session_number'); $sitting_start_date_time = $wgRequest->getVal('sitting_start_date_and_time'); $sitting_end_date_time = $wgRequest->getVal('sitting_end_date_and_time'); $sitting_session_number = $wgRequest->getVal('sitting_session_number'); $wpEditToken = $wgRequest->getVal('wpEditToken'); $sitting_desc = $wgRequest->getVal('sitting_desc'); $sitting_start_date = substr($sitting_start_date_time, 0, strpos($sitting_start_date_time, ' ')); $sitting_start_time = substr($sitting_start_date_time, strpos($sitting_start_date_time, ' ') + 1); $sitting_end_date = substr($sitting_end_date_time, 0, strpos($sitting_end_date_time, ' ')); $sitting_end_time = substr($sitting_end_date_time, strpos($sitting_end_date_time, ' ') + 1); $sitting_name = $sitting_of . '-' . $sitting_start_date; //$sitting_of.'-'.$sitting_start_date_time.'-' $title = Title::newFromText($sitting_name, MV_NS_SITTING); $wgArticle = new Article($title); $wgArticle->doEdit($sitting_desc, wfMsg('mv_summary_add_sitting')); $dbkey = $title->getDBKey(); $sitting = new MV_Sitting(array('name' => $dbkey, 'start_date' => $sitting_start_date, 'start_time' => $sitting_start_time, 'end_date' => $sitting_end_date, 'end_time' => $sitting_end_time)); //$sitting->db_load_sitting(); //$sitting->db_load_streams(); if ($sitting->insertSitting()) { if ($wgArticle->exists()) { $wgOut->redirect($title->getLocalURL("action=staff")); } else { $html .= 'Article ' . $sitting_name . ' does not exist'; $wgOut->addHtml($html); } } else { $WgOut->addHTML('Error: Duplicate Sitting Name?'); } }
public static function GetURI($p_publicationId, $p_languageId, $p_issueNo = null, $p_sectionNo = null, $p_articleNo = null) { $languageObj = new Language($p_languageId); if (!$languageObj->exists()) { return new PEAR_Error(getGS('Language does not exist.')); } $uri = $GLOBALS['Campsite']['SUBDIR'] . '/' . $languageObj->getCode() . '/'; if (!is_null($p_issueNo) && is_null($p_articleNo)) { $issueObj = new Issue($p_publicationId, $p_languageId, $p_issueNo); if (!$issueObj->exists()) { return new PEAR_Error(getGS('Issue does not exist.')); } $uri .= $issueObj->getUrlName() . '/'; } if (!is_null($p_sectionNo) && is_null($p_articleNo)) { $sectionObj = new Section($p_publicationId, $p_issueNo, $p_languageId, $p_sectionNo); if (!$sectionObj->exists()) { return new PEAR_Error(getGS('Section does not exist.')); } $uri .= $sectionObj->getUrlName() . '/'; } if (!is_null($p_articleNo)) { $articleObj = new Article($p_languageId, $p_articleNo); if (!$articleObj->exists()) { return new PEAR_Error(getGS('Article does not exist.')); } $issueObj = new Issue($p_publicationId, $p_languageId, $articleObj->getIssueNumber()); $sectionObj = new Section($p_publicationId, $articleObj->getIssueNumber(), $p_languageId, $articleObj->getSectionNumber()); $uri .= $issueObj->getUrlName() . '/'; $uri .= $sectionObj->getUrlName() . '/'; $uri .= $articleObj->getUrlName() . '/'; } return $uri; }
public function revertList($list, $revertUser) { global $wgServer, $wgLanguageCode; $results = array(); foreach ($list as $l) { if (preg_match('@^http://(.+)\\.wikihow\\.com/(.+)@', $l, $matches)) { if (!($wgLanguageCode == "en" && $matches[1] == "www" || $matches[1] == $wgLanguageCode)) { $results[] = array('url' => $l, 'success' => false, 'msg' => "Invalid URL for language"); } else { $link = $matches[2]; $title = Title::newFromUrl($link); $article = new Article($title); if ($article && $article->exists()) { $ret = $article->commitRollback($revertUser, wfMsg("mass-revert-message"), TRUE, $resultDetails); if (empty($ret)) { $results[] = array('url' => $l, 'success' => true); } else { $results[] = array('url' => $l, 'success' => false, 'msg' => $ret[0][0]); } } else { $results[] = array('url' => $l, 'success' => false, 'msg' => "Article not found"); } } } else { $results[] = array('url' => $l, 'success' => false, 'msg' => "Bad URL"); } } return $results; }
function detail($url) { $urlcat = $this->uri->segment(1); $category = new Newscatalogue(); $category->where(array('recycle' => 0, 'name_none' => $urlcat))->get(); if (!$category->exists()) { show_404(); } $dis['category'] = $category; $url = geturlfromuri($this->uri->segment(2)); $news = new Article(); $news->where(array('title_none' => $url, 'recycle' => 0)); $news->get(); if (!$news->exists()) { show_404(); } $dis['news'] = $news; $this->page_title = $news->title_vietnamese; $this->page_description = $news->short_vietnamese; $this->page_keyword = $news->tag; //related news $related_news = new Article(); $related_news->where('recycle', 0); $related_news->where('newscatalogue_id', $news->newscatalogue_id); $related_news->where("id !=", $news->id); $related_news->order_by('created', 'DESC'); $related_news->get_paged(0, 10, TRUE); $dis['related_news'] = $related_news; $dis['base_url'] = base_url(); $dis['view'] = 'front/newsother/news_de'; $this->viewfront($dis); }
function convert($newFormat, $pageName, $calName, $redirect, $go) { $search = "{$pageName}/{$calName}"; $pages = PrefixSearch::titleSearch($search, 1000000); //search upto 1,000,000 events (no performace issue) $count = $erroredCount = 0; foreach ($pages as $page) { $retval = false; $newPage = $this->convertToNewPage($page, $newFormat); $article = new Article(Title::newFromText($page)); if ($newPage != '') { $fromTitle = Title::newFromText($page); $toTitle = Title::newFromText($newPage); $articleNew = new Article(Title::newFromText($newPage)); if (!$article->isRedirect() && !$articleNew->exists()) { if ($go) { $retval = $fromTitle->moveTo($toTitle, true, 'CalendarConversion', $redirect); } else { if ($count < 10) { $testRun .= ' ' . $page . ' →→ ' . $newPage . '<br>'; } } } } } unset($pages); if ($go) { $ret = "Conversion completed."; } else { $ret = "<b>Test Results, add '<i>go</i>' to the <i>dateConverter</i> tag to convert:</b><br>{$testRun}"; } return $ret; }
/** * Just render some simple 404 page */ public function doRender404() { global $wgOut, $wgContLang, $wgCanonicalNamespaceNames; /** * check, maybe we have article with that title, if yes 301redirect to * this article */ $uri = $_SERVER['REQUEST_URI']; if (!preg_match('!^https?://!', $uri)) { $uri = 'http://unused' . $uri; } $uri = substr(parse_url($uri, PHP_URL_PATH), 1); Wikia::log(__METHOD__, false, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "[no referer]"); $title = $wgContLang->ucfirst(urldecode(ltrim($uri, "/"))); $namespace = NS_MAIN; /** * first check if title is in namespace other than main */ $parts = explode(":", $title, 2); if (count($parts) == 2) { foreach ($wgCanonicalNamespaceNames as $id => $name) { $translated = $wgContLang->getNsText($id); if (strtolower($translated) === strtolower($parts[0]) || strtolower($name) === strtolower($parts[0])) { $namespace = $id; $title = $parts[1]; break; } } } /** * create title from parts */ $oTitle = Title::newFromText($title, $namespace); if (!is_null($oTitle)) { if ($namespace == NS_SPECIAL || $namespace == NS_MEDIA) { /** * these namespaces are special and don't have articles */ header("X-Redirected-By: Our404Handler"); header(sprintf("Location: %s", $oTitle->getFullURL()), true, 301); exit(0); } else { $oArticle = new Article($oTitle); if ($oArticle->exists()) { header("X-Redirected-By: Our404Handler"); header(sprintf("Location: %s", $oArticle->getTitle()->getFullURL()), true, 301); exit(0); } } } /** * but if doesn't exist, we eventually show 404page */ $wgOut->setStatusCode(404); $info = wfMsgForContent('message404', $uri, urldecode($title)); $wgOut->addHTML('<h2>' . wfMsg('our404handler-oops') . '</h2> <div>' . $wgOut->parse($info) . '</div>'); }
function article_unique_title($str) { $this->form_validation->set_message('article_unique_title', 'Es existier bereits ein Artikel mit diesem Titel.'); $article = new Article(); $article->where('title', $str)->get(); if ($article->exists()) { return FALSE; } return TRUE; }
function test_article() { $article = new Article(9000001,9000002,9000003,9000004); // Test create $article->create("Unit Test Long Name", "Unit Test Short Name", "fastnews"); $this->assertTrue($article->exists()); // Test SET functions $article->setTitle("Unit Test New Title"); $article->setCreatorId(9000005); $article->setOnFrontPage(true); $article->setOnSection(true); $article->setWorkflowStatus('Y'); $article->setKeywords("Unit, Test"); $article->setIsIndexed(true); // Test GET functions $articleCopy = new Article(9000001, 9000002, 9000003, 9000004, $article->getArticleId()); $this->assertEquals(9000001, $articleCopy->getPublicationId()); $this->assertEquals(9000002, $articleCopy->getIssueNumber()); $this->assertEquals(9000003, $articleCopy->getSectionNumber()); $this->assertEquals(9000004, $articleCopy->getLanguageId()); $this->assertEquals(9000005, $articleCopy->getCreatorId()); $this->assertEquals("Unit Test New Title", $articleCopy->getTitle()); $this->assertEquals(true, $articleCopy->onFrontPage()); $this->assertEquals(true, $articleCopy->onSection()); $this->assertEquals('Y', $articleCopy->getWorkflowStatus()); $this->assertEquals("Unit, Test", $articleCopy->getKeywords()); $this->assertEquals(true, $articleCopy->isIndexed()); // Test DELETE functions $article->delete(); $this->assertFalse($article->exists()); }
function checkForEmpty($t) { $deleteComment = "Deleting unused profile box page"; if ($t) { $a = new Article($t); if ($a->exists()) { $content = $a->getContent(); if ($content == "") { if ($a->doDeleteArticle($deleteComment)) { echo $deleteComment . " " . $t->getText() . "\n"; return true; } } } } return false; }
function showList() { global $wgOut, $wgUser, $wgContLang; $fname = "BookSourceList::showList()"; # First, see if we have a custom list setup in # [[Wikipedia:Book sources]] or equivalent. $bstitle = Title::makeTitleSafe(NS_PROJECT, wfMsg("booksources")); $bsarticle = new Article($bstitle); if ($bsarticle->exists()) { $bstext = $bsarticle->getContent(false); if ($bstext) { $bstext = str_replace("MAGICNUMBER", $this->mIsbn, $bstext); $wgOut->addWikiText($bstext); return; } } # Otherwise, use the list of links in the default Language.php file. $s = wfMsg("booksourcetext") . "<ul>\n"; $bs = $wgContLang->getBookstoreList(); $bsn = array_keys($bs); foreach ($bsn as $name) { $adr = $bs[$name]; if (!$this->mIsbn) { $adr = explode(":", $adr, 2); $adr = explode("/", $adr[1]); $a = ""; while ($a == "") { $a = array_shift($adr); } $adr = "http://" . $a; } else { $adr = str_replace("\$1", $this->mIsbn, $adr); } $name = htmlspecialchars($name); $adr = htmlspecialchars($adr); $s .= "<li><a href=\"{$adr}\" class=\"external\">{$name}</a></li>\n"; } $s .= "</ul>\n"; $wgOut->addHTML($s); }
/** * Show the special page * * @param $params Mixed: parameter(s) passed to the page or null */ public function execute($params) { global $wgOut, $wgUser, $wgMemc; // This feature is only available to logged-in users. if (!$wgUser->isLoggedIn()) { throw new ErrorPageError('error', 'badaccess'); } // Show a message if the database is in read-only mode if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } $dbr = wfGetDB(DB_MASTER); $s = $dbr->selectRow('user_profile', array('up_user_id'), array('up_user_id' => $wgUser->getID()), __METHOD__); if ($s === false) { $dbw = wfGetDB(DB_MASTER); $dbw->insert('user_profile', array('up_user_id' => $wgUser->getID()), __METHOD__); } $profile = new UserProfile($wgUser->getName()); $profile_data = $profile->getProfile(); $user_page_type = $profile_data['user_page_type'] == 1 ? 0 : 1; $dbw = wfGetDB(DB_MASTER); $dbw->update('user_profile', array('up_type' => $user_page_type), array('up_user_id' => $wgUser->getID()), __METHOD__); $key = wfMemcKey('user', 'profile', 'info', $wgUser->getID()); $wgMemc->delete($key); if ($user_page_type == 1 && !$wgUser->isBlocked()) { $user_page = Title::makeTitle(NS_USER, $wgUser->getName()); $article = new Article($user_page); $user_page_content = $article->getContent(); $user_wiki_title = Title::makeTitle(NS_USER_WIKI, $wgUser->getName()); $user_wiki = new Article($user_wiki_title); if (!$user_wiki->exists()) { $user_wiki->doEdit($user_page_content, 'import user wiki'); } } $title = Title::makeTitle(NS_USER, $wgUser->getName()); $wgOut->redirect($title->getFullURL()); }
/** * initialize article title */ protected function initializeTitle($postedTitle) { if (!empty($postedTitle)) { $postedTitle = $this->getTitlePrefix() . $postedTitle; } $requestedTitle = $this->loadTitleFromRequest(); $requestedArticle = $requestedTitle ? new Article($requestedTitle) : null; if ($requestedTitle && ($this->titleNS == null || $requestedTitle->getNamespace() == $this->titleNS) && $requestedArticle && $requestedArticle->exists()) { // We are editing an existing article $this->setEditedTitle($requestedTitle); $this->mode = self::MODE_EDIT; return true; } $title = $this->getDefaultTitle(); $this->setEditedTitle($title); $this->mode = self::MODE_NEW_SETUP; if ($this->request->wasPosted()) { $this->mode = self::MODE_NEW; } if (empty($postedTitle)) { $this->titleStatus = self::STATUS_EMPTY; } else { // We are trying to create new article if ($this->titleNS == null) { $title = Title::newFromText($postedTitle); } else { $title = Title::newFromText($postedTitle, $this->titleNS); } if (!$title || strlen($title->getFragment()) > 0) { $this->titleStatus = self::STATUS_INVALID; } else { $article = new Article($title); if ($article->exists()) { $this->titleStatus = self::STATUS_ALREADY_EXISTS; } $this->setEditedTitle($title); } } }
function article() { if ($this->article) { return $this->article; } if (!is_null($this->articleId)) { if (isset(self::$articleCacheById[$this->articleId])) { return self::$articleCacheById[$this->articleId]; } if (isset(self::$titleCacheById[$this->articleId])) { $title = self::$titleCacheById[$this->articleId]; } else { $title = Title::newFromID($this->articleId); } if ($title) { $article = new Article($title); self::$articleCacheById[$this->articleId] = $article; } } if (isset($article) && $article->exists()) { $this->article = $article; return $article; } else { $title = Title::makeTitle($this->articleNamespace, $this->articleTitle); return new Article($title); } }
/** * @param int $p_publicationId * * @param int $p_languageId * * * @return mixed * array of issue publication dates * null if query does not match any issue */ public static function GetPublicationDates($p_publicationId, $p_languageId, $p_skipCache = false) { global $g_ado_db; $queryStr = 'SELECT Number FROM Articles ' . 'WHERE IdPublication = ' . $p_publicationId . ' AND ' . 'IdLanguage = ' . $p_languageId . " AND Published = 'Y' " . 'GROUP BY PublishDate ORDER BY PublishDate'; $rows = $g_ado_db->GetAll($queryStr); $dates = array(); if (is_array($rows)) { foreach ($rows as $row) { $tmpObj = new Article($p_languageId, $row['Number']); if ($tmpObj->exists()) { $dates[] = $tmpObj->getPublishDate(); } } } if (empty($dates)) { return null; } return array_unique($dates); } // fn GetPublicationDates
/** * main entry point * * @access public */ public function run() { global $wgUser, $wgTitle, $wgErrorLog; wfProfileIn(__METHOD__); $oldValue = $wgErrorLog; $wgErrorLog = true; /** * overwrite $wgUser for ~~~~ expanding */ $sysop = trim(wfMsgForContent("welcome-user")); if (!in_array($sysop, array("@disabled", "-"))) { $tmpUser = $wgUser; $wgUser = User::newFromName(self::WELCOMEUSER); $flags = 0; $bot_message = trim(wfMsgForContent("welcome-bot")); if ($bot_message == '@bot' || $wgUser && $wgUser->isAllowed('bot')) { $flags = EDIT_FORCE_BOT; } wfDebug(__METHOD__ . "-user: "******"-talk: " . $talkPage->getFullUrl()); if ($talkPage) { $this->mSysop = $this->getLastSysop(); $gEG = $this->mSysop->getEffectiveGroups(); $isSysop = in_array('sysop', $gEG); $isStaff = in_array('staff', $gEG); unset($gEG); $tmpTitle = $wgTitle; $sysopPage = $this->mSysop->getUserPage()->getTalkPage(); $signature = $this->expandSig(); $wgTitle = $talkPage; $welcomeMsg = false; $talkArticle = new Article($talkPage, 0); if (!self::isPosted($talkArticle, $this->mUser)) { if ($this->mAnon) { if ($this->isEnabled("message-anon")) { if ($isStaff && !$isSysop) { $key = $this->getMessageKey("anon-staff"); } else { $key = $this->getMessageKey("anon"); } $welcomeMsg = wfMsgNoTrans($key, array($this->getPrefixedText(), $sysopPage->getPrefixedText(), $signature, wfEscapeWikiText($this->mUser->getName()))); } else { wfDebug(__METHOD__ . "-talk: message-anon disabled"); } } else { /** * now create user page (if not exists of course) */ if ($this->isEnabled("page-user")) { $userPage = $this->mUser->getUserPage(); if ($userPage) { $wgTitle = $userPage; $userArticle = new Article($userPage, 0); wfDebug(__METHOD__ . "-userpage: " . $userPage->getFullUrl()); if (!$userArticle->exists()) { $pageMsg = wfMsgForContentNoTrans('welcome-user-page', $this->mUser->getName()); $userArticle->doEdit($pageMsg, false, $flags); } } else { wfDebug(__METHOD__ . "-page: user page already exists."); } } else { wfDebug(__METHOD__ . "-page: page-user disabled"); } if ($this->isEnabled("message-user")) { if ($isStaff && !$isSysop) { $key = $this->getMessageKey("user-staff"); } else { $key = $this->getMessageKey("user"); } $welcomeMsg = wfMsgNoTrans($key, array($this->getPrefixedText(), $sysopPage->getPrefixedText(), $signature, wfEscapeWikiText($this->mUser->getName()))); } else { wfDebug(__METHOD__ . "-talk: message-user disabled"); } } if ($welcomeMsg) { $wgTitle = $talkPage; /** is it necessary there? **/ //we posting it on talk page even when we have message wall //hack for notification problem global $wgCityId, $wgServer; $wgServer = WikiFactory::getVarValueByName('wgServer', $wgCityId); $this->doPost($talkArticle, $flags, wfMsgForContent("welcome-message-log"), $welcomeMsg, $wgUser, $this->mUser, $this->mSysop); } } $wgTitle = $tmpTitle; } } $wgUser = $tmpUser; $wgErrorLog = $oldValue; } else { wfDebug(__METHOD__ . "-disabled: " . $sysop); } wfProfileOut(__METHOD__); return true; }
/** * Returns true if the article was translated in to the language * identified by the given language code * * @param string $p_language - language code * @return bool */ public function translated_to($p_language) { if (is_string($p_language)) { $languages = Language::GetLanguages(null, $p_language); if (sizeof($languages) == 0) { return (int)false; } $language = $languages[0]; } else { $language = $p_language; } $article = new Article($language->getLanguageId(), $this->m_dbObject->getArticleNumber()); return (int)$article->exists() && ($article->isPublished() || CampTemplate::singleton()->context()->preview); }
if (!Input::IsValid()) { camp_html_display_error(getGS('Invalid input: $1', Input::GetErrorString())); exit; } $articleObj = new Article($languageId, $articleNumber); if (!$articleObj->exists()) { camp_html_display_error(getGS('Article does not exist.')); exit; } $translationLanguageObj = new Language($f_translation_language); if (!$translationLanguageObj->exists()) { camp_html_display_error(getGS('Language does not exist.')); exit; } $translationArticle = new Article($f_translation_language, $articleNumber); if ($translationArticle->exists()) { camp_html_add_msg(getGS("The article has already been translated into \$1.", $translationLanguageObj->getNativeName())); camp_html_goto_page($backLink); } $f_publication_id = $articleObj->getPublicationId(); // Only create the translated issue and section if the article has been // categorized. if ($f_publication_id > 0) { $publicationObj = new Publication($f_publication_id); if (!$publicationObj->exists()) { camp_html_display_error(getGS('Publication does not exist.'), $backLink); exit; } $f_issue_number = $articleObj->getIssueNumber(); $issueObj = new Issue($f_publication_id, $f_language_id, $f_issue_number); if (!$issueObj->exists()) {
$dbr = wfGetDB(DB_SLAVE); $res = $dbr->query('select * from Comments join page on Comment_Page_ID = page_id where page_namespace = 500'); while ($row = $res->fetchObject()) { $content = $row->Comment_Text; $user = User::newFromName($row->Comment_Username); $cTitle = $row->page_title; $cNamespace = 500; $cContent = $row->Comment_Text; try { $date = new DateTime($row->Comment_Date); } catch (Exception $e) { echo $e->getMessage(); exit(1); } $date_suffix = $date->format('YmdGis'); $newTitle = $cTitle . '/' . '@comment-' . $row->Comment_Username . '-' . $date_suffix; $wTitle = Title::newFromText($newTitle, 500 + 1); $parentTitle = Title::newFromText($cTitle, $cNamespace); $wArticle = new Article($wTitle); if (!$wArticle->exists() && is_object($parentTitle) && $parentTitle->exists()) { wfWaitForSlaves(); $wArticle->doEdit($content, 'Importing comments from old armchair', EDIT_FORCE_BOT, false, $user); wfWaitForSlaves(); } else { echo "skipped one: ID {$row->Comment_ID}\n"; } $i++; if ($i % 10 == 0) { echo $i . "\n"; } }
$f_language_id = Input::Get('f_language_id', 'int', 0, true); $f_language_selected = Input::Get('f_language_selected', 'int', 0); $f_article_number = Input::Get('f_article_number', 'int', 0); $f_attachment_id = Input::Get('f_attachment_id', 'int', 0); if (!Input::IsValid()) { camp_html_display_error($translator->trans('Invalid input: $1', array('$1' => Input::GetErrorString())), $_SERVER['REQUEST_URI'], true); exit; } if ($f_publication_id > 0) { $publicationObj = new Publication($f_publication_id); $issueObj = new Issue($f_publication_id, $f_language_id, $f_issue_number); $sectionObj = new Section($f_publication_id, $f_issue_number, $f_language_id, $f_section_number); } $articleObj = new Article($f_language_selected, $f_article_number); $attachmentObj = new Attachment($f_attachment_id); if (!$articleObj->exists()) { camp_html_display_error($translator->trans("Article does not exist."), null, true); exit; } $isDisabled = ''; $isReadOnly = ''; if (!$g_user->hasPermission('ChangeFile')) { $isDisabled = 'disabled'; $isReadOnly = 'readonly'; $title = $translator->trans('File information', array(), 'article_files'); } else { $title = $translator->trans('Change file information', array(), 'article_files'); } // Add extra breadcrumb for image list. if ($f_publication_id > 0) { $extraCrumbs = array($translator->trans("Attachments", array(), 'article_files') => "");
/** * Show the special page * * @param $section Mixed: parameter passed to the page or null */ public function execute($section) { global $wgUser, $wgOut, $wgRequest, $wgUserProfileScripts, $wgUpdateProfileInRecentChanges, $wgSupressPageTitle; $wgSupressPageTitle = true; $wgOut->setHTMLTitle(wfMsg('pagetitle', wfMsg('edit-profile-title'))); // This feature is only available for logged-in users. if (!$wgUser->isLoggedIn()) { $wgOut->setPageTitle(wfMsgForContent('user-profile-update-notloggedin-title')); $wgOut->addHTML(wfMsgForContent('user-profile-update-notloggedin-text', SpecialPage::getTitleFor('Userlogin')->escapeFullURL(), SpecialPage::getTitleFor('Userlogin', 'signup')->escapeFullURL())); return; } // No need to allow blocked users to access this page, they could abuse it, y'know. if ($wgUser->isBlocked()) { $wgOut->blockedPage(false); return false; } // Database operations require write mode if (wfReadOnly()) { $wgOut->readOnlyPage(); return; } // Add CSS & JS $wgOut->addExtensionStyle($wgUserProfileScripts . '/UserProfile.css'); $wgOut->addScriptFile($wgUserProfileScripts . '/UpdateProfile.js'); if ($wgRequest->wasPosted()) { if (!$section) { $section = 'basic'; } switch ($section) { case 'basic': $this->saveProfileBasic(); $this->saveSettings_basic(); break; case 'personal': $this->saveProfilePersonal(); break; case 'custom': $this->saveProfileCustom(); break; case 'preferences': $this->saveSettings_pref(); break; } UserProfile::clearCache($wgUser->getID()); $log = new LogPage(wfMsgForContent('user-profile-update-profile')); if (!$wgUpdateProfileInRecentChanges) { $log->updateRecentChanges = false; } $log->addEntry(wfMsgForContent('user-profile-update-profile'), $wgUser->getUserPage(), wfMsgForContent('user-profile-update-log-section') . " '{$section}'"); $wgOut->addHTML('<span class="profile-on">' . wfMsg('user-profile-update-saved') . '</span><br /><br />'); // create user page if not exists $title = Title::makeTitle(NS_USER, $wgUser->getName()); $article = new Article($title); if (!$article->exists()) { $article->doEdit('', 'create user page', EDIT_SUPPRESS_RC); } } if (!$section) { $section = 'basic'; } switch ($section) { case 'basic': $wgOut->addHTML($this->displayBasicForm()); break; case 'personal': $wgOut->addHTML($this->displayPersonalForm()); break; case 'custom': $wgOut->addHTML($this->displayCustomForm()); break; case 'preferences': $wgOut->addHTML($this->displayPreferencesForm()); break; } }
function buildCurrentSlide($page, $notoc) { global $wgScript, $wgParser; if (trim($page) == "") { return ""; } $link = $wgScript . "?title={$page}"; $article = new Article(Title::newFromText($page)); while ($article->isRedirect()) { $redirectedArticleTitle = Title::newFromRedirect($article->getContent()); $article = new Article($redirectedArticleTitle); } if ($article->exists()) { $slideBody = $article->getContent() . $notoc . " __NOEDITSECTION__"; } else { $slideBody = "The [[{$page}]] slide does not exist. Did you want to <b>[[{$page} | create]]</b> it?"; } $this->currentPageLink = "<a href='{$link}'>{$page}</a>"; //html $this->slideBody = $wgParser->recursiveTagParse($slideBody); //wiki markup converted to html }
function execute( $par ) { global $wgUser, $wgOut, $wgLang, $wgMemc, $wgDBname; global $wgRequest, $wgSitename, $wgLanguageCode; global $wgFilterCallback, $wgWhitelistEdit; //echo "topic: " . $wgRequest->getVal("topic_name") . "<br />"; //echo "title: " . $wgRequest->getVal("title") . "<br />"; //echo "comment: " . $wgRequest->getVal("comment_text") . "<br />"; //echo "new_topic id " . $wgRequest->getVal("new_topic") . "<br />"; if ( wfReadOnly() ) { $wgOut->readOnlyPage(); return; } $t = Title::newFromDBKey( $wgRequest->getVal( 'target' ) ); if ( $t == null ) { $wgOut->showErrorPage( 'postcomment', 'postcomment_invalidrequest' ); return; } $errors = $t->getUserPermissionsErrors( 'edit', $wgUser ); if ( count( $errors ) ) { $wgOut->showPermissionsErrorPage( $errors, 'edit' ); return; } if ( $wgUser->pingLimiter() ) { $wgOut->rateLimited(); return; } $article = new Article( $t ); $update = $article->exists(); $comment = $wgRequest->getVal( 'comment_text' ); $topic = $wgRequest->getVal( 'topic_name' ); if ( trim( $comment ) == '' ) { $wgOut->showErrorPage( 'postcomment', 'postcomment_nopostingtoadd' ); return; } $user = $wgUser->getName(); $real_name = $wgUser->getRealName(); if ( $real_name == '' ) { $real_name = $user; } $dateStr = $wgLang->timeanddate( wfTimestampNow() ); $formattedComment = " <div id=\"discussion_entry\"><table width=\"100%\"> <tr><td width=\"50%\" valign=\"top\" class=\"discussion_entry_user\">" . wfMsgExt( 'postcomment-userwrote', array( 'parsemag' ), $user, $real_name ) . " </td><td align=\"right\" width=\"50%\" class=\"discussion_entry_date\">" . wfMsg( 'postcomment_on', $dateStr ) . "<br /> </td></tr><tr> <td colspan=2 class=\"discussion_entry_comment\"> $comment</td></tr> <tr><td colspan=\"2\" class=\"discussion_entry_date\" padding=5>[[User_talk:$user#post|" . wfMsg('postcomment_replyto', $real_name) . "]]</td></tr> </table></div> "; $text = ''; if ( $update ) { $r = Revision::newFromTitle( $t ); $text = $r->getText(); } $text .= "\n\n$formattedComment\n\n"; $tmp = ""; if ( $wgFilterCallback && $wgFilterCallback( $t, $text, $tmp) ) { # Error messages or other handling should be performed by the filter function return; } $article->doEdit( $text, '' ); }
/** * testUseTableFalseExistsCheck method * * @return void */ public function testUseTableFalseExistsCheck() { $this->loadFixtures('Article'); $Article = new Article(); $Article->id = 1337; $result = $Article->exists(); $this->assertFalse($result); $Article->useTable = false; $Article->id = null; $result = $Article->exists(); $this->assertFalse($result); // An article with primary key of '1' has been loaded by the fixtures. $Article->useTable = false; $Article->id = 1; $result = $Article->exists(); $this->assertTrue($result); }
private function getArticle($number, $language, $user) { $em = $this->container->get('em'); $languageObject = $em->getRepository('Newscoop\\Entity\\Language')->findOneByCode($language); // Fetch article $articleObj = new \Article($languageObject->getId(), $number); if (!$articleObj->exists()) { throw new NewscoopException('Article does not exist'); } if (!$articleObj->userCanModify($user)) { throw new AccessDeniedException('User cannot modify article.'); } // Only users with a lock on the article can change it. if ($articleObj->isLocked() && $user->getUserId() != $articleObj->getLockedByUser()) { $lockTime = new \DateTime($articleObj->getLockTime()); $now = new \DateTime('now'); $difference = $now->diff($lockTime); $ago = $difference->format('%R%H:%I:%S'); $lockUser = new \User($articleObj->getLockedByUser()); throw new NewscoopException(sprintf('Article locked by %s (%s ago)', $lockUser->getRealName(), $ago)); } return $articleObj; }
<?php require_once($GLOBALS['g_campsiteDir']."/classes/Article.php"); require_once($GLOBALS['g_campsiteDir']."/classes/ArticlePublish.php"); require_once($GLOBALS['g_campsiteDir']."/classes/Issue.php"); require_once($GLOBALS['g_campsiteDir']."/classes/IssuePublish.php"); // AUTOPUBLISH TESTS echo "<h2>ARTICLE AUTOPUBLISH TESTS</h2>"; // create an article echo "Creating article...<br>"; $newArticle = new Article(1, 1, 1, 1); $newArticle->create('fastnews', 'autopublish test '.rand()); if (!$newArticle->exists()) { echo "failed to create article.<br>"; die(); } $newArticle->dumpToHtml(); // create an article event in the past echo "Creating event to publish the article...<br>"; $datetime = strftime("%Y-%m-%d %H:%M:00"); $articlePublishObj = new ArticlePublish($newArticle->getArticleId(), 1, $datetime); $articlePublishObj->create(); $articlePublishObj->setPublishAction('P'); $articlePublishObj->dumpToHtml(); echo "Getting events...<br>"; $events = ArticlePublish::GetPendingActions();
function warranty() { $news = new Article(); $news->where('id', 166); $news->get(); if (!$news->exists()) { show_404(); } $dis['news'] = $news; $this->page_title = $news->{'title_vietnamese'} . " - " . $this->page_title; $dis['base_url'] = base_url(); $dis['view'] = 'singlepage'; $this->viewfront($dis); }