public function executeNew(sfWebRequest $request) { $this->procedure = Doctrine::getTable('Procedure')->find($request->getParameter('procedure_id')); $this->last_state = $this->procedure->getLastRevision()->getRevisionStateId(); if ($this->last_state != 4) { $revision = new Revision(); $revision->setProcedureId($request->getParameter('procedure_id')); $this->form = new FrontRevisionForm($revision); } }
/** * Callback function for each revision, preprocessToObj() * @param Revision $rev */ public function processRevision($rev) { $content = $rev->getContent(Revision::RAW); if ($content->getModel() !== CONTENT_MODEL_WIKITEXT) { return; } try { $this->mPreprocessor->preprocessToObj(strval($content->getNativeData()), 0); } catch (Exception $e) { $this->error("Caught exception " . $e->getMessage() . " in " . $rev->getTitle()->getPrefixedText()); } }
public function execute() { $db = wfGetDB(DB_MASTER); if (!$db->tableExists('revision')) { $this->error("revision table does not exist", true); } $this->output("Populating rev_len column\n"); $start = $db->selectField('revision', 'MIN(rev_id)', false, __FUNCTION__); $end = $db->selectField('revision', 'MAX(rev_id)', false, __FUNCTION__); if (is_null($start) || is_null($end)) { $this->output("...revision table seems to be empty.\n"); $db->insert('updatelog', array('ul_key' => 'populate rev_len'), __METHOD__, 'IGNORE'); return; } # Do remaining chunks $blockStart = intval($start); $blockEnd = intval($start) + $this->mBatchSize - 1; $count = 0; $missing = 0; while ($blockStart <= $end) { $this->output("...doing rev_id from {$blockStart} to {$blockEnd}\n"); $res = $db->select('revision', Revision::selectFields(), array("rev_id >= {$blockStart}", "rev_id <= {$blockEnd}", "rev_len IS NULL"), __METHOD__); # Go through and update rev_len from these rows. foreach ($res as $row) { $rev = new Revision($row); $text = $rev->getRawText(); if (!is_string($text)) { # This should not happen, but sometimes does (bug 20757) $this->output("Text of revision {$row->rev_id} unavailable!\n"); $missing++; } else { # Update the row... $db->update('revision', array('rev_len' => strlen($text)), array('rev_id' => $row->rev_id), __METHOD__); $count++; } } $blockStart += $this->mBatchSize; $blockEnd += $this->mBatchSize; wfWaitForSlaves(5); } $logged = $db->insert('updatelog', array('ul_key' => 'populate rev_len'), __METHOD__, 'IGNORE'); if ($logged) { $this->output("rev_len population complete ... {$count} rows changed ({$missing} missing)\n"); return true; } else { $this->output("Could not insert rev_len population row.\n"); return false; } }
/** * @param $title Title * @param $revision Revision * @param $fname string * @return void */ public static function runForTitleInternal(Title $title, Revision $revision, $fname) { wfProfileIn($fname); $content = $revision->getContent(Revision::RAW); if (!$content) { // if there is no content, pretend the content is empty $content = $revision->getContentHandler()->makeEmptyContent(); } // Revision ID must be passed to the parser output to get revision variables correct $parserOutput = $content->getParserOutput($title, $revision->getId(), null, false); $updates = $content->getSecondaryDataUpdates($title, null, false, $parserOutput); DataUpdate::runUpdates($updates); InfoAction::invalidateCache($title); wfProfileOut($fname); }
public function doDBUpdates() { $db = $this->getDB(DB_MASTER); if (!$db->tableExists('revision')) { $this->error("revision table does not exist", true); } else { if (!$db->fieldExists('revision', 'rev_sha1', __METHOD__)) { $this->output("rev_sha1 column does not exist\n\n", true); return false; } } $this->output("Populating rev_len column\n"); $start = $db->selectField('revision', 'MIN(rev_id)', false, __METHOD__); $end = $db->selectField('revision', 'MAX(rev_id)', false, __METHOD__); if (!$start || !$end) { $this->output("...revision table seems to be empty.\n"); return true; } # Do remaining chunks $blockStart = intval($start); $blockEnd = intval($start) + $this->mBatchSize - 1; $count = 0; $missing = 0; $fields = Revision::selectFields(); while ($blockStart <= $end) { $this->output("...doing rev_id from {$blockStart} to {$blockEnd}\n"); $res = $db->select('revision', $fields, array("rev_id >= {$blockStart}", "rev_id <= {$blockEnd}", "rev_len IS NULL"), __METHOD__); # Go through and update rev_len from these rows. foreach ($res as $row) { $rev = new Revision($row); $content = $rev->getContent(); if (!$content) { # This should not happen, but sometimes does (bug 20757) $this->output("Content of revision {$row->rev_id} unavailable!\n"); $missing++; } else { # Update the row... $db->update('revision', array('rev_len' => $content->getSize()), array('rev_id' => $row->rev_id), __METHOD__); $count++; } } $blockStart += $this->mBatchSize; $blockEnd += $this->mBatchSize; wfWaitForSlaves(); } $this->output("rev_len population complete ... {$count} rows changed ({$missing} missing)\n"); return true; }
public function execute() { $params = $this->extractRequestParams(); $rev1 = $this->revisionOrTitleOrId($params['fromrev'], $params['fromtitle'], $params['fromid']); $rev2 = $this->revisionOrTitleOrId($params['torev'], $params['totitle'], $params['toid']); $revision = Revision::newFromId($rev1); if (!$revision) { $this->dieUsage('The diff cannot be retrieved, ' . 'one revision does not exist or you do not have permission to view it.', 'baddiff'); } $contentHandler = $revision->getContentHandler(); $de = $contentHandler->createDifferenceEngine($this->getContext(), $rev1, $rev2, null, true, false); $vals = array(); if (isset($params['fromtitle'])) { $vals['fromtitle'] = $params['fromtitle']; } if (isset($params['fromid'])) { $vals['fromid'] = $params['fromid']; } $vals['fromrevid'] = $rev1; if (isset($params['totitle'])) { $vals['totitle'] = $params['totitle']; } if (isset($params['toid'])) { $vals['toid'] = $params['toid']; } $vals['torevid'] = $rev2; $difftext = $de->getDiffBody(); if ($difftext === false) { $this->dieUsage('The diff cannot be retrieved. Maybe one or both revisions do ' . 'not exist or you do not have permission to view them.', 'baddiff'); } ApiResult::setContentValue($vals, 'body', $difftext); $this->getResult()->addValue(null, $this->getModuleName(), $vals); }
/** * Loads the mapping table. */ private function loadTable() { // no need to load multiple times. if ($this->loaded) { return; } $this->loaded = true; $title = Title::newFromText(self::$tablePageName); if (!$title->exists()) { return; } $tablePageRev = Revision::newFromTitle($title); if (is_object($tablePageRev)) { $tablePage = $tablePageRev->getText(); global $wgUser; $parser = new Parser(); $parser->setFunctionHook('tag_to_template', array($this, 'mg_tag_to_template')); // this will populate the 'map' variable // assuming of course that the page was edited with // {{#tag_to_template| ... }} instructions. $this->initPhase = true; $parser->parse($tablePage, $title, new ParserOptions($wgUser)); $this->initPhase = false; } }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $ids = array_map('intval', $this->ids); $queryInfo = ['tables' => ['revision', 'user'], 'fields' => array_merge(Revision::selectFields(), Revision::selectUserFields()), 'conds' => ['rev_page' => $this->title->getArticleID(), 'rev_id' => $ids], 'options' => ['ORDER BY' => 'rev_id DESC'], 'join_conds' => ['page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond()]]; ChangeTags::modifyDisplayQuery($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], $queryInfo['join_conds'], $queryInfo['options'], ''); $live = $db->select($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], __METHOD__, $queryInfo['options'], $queryInfo['join_conds']); if ($live->numRows() >= count($ids)) { // All requested revisions are live, keeps things simple! return $live; } $archiveQueryInfo = ['tables' => ['archive'], 'fields' => Revision::selectArchiveFields(), 'conds' => ['ar_rev_id' => $ids], 'options' => ['ORDER BY' => 'ar_rev_id DESC'], 'join_conds' => []]; ChangeTags::modifyDisplayQuery($archiveQueryInfo['tables'], $archiveQueryInfo['fields'], $archiveQueryInfo['conds'], $archiveQueryInfo['join_conds'], $archiveQueryInfo['options'], ''); // Check if any requested revisions are available fully deleted. $archived = $db->select($archiveQueryInfo['tables'], $archiveQueryInfo['fields'], $archiveQueryInfo['conds'], __METHOD__, $archiveQueryInfo['options'], $archiveQueryInfo['join_conds']); if ($archived->numRows() == 0) { return $live; } elseif ($live->numRows() == 0) { return $archived; } else { // Combine the two! Whee $rows = []; foreach ($live as $row) { $rows[$row->rev_id] = $row; } foreach ($archived as $row) { $rows[$row->ar_rev_id] = $row; } krsort($rows); return new FakeResultWrapper(array_values($rows)); } }
function wfSpecialCheckmylinks($par) { global $wgRequest, $wgSitename, $wgLanguageCode; global $wgDeferredUpdateList, $wgOut, $wgUser, $wgServer, $wgParser, $wgTitle; $fname = "wfCheckmylinks"; $wgOut->addHTML(wfMsgWikiHtml('checkmylinks_summary')); if ($wgUser->getID() > 0) { $t = Title::makeTitle(NS_USER, $wgUser->getName() . "/Mylinks"); if ($t->getArticleID() > 0) { $r = Revision::newFromTitle($t); $text = $r->getText(); if ($text != "") { $ret = "<h3>" . wfMsg('mylinks') . "</h3>"; $options = new ParserOptions(); $output = $wgParser->parse($text, $wgTitle, $options); $ret .= $output->getText(); } $size = strlen($ret); if ($size > 3000) { $wgOut->addHTML(wfMsgWikiHtml('checkmylinks_size_bad', number_format($size, 0, "", ","))); } else { $wgOut->addHTML(wfMsgWikiHtml('checkmylinks_size_good', number_format($size, 0, "", ","))); } } else { $wgOut->addHTML(wfMsgWikiHtml('checkmylinks_error')); } } else { $wgOut->addHTML(wfMsgWikiHtml('checkmylinks_notloggedin')); } }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $ids = array_map('intval', $this->ids); $live = $db->select(array('revision', 'page', 'user'), array_merge(Revision::selectFields(), Revision::selectUserFields()), array('rev_page' => $this->title->getArticleID(), 'rev_id' => $ids), __METHOD__, array('ORDER BY' => 'rev_id DESC'), array('page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond())); if ($live->numRows() >= count($ids)) { // All requested revisions are live, keeps things simple! return $live; } // Check if any requested revisions are available fully deleted. $archived = $db->select(array('archive'), Revision::selectArchiveFields(), array('ar_rev_id' => $ids), __METHOD__, array('ORDER BY' => 'ar_rev_id DESC')); if ($archived->numRows() == 0) { return $live; } elseif ($live->numRows() == 0) { return $archived; } else { // Combine the two! Whee $rows = array(); foreach ($live as $row) { $rows[$row->rev_id] = $row; } foreach ($archived as $row) { $rows[$row->ar_rev_id] = $row; } krsort($rows); return new FakeResultWrapper(array_values($rows)); } }
/** * check for plagiarism with copyscape * return true if there's an issue */ private static function copyCheck($t) { $threshold = 0.05; $result = ''; $r = Revision::newFromTitle($t); if (!$r) { return 'No such article'; } $text = Wikitext::flatten($r->getText()); $res = copyscape_api_text_search_internet($text, 'ISO-8859-1', 2); if ($res['count']) { $words = $res['querywords']; foreach ($res['result'] as $r) { if (!preg_match("@^http://[a-z0-9]*.(wikihow|whstatic|youtube).com@i", $r['url'])) { //if ($r['minwordsmatched'] / $words > $threshold) { //we got one! $result .= '<b>Plagiarized:</b> <a href="' . $r['url'] . '">' . $r['url'] . '</a><br />'; //} } } } else { $result = ''; } return $result; }
protected function parseWikitext($title, $newRevId) { $apiParams = array('action' => 'parse', 'page' => $title->getPrefixedDBkey(), 'oldid' => $newRevId, 'prop' => 'text|revid|categorieshtml|displaytitle|modules|jsconfigvars'); $api = new ApiMain(new DerivativeRequest($this->getRequest(), $apiParams, false), true); $api->execute(); if (defined('ApiResult::META_CONTENT')) { $result = $api->getResult()->getResultData(null, array('BC' => array(), 'Types' => array(), 'Strip' => 'all')); } else { $result = $api->getResultData(); } $content = isset($result['parse']['text']['*']) ? $result['parse']['text']['*'] : false; $categorieshtml = isset($result['parse']['categorieshtml']['*']) ? $result['parse']['categorieshtml']['*'] : false; $links = isset($result['parse']['links']) ? $result['parse']['links'] : array(); $revision = Revision::newFromId($result['parse']['revid']); $timestamp = $revision ? $revision->getTimestamp() : wfTimestampNow(); $displaytitle = isset($result['parse']['displaytitle']) ? $result['parse']['displaytitle'] : false; $modules = isset($result['parse']['modules']) ? $result['parse']['modules'] : array(); $jsconfigvars = isset($result['parse']['jsconfigvars']) ? $result['parse']['jsconfigvars'] : array(); if ($content === false || strlen($content) && $revision === null) { return false; } if ($displaytitle !== false) { // Escape entities as in OutputPage::setPageTitle() $displaytitle = Sanitizer::normalizeCharReferences(Sanitizer::removeHTMLtags($displaytitle)); } return array('content' => $content, 'categorieshtml' => $categorieshtml, 'basetimestamp' => $timestamp, 'starttimestamp' => wfTimestampNow(), 'displayTitleHtml' => $displaytitle, 'modules' => $modules, 'jsconfigvars' => $jsconfigvars); }
function formatResult($skin, $result) { global $wgContLang; # Make a link to the redirect itself $rd_title = Title::makeTitle($result->namespace, $result->title); $arr = $wgContLang->getArrow() . $wgContLang->getDirMark(); $rd_link = $skin->makeKnownLinkObj($rd_title, '', 'redirect=no'); # Find out where the redirect leads $revision = Revision::newFromTitle($rd_title); if ($revision) { # Make a link to the destination page $target = Title::newFromRedirect($revision->getText()); if ($target) { $targetLink = $skin->makeLinkObj($target); } else { /** @todo Put in some decent error display here */ $targetLink = '*'; } } else { /** @todo Put in some decent error display here */ $targetLink = '*'; } # Format the whole thing and return it return "{$rd_link} {$arr} {$targetLink}"; }
/** * ToC rendering for non-hubs * @param $title Title of hub the ToC is generated off * @return string html */ public function renderSubpageToC(Title $title) { $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer(); // We assume $title is sane. This is supposed to be called with a $title gotten from CollaborationHubContent::getParentHub, which already checks if it is. $rev = Revision::newFromTitle($title); $content = $rev->getContent(); $colour = $content->getThemeColour(); $image = $content->getImage(); $html = Html::openElement('div', ['class' => "mw-ck-theme-{$colour}"]); $html .= Html::openElement('div', ['class' => "mw-ck-subpage-toc"]); // ToC label $html .= Html::rawElement('div', ['class' => 'mw-ck-toc-label'], Html::rawElement('span', [], wfMessage('collaborationkit-subpage-toc-label')->inContentLanguage()->text())); // hubpage $name = $content->getDisplayName() == '' ? $title->getText() : $content->getDisplayName(); $link = $this->renderItem($title, $name, $image, 16); $html .= Html::rawElement('div', ['class' => 'mw-ck-toc-subpage-hub'], $link); // Contents $html .= Html::openElement('ul', ['class' => 'mw-ck-toc-contents']); foreach ($content->getContent() as $item) { $itemTitle = Title::newFromText($item['title']); if (isset($item['display_title'])) { $itemDisplayTitle = $item['display_title']; } else { $itemDisplayTitle = $itemTitle->getSubpageText(); } $itemImage = isset($item['image']) ? $item['image'] : $itemDisplayTitle; $itemLink = $this->renderItem($itemTitle, $itemDisplayTitle, $itemImage, $colour, 16); $html .= Html::rawElement('li', ['class' => 'mw-ck-toc-item'], $itemLink); } $html .= Html::closeElement('ul'); $html .= Html::closeElement('div'); $html .= Html::closeElement('div'); return $html; }
private function removeImagesFromArticle($articleId) { $title = Title::newFromID($articleId); if ($title) { $revision = Revision::newFromTitle($title); $text = $revision->getText(); //regular expressions copied out of maintenance/wikiphotoProcessImages.php //but modified to remove the leading BR tags if they exist //In the callback we keep track of each image name that we remove $text = preg_replace_callback('@(<\\s*br\\s*[\\/]?>)*\\s*\\[\\[Image:([^\\]]*)\\]\\]@im', function ($matches) { $image = $matches[2]; $pipeLoc = strpos($image, "|"); if ($pipeLoc !== false) { $image = substr($image, 0, $pipeLoc); } AdminImageRemoval::$imagesRemoved[] = $image; return ''; }, $text); $text = preg_replace_callback('@(<\\s*br\\s*[\\/]?>)*\\s*\\{\\{largeimage\\|([^\\}]*)\\}\\}@im', function ($matches) { $image = $matches[2]; AdminImageRemoval::$imagesRemoved[] = $image; return ''; }, $text); $text = preg_replace('@(<\\s*br\\s*[\\/]?>)*\\s*\\{\\{largeimage\\|[^\\}]*\\}\\}@im', '', $text); $article = new Article($title); $saved = $article->doEdit($text, 'Removing all images from article.'); } }
public function execute() { $this->output("Looking for pages with page_latest set to 0...\n"); $dbw = wfGetDB(DB_MASTER); $result = $dbw->select('page', array('page_id', 'page_namespace', 'page_title'), array('page_latest' => 0), __METHOD__); $n = 0; foreach ($result as $row) { $pageId = intval($row->page_id); $title = Title::makeTitle($row->page_namespace, $row->page_title); $name = $title->getPrefixedText(); $latestTime = $dbw->selectField('revision', 'MAX(rev_timestamp)', array('rev_page' => $pageId), __METHOD__); if (!$latestTime) { $this->output(wfWikiID() . " {$pageId} [[{$name}]] can't find latest rev time?!\n"); continue; } $revision = Revision::loadFromTimestamp($dbw, $title, $latestTime); if (is_null($revision)) { $this->output(wfWikiID() . " {$pageId} [[{$name}]] latest time {$latestTime}, can't find revision id\n"); continue; } $id = $revision->getId(); $this->output(wfWikiID() . " {$pageId} [[{$name}]] latest time {$latestTime}, rev id {$id}\n"); if ($this->hasOption('fix')) { $article = new Article($title); $article->updateRevisionOn($dbw, $revision); } $n++; } $dbw->freeResult($result); $this->output("Done! Processed {$n} pages.\n"); if (!$this->hasOption('fix')) { $this->output("This was a dry run; rerun with --fix to update page_latest.\n"); } }
/** * Run a refreshLinks job * @return boolean success */ function run() { global $wgParser; wfProfileIn(__METHOD__); $linkCache =& LinkCache::singleton(); $linkCache->clear(); if (is_null($this->title)) { $this->error = "refreshLinks: Invalid title"; wfProfileOut(__METHOD__); return false; } $revision = Revision::newFromTitle($this->title); if (!$revision) { $this->error = 'refreshLinks: Article not found "' . $this->title->getPrefixedDBkey() . '"'; wfProfileOut(__METHOD__); return false; } wfProfileIn(__METHOD__ . '-parse'); $options = new ParserOptions(); $parserOutput = $wgParser->parse($revision->getText(), $this->title, $options, true, true, $revision->getId()); wfProfileOut(__METHOD__ . '-parse'); wfProfileIn(__METHOD__ . '-update'); $update = new LinksUpdate($this->title, $parserOutput, false); $update->doUpdate(); wfProfileOut(__METHOD__ . '-update'); wfProfileOut(__METHOD__); return true; }
function displayQuickNoteButtons($id = '') { global $wgLanguageCode; // INTL: Only give these buttons to english site if ($wgLanguageCode != 'en') { return ""; } list($tb1, $tb2, $tb3) = QuickNoteEdit::getQNTemplates(); $start1 = strpos($tb1, "{{subst:") + strlen("{{subst:"); $end1 = strpos($tb1, "|") - strlen("{{subst:"); $tp1 = substr($tb1, $start1, $end1); $template = Title::makeTitle(NS_TEMPLATE, $tp1); $r = Revision::newFromTitle($template); $tb1_message = $r->getText(); $tb1_message = preg_replace('/<noinclude>(.*?)<\\/noinclude>/is', '', $tb1_message); $tb1_message = str_replace("\n", "\\n", $tb1_message); $tb1_message = str_replace("'", "\\'", $tb1_message); $start3 = strpos($tb3, "{{subst:") + strlen("{{subst:"); $end3 = strpos($tb3, "|") - strlen("{{subst:"); $tp3 = substr($tb3, $start3, $end3); $template = Title::makeTitle(NS_TEMPLATE, $tp3); $r = Revision::newFromTitle($template); $tb3_message = $r->getText(); $tb3_message = preg_replace('/<noinclude>(.*?)<\\/noinclude>/is', '', $tb3_message); $tb3_message = str_replace("\n", "\\n", $tb3_message); $tb3_message = str_replace("'", "\\'", $tb3_message); $buttons = "<div><br /><input tabindex='1' class='button secondary' type='button' value='" . wfMsg('Quicknote_Button1') . "' onclick=\"checkThumbsUp();qnButtons('postcommentForm_" . $id . "', '" . $tb1_message . "')\" />\n\t\t <input tabindex='3' class='button secondary' type='button' value='" . wfMsg('Quicknote_Button3') . "' onclick=\"qnButtons('postcommentForm_" . $id . "', '" . $tb3_message . "')\" /></div>"; return $buttons; }
private function handleImageFeedback() { global $wgRequest, $wgOut, $wgName, $wgUser; $dbw = wfGetDB(DB_MASTER); $reason = $wgRequest->getVal('reason'); // Remove / chars from reason since this will be our delimeter in the ii_reason field $reason = $dbw->strencode(trim(str_replace("/", "", $reason))); // Add user who reported $reason = $wgUser->getName() . " says: {$reason}"; $voteTypePrefix = $wgRequest->getVal('voteType') == 'good' ? 'ii_good' : 'ii_bad'; $aid = $dbw->addQuotes($wgRequest->getVal('aid')); $imgUrl = substr(trim($wgRequest->getVal('imgUrl')), 1); $isWikiPhotoImg = 0; // Check if image is a wikiphoto image $t = Title::newFromUrl($imgUrl); if ($t && $t->exists()) { $r = Revision::newFromTitle($t); $userText = $r->getUserText(); if (strtolower($r->getUserText()) == self::WIKIPHOTO_USER_NAME) { $isWikiPhotoImg = 1; } $url = substr($t->getLocalUrl(), 1); $voteField = $voteTypePrefix . "_votes"; $reasonField = $voteTypePrefix . "_reasons"; $sql = "INSERT INTO image_feedback \n\t\t\t\t(ii_img_page_id, ii_wikiphoto_img, ii_page_id, ii_img_url, {$voteField}, {$reasonField}) VALUES \n\t\t\t\t({$t->getArticleId()}, {$isWikiPhotoImg}, {$aid}, '{$url}', 1, '{$reason}') \n\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t{$voteField} = {$voteField} + 1, {$reasonField} = CONCAT({$reasonField}, '/{$reason}')"; $dbw->query($sql, __METHOD__); $wgOut->setArticleBodyOnly(true); } }
function getQueryInfo() { $conds = $this->mConds; $conds['rev_page'] = $this->articleID; $conds[] = "rev_timestamp < " . $this->mDb->addQuotes($this->maxTimestamp); return ['tables' => ['revision', 'page', 'user'], 'fields' => array_merge(Revision::selectFields(), Revision::selectUserFields()), 'conds' => $conds, 'join_conds' => ['page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond()]]; }
/** * @param IDatabase $db * @return mixed */ public function doQuery($db) { $ids = array_map('intval', $this->ids); $queryInfo = array('tables' => array('revision', 'user'), 'fields' => array_merge(Revision::selectFields(), Revision::selectUserFields()), 'conds' => array('rev_page' => $this->title->getArticleID(), 'rev_id' => $ids), 'options' => array('ORDER BY' => 'rev_id DESC'), 'join_conds' => array('page' => Revision::pageJoinCond(), 'user' => Revision::userJoinCond())); ChangeTags::modifyDisplayQuery($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], $queryInfo['join_conds'], $queryInfo['options'], ''); return $db->select($queryInfo['tables'], $queryInfo['fields'], $queryInfo['conds'], __METHOD__, $queryInfo['options'], $queryInfo['join_conds']); }
function getTopLevelCategories() { global $wgCategoriesArticle; wfLoadExtensionMessages('Sitemap'); $results = array(); $revision = Revision::newFromTitle(Title::newFromText(wfMsg('categories_article'))); if (!$revision) { return $results; } // INTL: If there is a redirect to a localized page name, follow it if (strpos($revision->getText(), "#REDIRECT") !== false) { $revision = Revision::newFromTitle(Title::newFromRedirect($revision->getText())); } $lines = split("\n", $revision->getText()); foreach ($lines as $line) { if (preg_match('/^\\*[^\\*]/', $line)) { $line = trim(substr($line, 1)); switch ($line) { case "Other": case "wikiHow": break; default: $results[] = $line; } } } return $results; }
/** * Patrols the article or provides the reason the patrol failed. */ public function execute() { $params = $this->extractRequestParams(); $this->requireOnlyOneParameter($params, 'rcid', 'revid'); if (isset($params['rcid'])) { $rc = RecentChange::newFromID($params['rcid']); if (!$rc) { $this->dieUsageMsg(array('nosuchrcid', $params['rcid'])); } } else { $rev = Revision::newFromId($params['revid']); if (!$rev) { $this->dieUsageMsg(array('nosuchrevid', $params['revid'])); } $rc = $rev->getRecentChange(); if (!$rc) { $this->dieUsage('The revision ' . $params['revid'] . " can't be patrolled as it's too old", 'notpatrollable'); } } $retval = $rc->doMarkPatrolled($this->getUser()); if ($retval) { $this->dieUsageMsg(reset($retval)); } $result = array('rcid' => intval($rc->getAttribute('rc_id'))); ApiQueryBase::addTitleInfo($result, $rc->getTitle()); $this->getResult()->addValue(null, $this->getModuleName(), $result); }
public static function articleCountWordDiff(&$article, &$user, $newText, $summary, $flag, $fake1, $fake2, &$flags, $revision, &$status, $baseRevId) { global $wgContentNamespaces, $wgSitename; wfProfileIn(__METHOD__); if (is_null($revision)) { // nothing's changed, quit early wfProfileOut(__METHOD__); return true; } if (!in_array($article->getTitle()->getNamespace(), $wgContentNamespaces)) { wfProfileOut(__METHOD__); return true; } // do not push reverts $baseRevision = Revision::newFromId($baseRevId); if ($baseRevision && $revision->getTextId() == $baseRevision->getTextId()) { wfProfileOut(__METHOD__); return true; } $diff = 0; $wNewCount = strlen($newText); $wOldCount = strlen($article->getRawText()); $countDiff = $wNewCount - $wOldCount; if ($countDiff > self::$MIN_CHARS_TO_PUSH) { $params = array('$ARTICLENAME' => $article->getTitle()->getText(), '$WIKINAME' => $wgSitename, '$ARTICLE_URL' => $article->getTitle()->getFullURL("ref=fbfeed&fbtype=largeedit"), '$EVENTIMG' => self::$eventImage, '$SUMMART' => $summary, '$TEXT' => self::shortenText(self::parseArticle($article, $newText))); self::pushEvent(self::$messageName, $params, __CLASS__); } wfProfileOut(__METHOD__); return true; }
function formatResult($skin, $result) { global $wgContLang; # Make a link to the redirect itself $rd_title = Title::makeTitle($result->namespace, $result->title); $rd_link = $skin->makeKnownLinkObj($rd_title, '', 'redirect=no'); # Find out where the redirect leads $revision = Revision::newFromTitle($rd_title); if ($revision) { # Make a link to the destination page $target = Title::newFromRedirect($revision->getText()); if ($target) { $targetLink = $skin->makeLinkObj($target); } else { /** @todo Put in some decent error display here */ $targetLink = '*'; } } else { /** @todo Put in some decent error display here */ $targetLink = '*'; } # Check the language; RTL wikis need a ← $arr = $wgContLang->isRTL() ? ' ← ' : ' → '; # Format the whole thing and return it return $rd_link . $arr . $targetLink; }
public function testHidingRevisions() { $user = self::$users['sysop']->getUser(); $revid = array_shift($this->revs); $out = $this->doApiRequest(array('action' => 'revisiondelete', 'type' => 'revision', 'target' => self::$page, 'ids' => $revid, 'hide' => 'content|user|comment', 'token' => $user->getEditToken())); // Check the output $out = $out[0]['revisiondelete']; $this->assertEquals($out['status'], 'Success'); $this->assertArrayHasKey('items', $out); $item = $out['items'][0]; $this->assertArrayHasKey('userhidden', $item); $this->assertArrayHasKey('commenthidden', $item); $this->assertArrayHasKey('texthidden', $item); $this->assertEquals($item['id'], $revid); // Now check that that revision was actually hidden $rev = Revision::newFromId($revid); $this->assertEquals($rev->getContent(Revision::FOR_PUBLIC), null); $this->assertEquals($rev->getComment(Revision::FOR_PUBLIC), ''); $this->assertEquals($rev->getUser(Revision::FOR_PUBLIC), 0); // Now test unhiding! $out2 = $this->doApiRequest(array('action' => 'revisiondelete', 'type' => 'revision', 'target' => self::$page, 'ids' => $revid, 'show' => 'content|user|comment', 'token' => $user->getEditToken())); // Check the output $out2 = $out2[0]['revisiondelete']; $this->assertEquals($out2['status'], 'Success'); $this->assertArrayHasKey('items', $out2); $item = $out2['items'][0]; $this->assertArrayNotHasKey('userhidden', $item); $this->assertArrayNotHasKey('commenthidden', $item); $this->assertArrayNotHasKey('texthidden', $item); $this->assertEquals($item['id'], $revid); $rev = Revision::newFromId($revid); $this->assertNotEquals($rev->getContent(Revision::FOR_PUBLIC), null); $this->assertNotEquals($rev->getComment(Revision::FOR_PUBLIC), ''); $this->assertNotEquals($rev->getUser(Revision::FOR_PUBLIC), 0); }
/** * Run job * @return boolean success */ function run() { wfProfileIn('SMWUpdateJob::run (SMW)'); global $wgParser; LinkCache::singleton()->clear(); if (is_null($this->title)) { $this->error = "SMWUpdateJob: Invalid title"; wfProfileOut('SMWUpdateJob::run (SMW)'); return false; } elseif (!$this->title->exists()) { smwfGetStore()->deleteSubject($this->title); // be sure to clear the data wfProfileOut('SMWUpdateJob::run (SMW)'); return true; } $revision = Revision::newFromTitle($this->title); if (!$revision) { $this->error = 'SMWUpdateJob: Page exists but no revision was found for "' . $this->title->getPrefixedDBkey() . '"'; wfProfileOut('SMWUpdateJob::run (SMW)'); return false; } wfProfileIn(__METHOD__ . '-parse'); $options = new ParserOptions(); $output = $wgParser->parse($revision->getText(), $this->title, $options, true, true, $revision->getID()); wfProfileOut(__METHOD__ . '-parse'); wfProfileIn(__METHOD__ . '-update'); SMWParseData::storeData($output, $this->title, false); wfProfileOut(__METHOD__ . '-update'); wfProfileOut('SMWUpdateJob::run (SMW)'); return true; }
protected function handleRow(stdClass $row) { $title = Title::makeTitle($row->page_namespace, $row->page_title); $this->output("Processing {$title} ({$row->page_id})...\n"); $rev = Revision::newFromTitle($title); $content = $rev->getContent(Revision::RAW); $dbw = $this->getDB(DB_MASTER); if ($content instanceof JsonContent) { if ($content->isValid()) { // Yay, actually JSON. We need to just change the // page_content_model because revision will automatically // use the default, which is *now* JSON. $this->output("Setting page_content_model to json..."); $dbw->update('page', ['page_content_model' => CONTENT_MODEL_JSON], ['page_id' => $row->page_id], __METHOD__); $this->output("done.\n"); wfWaitForSlaves(); } else { // Not JSON...force it to wikitext. We need to update the // revision table so that these revisions are always processed // as wikitext in the future. page_content_model is already // set to "wikitext". $this->output("Setting rev_content_model to wikitext..."); // Grab all the ids for batching $ids = $dbw->selectFieldValues('revision', 'rev_id', ['rev_page' => $row->page_id], __METHOD__); foreach (array_chunk($ids, 50) as $chunk) { $dbw->update('revision', ['rev_content_model' => CONTENT_MODEL_WIKITEXT], ['rev_page' => $row->page_id, 'rev_id' => $chunk]); wfWaitForSlaves(); } $this->output("done.\n"); } } else { $this->output("not a JSON page? Skipping\n"); } }
function getRepublishText($t) { global $wgRequest, $wgContLang, $wgOut, $wgServer; if (!$t) { return ""; } $r = Revision::newFromTitle($t); $mp = Title::newMainPage(); $title = "<h1 style='margin-bottom: 0px;'><a href=\"" . $t->getFullURL() . "\">" . wfMsg('howto', $t->getText()) . "</a></h1>\n" . wfMsg('republish_taglinelink', $mp->getFullURL()) . "<br/>"; if (!$r) { return ""; } $text = $r->getText(); if ($wgRequest->getVal('striptags', 'true') != 'false') { $text = preg_replace("/\\[\\[" . $wgContLang->getNSText(NS_IMAGE) . "[^\\]]*\\]\\]/", "", $text); } $output = $wgOut->parse($text); //$output = str_replace("<div class='SecL'></div><div class='SecR'></div>", "", $output); //$output = preg_replace("/<div id=\"[a-z]*\"/", "<div ", $output); $output = str_replace('href="/', 'href="' . $wgServer . '/', $output); if ($wgRequest->getVal('striptags', 'true') != 'false') { $output = strip_tags($output, '<b><i><h1><h2><ol><ul><li><a>'); } else { $output = str_replace('<img src="/', '<img src="http://www.wikihow.com/', $output); } $output = preg_replace("@href=(['\"])/@", "href=\$1{$wgServer}/", $output); $output = $title . "\n" . $output . wfMsg('republish_footer', $t->getText(), $t->getFullURL()); $output = preg_replace("/\n\n[\n]*/", "\n", $output); return $output; }
function smwf_et_Access($method, $params) { global $smwgQEnabled, $smwgExtTabEnabled; $result = "Semantic ExtTab disabled."; if ($method == "internalLoad") { if ($smwgExtTabEnabled) { $p = explode(',', $params, 2); $title = $p[1]; $html = $title; global $wgTitle, $smwgIQRunningNumber; // pay attention to $smwgIQRunningNumber $smwgIQRunningNumber = intval($p[0]) * 10; $wgTitle = Title::newFromText($title); $revision = Revision::newFromTitle($wgTitle); if ($revision !== NULL) { global $wgParser, $wgOut; $popts = $wgOut->parserOptions(); $popts->setTidy(true); $popts->enableLimitReport(); $html = $wgParser->parse($revision->getText(), $wgTitle, $popts)->getText(); } return $html; } } else { return "Operation failed, please retry later."; } return $result; }