function show($params) { global $wgOut; // Just parse the details out. list($action, $article_id, $queue) = $params; $article = Article::newFromId($article_id); $this->process($article, $queue); }
function wfPrintSalo($name) { $text = $name . " з'їв сала"; $id = Title::newMainPage()->getArticleId(); $ar = Article::newFromId($id); $ar->updateArticle($text, '', false, false); return true; }
function testPageStatsService() { global $wgTitle, $wgMemc; $wgTitle = Title::newMainPage(); $articleId = $wgTitle->getArticleId(); $article = Article::newFromId($articleId); $key = wfMemcKey('services', 'pageheader', 'current-revision', $articleId); // macbre: perform this test only for existing pages if (!$wgTitle->exists()) { $this->markTestSkipped('Main page cannot be found'); return; } $service = new PageStatsService($articleId); $this->assertType('array', $service->getMostLinkedCategories()); $this->assertType('int', $service->getCommentsCount()); $this->assertType('int', $service->getLikesCount()); $this->assertType('array', $service->getCurrentRevision()); $this->assertType('array', $service->getPreviousEdits()); $this->assertType('string', $service->getFirstRevisionTimestamp()); // comments counter regenerating $comments = $service->getCommentsCount(); $service->regenerateCommentsCount(); $this->assertEquals($comments, $service->getCommentsCount()); // remove cached stats when article is edited $user = $flags = $status = false; PageStatsService::onArticleSaveComplete($article, $user, false, false, false, false, false, $flags, false, $status, false); $data = $wgMemc->get($key); $this->assertTrue(empty($data)); $service->getCurrentRevision(); $data = $wgMemc->get($key); $this->assertFalse(empty($data)); // remove cached stats when article (comment) is deleted PageStatsService::onArticleDeleteComplete($article, $user, false, $articleId); $data = $wgMemc->get($key); $this->assertTrue(empty($data)); $service->getCurrentRevision(); // regenerate data $service->regenerateData(); $data = $wgMemc->get($key); $this->assertTrue(empty($data)); }
/** * Overrides content of parent page with contents of draft page * @param Title $draftTitle Title object of sub page (draft) * @throws PermissionsException */ private function approveDraft(Title $draftTitle) { // Get Title object of parent page $helper = new TemplateDraftHelper(); $parentTitle = $helper->getParentTitle($draftTitle); // Check edit rights if (!$parentTitle->userCan('templatedraft')) { throw new PermissionsException('edit'); } // Get contents of draft page $article = Article::newFromId($draftTitle->getArticleID()); $draftContent = $article->getContent(); // Get WikiPage object of parent page $page = WikiPage::newFromID($parentTitle->getArticleID()); // Save to parent page $page->doEdit($draftContent, wfMessage('templatedraft-approval-summary')->inContentLanguage()->plain()); // Remove Draft page $draftPage = WikiPage::newFromID($draftTitle->getArticleID()); $draftPage->doDeleteArticle(wfMessage('templatedraft-draft-removal-summary')->inContentLanguage()->plain()); // Show a confirmation message to a user after redirect BannerNotificationsController::addConfirmation(wfMessage('templatedraft-approval-success-confirmation')->escaped(), BannerNotificationsController::CONFIRMATION_CONFIRM, true); }
/** * Purges memcache entry */ public function purge() { global $wgMemc; wfProfileIn(__METHOD__); // clear data cache $wgMemc->delete($this->mMemcacheKey); $this->mData = null; $article = Article::newFromId($this->mQuizElementId); if (!empty($article)) { // purge quizElement page $article->doPurge(); // apply changes to page_touched fields $dbw = wfGetDB(DB_MASTER); $dbw->commit(); } // purge cached quiz if (empty($this->mQuizTitleObject)) { $this->load(); } if (!empty($this->mQuizTitleObject)) { $quizArticle = new WikiaQuizIndexArticle($this->mQuizTitleObject); $quizArticle->doPurge(); } else { // should never get to this point } wfDebug(__METHOD__ . ": purged quizElement #{$this->mQuizElementId}\n"); wfProfileOut(__METHOD__); }
/** * Purges memcache entry */ public function purge() { global $wgMemc; wfProfileIn(__METHOD__); // clear data cache $wgMemc->delete($this->mMemcacheKey); $this->mData = null; $article = Article::newFromId($this->mId); if (!empty($article)) { // purge page $article->doPurge(); // apply changes to page_touched fields $dbw = wfGetDB(DB_MASTER); $dbw->commit(); } wfDebug(__METHOD__ . ": purged RelatedVideos NS article #{$this->mId}\n"); wfProfileOut(__METHOD__); }
function sfAddSpeciesChild(&$page_contents, $page_title, $form_title) { $page_title = $form_title; $form_title = $page_title; //echo '<pre>'; print_r(func_get_args()); print_r($_GET); exit; if (isset($_GET['extend'])) { $extend = str_replace('_', ' ', $_GET['extend']); } if (isset($_GET['child_type'])) { $child_type = strtolower($_GET['child_type']); } else { if (isset($_GET['title'])) { if (preg_match('~^Special:FormEdit/([\\w]+)(/([\\w]+))?$~', $_GET['title'], $matches)) { //$extend = $child_type = strtolower($matches[1]); } } } if (!isset($extend) || !isset($child_type)) { return true; } $list_title = Title::newFromText($extend); $id = $list_title->getArticleID(); if (!$id) { return true; } $article = Article::newFromId($id); $text = $article->getRawText(); $text = self::removeField($text, array('common', 'primary image')); $preload = ''; //fields which, if present in the plant template, should be removed. These are fields which a small minority of pages will have which were used previously but now cause problems when extending $bad_fields = array('cultivar of', 'cultivar name', 'show cultivar group', 'cultivar group', 'is a variety', 'variety type', 'variety name', 'variety of', 'subspecies name', 'subspecies of'); //$bad_fields=array(); //echo $text; exit; switch ($child_type) { case 'cultivar_group': if (!strstr($text, "{{Plant\n|")) { //make sure there's an instance of the plant template in the page we're extending return true; } $text = self::removeField($text, $bad_fields); $preload = str_replace("{{Plant\n|", "{{Cultivar group\n|cultivar group of=" . $extend . '|', $text); break; case 'cultivar': if (strstr($text, "{{Plant\n|")) { $text = self::removeField($text, $bad_fields); $preload = str_replace("{{Plant\n|", "{{Cultivar\n|cultivar of=" . $extend . "\n|", $text); } elseif (strstr($text, "{{Cultivar group\n|")) { $text = self::removeField($text, $bad_fields); $preload = str_replace("{{Cultivar group\n|", "{{Cultivar\n|cultivar of=" . $extend . "\n|", $text); } else { return true; } break; case 'variety': $preload = str_replace("{{Plant\n|", '{{Variety', $text); case 'subspecies': $preload = str_replace("{{Plant\n|", '{{Subspecies', $text); break; } if (isset($preload)) { $page_contents = $preload; } //echo $preload; exit; return true; }
function editArticle() { global $wgOpenStackManagerCreateProjectSALPages; if (!OpenStackNovaArticle::canCreatePages()) { return; } $format = <<<RESOURCEINFO {{Nova Resource |Resource Type=project |Project Name=%s |Members=%s}} __NOEDITSECTION__ RESOURCEINFO; $rawmembers = $this->getMembers(); $members = array(); foreach ($rawmembers as $member) { array_push($members, 'User:'******',', $members)); OpenStackNovaArticle::editArticle($this->getProjectName(), $text); if ($wgOpenStackManagerCreateProjectSALPages) { $pagename = $this->getProjectName() . "/SAL"; $id = Title::newFromText($pagename, NS_NOVA_RESOURCE)->getArticleId(); $article = Article::newFromId($id); $content = ''; if ($article) { $content = $article->getRawText(); } $text = "{{SAL|Project Name=" . $this->getProjectName() . "}}"; if (!strstr($content, $text)) { OpenStackNovaArticle::editArticle($pagename, $text); } } }
/** * Purges memcache entry and articles having current poll transcluded */ public function purge() { global $wgMemc, $wgCityId; wfProfileIn(__METHOD__); // clear data cache $wgMemc->delete($this->mMemcacheKey); $this->mData = null; $article = Article::newFromId($this->mPollId); if (!empty($article)) { // purge poll page $article->doPurge(); // purge articles embedding this poll $task = (new \Wikia\Tasks\Tasks\HTMLCacheUpdateTask())->wikiId($wgCityId)->title($article->getTitle()); $task->call('purge', 'templatelinks'); $task->queue(); // apply changes to page_touched fields $dbw = wfGetDB(DB_MASTER); $dbw->commit(); } wfDebug(__METHOD__ . ": purged poll #{$this->mPollId}\n"); wfProfileOut(__METHOD__); }
function _make_links($page_id, $rev_id, $content) { $links = array('image' => 0, 'video' => 0); $oArticle = Article::newFromId($page_id); if ($oArticle instanceof Article) { $editInfo = $oArticle->prepareTextForEdit($content, $rev_id); $images = $editInfo->output->getImages(); if (!empty($images)) { foreach ($images as $iname => $dummy) { if (substr($iname, 0, 1) == ':') { $links['video']++; } else { $links['image']++; } } } } return $links; }
function show($params) { $article_id = $params[1]; $article = Article::newFromId($article_id); $this->process($article); }
/** * Function that is called after the user confirms the change. * Checks for the token and insertes the template. If the token is wrong or the article doesn't exist, preview() is shown * * @param $page String: title of the page that needs to be edited * @param $template String: title of the selected template * @param $token String: token that is included in the html form in preview() */ function submit($page, $template, $token) { global $wgOut, $wgUser; if (!$wgUser->matchEditToken($token)) { # Wrong Edit token. Show preview page $this->preview($page, $template); return; } $id = Title::newFromText($page)->getArticleId(); if ($id == 0) { # Page does not exist. Show preview page $wgOut->wrapWikiMsg("<div class='error plainlinks'>\n\$1</div>\n", array('flagpage-nonexistent', $page)); $this->preview($page, $template); return; } $article = Article::newFromId($id); $text = "{{" . $template . "}}\n\n" . $article->getRawText(); $summary = wfMsg('flagpage-summary', $template); $article->doEdit($text, $summary, EDIT_UPDATE, $id); $wgOut->addWikiMsg('flagpage-success', $template, $page, $id); // FIXME Broken link without oldid // TODO Add nice way to undo changes (copy HTML Forms of EditPage.php) }
$startTime = time(); $numFailed = 0; for($cnt=0; $cnt < $numRedirects; $cnt++){ $title = $redirectCache[$cnt]; $redirTo = "NULL"; // Ignore the result - just doing it to fill the 'redirTo'. $titleObj = Title::newFromDBkey($title); if( $titleObj ) { if($titleObj->exists()){ $article = Article::newFromID($titleObj->getArticleID()); if($article && $article->isRedirect()){ $reTitle = $article->followRedirect(); // follows redirects recursively if($reTitle && is_object($reTitle)){ //unset($article); // hint to garbage collector - doesn't appear to do anything in this case $article = Article::newFromId($reTitle->getArticleID()); } } if($article){ $redirTo = $article->getTitle()->getDBkey(); //$retVal = $article->getRawText(); // don't need the final page text. //unset($article); // hint to garbage collector - doesn't appear to do anything in this case fwrite($REDIR_FILE, formatForUb("$title")."\t\t".formatForUb("$redirTo")."\n"); } else { print "WARNING: REDIR DID NOT TERMINATE ON VALID FILE: \"$title\"\n"; $numFailed++; } } } // Output progress occasionally (but not constantly to avoid just filling the buffer constantly.
function lw_getPage($pageTitle, &$finalName = '', $debug = false, $page_namespace = NS_MAIN, &$page_id = '') { $retVal = ""; $finalName = $pageTitle; // Get the text of the end-point article and record what the final article name is. $title = Title::newFromText($pageTitle, $page_namespace); if ($title) { if ($title->exists()) { $page_id = $title->getArticleID(); $article = Article::newFromID($title->getArticleID()); if (is_object($article)) { /* @var $article WikiPage */ if ($article->isRedirect()) { $reTitle = $article->followRedirect(); // follows redirects recursively if ($reTitle instanceof Title) { $article = Article::newFromId($reTitle->getArticleID()); } else { $article = null; } } if (is_object($article)) { $finalName = $article->getTitle()->getDBkey(); $retVal = $article->getRawText(); } } } } // print (!$debug?"":"page code\n$retVal\n"); return $retVal; }
/** * Stuff that needs to be done after loading new data. */ protected function postLoad() { if (isset($this->mDiscussionPageID)) { $this->mDiscussionPage = Article::newFromId($this->mDiscussionPageID); } $this->mArticle = Article::newFromId($this->mArticleID); // Split votes. if (isset($this->mVotes) && count($this->mVotes)) { $this->mVotesEndorse = array(); $this->mVotesObject = array(); foreach ($this->mVotes as $vote) { $type = ucfirst($vote['type']); $arr_name = "mVotes{$type}"; $this->{$arr_name}[] = $vote; } } elseif (isset($this->mVotes)) { // Clear them. $this->mVotesEndorse = array(); $this->mVotesObject = array(); } }
/** * Purges memcache entry and articles having current poll transcluded */ public function purge() { global $wgMemc; wfProfileIn(__METHOD__); // clear data cache $wgMemc->delete($this->mMemcacheKey); $this->mData = null; $article = Article::newFromId($this->mPollId); if (!empty($article)) { // purge poll page $article->doPurge(); // purge articles embedding this poll $updateJob = new HTMLCacheUpdate($article->getTitle(), 'templatelinks'); $updateJob->doUpdate(); // apply changes to page_touched fields $dbw = wfGetDB(DB_MASTER); $dbw->commit(); } wfDebug(__METHOD__ . ": purged poll #{$this->mPollId}\n"); wfProfileOut(__METHOD__); }
public function saveEmpty() { if (is_null($this->UserPage)) { $id = Title::makeTitle(NS_TEMPLATE, 'Semantic_Social_Profile')->getArticleId(); $template = Article::newFromId($id)->getRawText(); $this->UserPage = new Article(Title::makeTitle(NS_USER, $this->User)); $this->UserPage->doEdit(preg_replace("/^.*(?:<pre>)(.*)(?:<\\/pre>).*\$/isU", "\$1", $template, 1), $this->summary); } }
private function _make_links() { $links = array('image' => 0, 'video' => 0); $content = $this->mContent; $oArticle = Article::newFromId($this->mPageId); if ($oArticle instanceof Article) { if (!empty($this->stripTags)) { /* skip some special tags */ foreach ($this->stripTags as $id => $tag) { $content = preg_replace($tag, '', $content); } } $content = str_replace("{{", "", $content); global $wgParser; $wgParser->clearTagHooks(); $editInfo = $oArticle->prepareTextForEdit($content, $this->mRevId); $images = $editInfo->output->getImages(); if (!empty($images)) { foreach ($images as $iname => $dummy) { if (substr($iname, 0, 1) == ':') { $links['video']++; } else { $links['image']++; } } } } return $links; }
function refresh(&$row) { global $wgRequest, $wgTemplateName, $wgTermField, $wgDefinitionField; $templatename = $wgTemplateName ? $wgTemplateName : "Lexicon"; $termfield = $wgTermField ? $wgTermField : "term"; $definitionfield = $wgDefinitionField ? $wgDefinitionField : "definition"; $dbr = wfGetDB(DB_MASTER); $res = $dbr->select('templatelinks', array('tl_from'), array('tl_from' => $row->id, 'tl_title' => $templatename), __METHOD__); if ($row1 = $res->fetchObject()) { $term = $definition = ''; $title = Title::newFromID($row1->tl_from); $id = $title->getArticleId(); $article = Article::newFromId($id); $content1 = $article->getRawText(); $content = str_replace("\n", '', $article->getRawText()); $url = $title->getFullUrl(); $termTeplate_reg = "/{{[\\s]*" . $templatename . "(.*)}}/i"; if (preg_match($termTeplate_reg, $content, $matches)) { $paras = $matches[1]; } else { return false; } $fields = preg_split("/\\|/", $paras); foreach ($fields as $field) { $value = preg_split("/=/", $field); if (trim($value[0]) == $termfield) { $term = trim($value[1]); } if (trim($value[0]) == $definitionfield) { $definition = trim($value[1]); } } if (!strlen($definition) || !strlen($term)) { return false; } $row->term = $term; $row->def = $definition; $row->url = $url; update_cache($row1->tl_from, $term, $definition, $url); } else { $dbw = wfGetDB(DB_MASTER); $dbw->delete('Lexicon_cache', array('id' => $row->id), __METHOD__); return false; } return true; }
function editArticle() { global $wgOpenStackManagerCreateProjectSALPages, $wgOpenStackManagerProjectNamespace; if (!OpenStackNovaArticle::canCreatePages()) { return; } $format = <<<RESOURCEINFO {{Nova Resource |Resource Type=project |Project Name=%s |Admins=%s |Members=%s}} __NOEDITSECTION__ RESOURCEINFO; $rawmembers = $this->getMembers(); $members = array(); foreach ($rawmembers as $member) { $members[] = 'User:'******'User:'******',', $admins), implode(',', $members)); OpenStackNovaArticle::editArticle($this->getProjectName(), $text, $wgOpenStackManagerProjectNamespace); if ($wgOpenStackManagerCreateProjectSALPages) { $pagename = $this->getProjectName() . "/SAL"; $id = Title::newFromText($pagename, $wgOpenStackManagerProjectNamespace)->getArticleId(); $article = Article::newFromId($id); $content = ''; if ($article) { $content = $article->getRawText(); } $text = "{{SAL|Project Name=" . $this->getProjectName() . "}}"; if (!strstr($content, $text)) { OpenStackNovaArticle::editArticle($pagename, $text, $wgOpenStackManagerProjectNamespace); } } }