/** * @since 2.0 * * @return boolean */ public function process() { // Avoid having "noarticletext" info being generated for predefined // properties as we are going to display an introductory text if ($this->article->getTitle()->getNamespace() === SMW_NS_PROPERTY) { return DIProperty::newFromUserLabel($this->article->getTitle()->getText())->isUserDefined(); } return true; }
public function __construct(Page $page) { if ($page instanceof Page) { $this->output = str_replace('{{ title }}', $page->getTitle(), $this->html); $this->output = str_replace('{{ description }}', $page->getDescription(), $this->output); } }
/** * Get template and image versions from parsing a revision * @param Page $article * @param Revision $rev * @param User $user * @param string $regen use 'regen' to force regeneration * @return array( templateIds, fileSHA1Keys ) * templateIds like ParserOutput->mTemplateIds * fileSHA1Keys like ParserOutput->mImageTimeKeys */ public static function getRevIncludes(Page $article, Revision $rev, User $user, $regen = '') { global $wgParser, $wgMemc; wfProfileIn(__METHOD__); $versions = false; $key = self::getCacheKey($article->getTitle(), $rev->getId()); if ($regen !== 'regen') { // check cache $versions = FlaggedRevs::getMemcValue($wgMemc->get($key), $article, 'allowStale'); } if (!is_array($versions)) { // cache miss $pOut = false; if ($rev->isCurrent()) { $parserCache = ParserCache::singleton(); # Try current version parser cache (as anon)... $pOut = $parserCache->get($article, $article->makeParserOptions($user)); if ($pOut == false && $rev->getUser()) { // try the user who saved the change $author = User::newFromId($rev->getUser()); $pOut = $parserCache->get($article, $article->makeParserOptions($author)); } } // ParserOutput::mImageTimeKeys wasn't always there if ($pOut == false || !FlaggedRevs::parserOutputIsVersioned($pOut)) { $title = $article->getTitle(); $pOpts = ParserOptions::newFromUser($user); // Note: tidy off $pOut = $wgParser->parse($rev->getText(), $title, $pOpts, true, true, $rev->getId()); } # Get the template/file versions used... $versions = array($pOut->getTemplateIds(), $pOut->getFileSearchOptions()); # Save to cache (check cache expiry for dynamic elements)... $data = FlaggedRevs::makeMemcObj($versions); $wgMemc->set($key, $data, $pOut->getCacheExpiry()); } else { $tVersions =& $versions[0]; // templates # Do a link batch query for page_latest... $lb = new LinkBatch(); foreach ($tVersions as $ns => $tmps) { foreach ($tmps as $dbKey => $revIdDraft) { $lb->add($ns, $dbKey); } } $lb->execute(); # Update array with the current page_latest values. # This kludge is there since $newTemplates (thus $revIdDraft) is cached. foreach ($tVersions as $ns => &$tmps) { foreach ($tmps as $dbKey => &$revIdDraft) { $title = Title::makeTitle($ns, $dbKey); $revIdDraft = (int) $title->getLatestRevID(); } } } wfProfileOut(__METHOD__); return $versions; }
/** * Get template and image versions from parsing a revision * @param Page $article * @param Revision $rev * @param User $user * @param string $regen use 'regen' to force regeneration * @return array( templateIds, fileSHA1Keys ) * templateIds like ParserOutput->mTemplateIds * fileSHA1Keys like ParserOutput->mImageTimeKeys */ public static function getRevIncludes(Page $article, Revision $rev, User $user, $regen = '') { global $wgMemc; wfProfileIn(__METHOD__); $key = self::getCacheKey($article->getTitle(), $rev->getId()); if ($regen === 'regen') { $versions = false; // skip cache } elseif ($rev->isCurrent()) { // Check cache entry against page_touched $versions = FlaggedRevs::getMemcValue($wgMemc->get($key), $article); } else { // Old revs won't always be invalidated with template/file changes. // Also, we don't care if page_touched changed due to a direct edit. $versions = FlaggedRevs::getMemcValue($wgMemc->get($key), $article, 'allowStale'); if (is_array($versions)) { // entry exists // Sanity check that the cache is reasonably up to date list($templates, $files) = $versions; if (self::templatesStale($templates) || self::filesStale($files)) { $versions = false; // no good } } } if (!is_array($versions)) { // cache miss $pOut = false; if ($rev->isCurrent()) { $parserCache = ParserCache::singleton(); # Try current version parser cache for this user... $pOut = $parserCache->get($article, $article->makeParserOptions($user)); if ($pOut == false) { # Try current version parser cache for the revision author... $optsUser = $rev->getUser() ? User::newFromId($rev->getUser()) : 'canonical'; $pOut = $parserCache->get($article, $article->makeParserOptions($optsUser)); } } // ParserOutput::mImageTimeKeys wasn't always there if ($pOut == false || !FlaggedRevs::parserOutputIsVersioned($pOut)) { $content = $rev->getContent(Revision::RAW); if (!$content) { // Just for extra sanity $pOut = new ParserOutput(); } else { $pOut = $content->getParserOutput($article->getTitle(), $rev->getId(), ParserOptions::newFromUser($user)); } } # Get the template/file versions used... $versions = array($pOut->getTemplateIds(), $pOut->getFileSearchOptions()); # Save to cache (check cache expiry for dynamic elements)... $data = FlaggedRevs::makeMemcObj($versions); $wgMemc->set($key, $data, $pOut->getCacheExpiry()); } wfProfileOut(__METHOD__); return $versions; }
/** * @param page Page * @return PageDto */ public function mapPageToDto(Page $page) { $pageDto = new PageDto(); $pageDto->setId($page->getId()); $pageDto->setTitle($page->getTitle()); $pageDto->setName($page->getName()); $pageDto->setDescription($page->getDescription()); $pageDto->setPosition($page->getPosition()); return $pageDto; }
public static function storePage(Page $page, $rootUrl) { $mysqli = self::connect(); $query = "INSERT INTO news_retriever_page (date, title, siteroot, pageurl, content) VALUES(?,?,?,?,?)"; $statement = $mysqli->prepare($query); $date = $page->getDate()->format('Y-m-d'); $title = $page->getTitle(); $content = $page->getPageAsHtml(); $statement->bind_param('sssss', $date, $title, $rootUrl, $page->getPageUrl(), $content); $statement->execute(); $mysqli->close(); }
/** * Adds a revision to a page, while returning the resuting revision's id * * @param $page WikiPage: page to add the revision to * @param $text string: revisions text * @param $text string: revisions summare * * @throws MWExcepion */ protected function addRevision(Page $page, $text, $summary) { $status = $page->doEditContent(ContentHandler::makeContent($text, $page->getTitle()), $summary); if ($status->isGood()) { $value = $status->getValue(); $revision = $value['revision']; $revision_id = $revision->getId(); $text_id = $revision->getTextId(); if ($revision_id > 0 && $text_id > 0) { return array($revision_id, $text_id); } } throw new MWException("Could not determine revision id (" . $status->getWikiText() . ")"); }
/** * Adds a revision to a page, while returning the resuting revision's id * * @param Page $page Page to add the revision to * @param string $text Revisions text * @param string $summary Revisions summary * @param string $model The model ID (defaults to wikitext) * * @throws MWException * @return array */ protected function addRevision(Page $page, $text, $summary, $model = CONTENT_MODEL_WIKITEXT) { $status = $page->doEditContent(ContentHandler::makeContent($text, $page->getTitle(), $model), $summary); if ($status->isGood()) { $value = $status->getValue(); $revision = $value['revision']; $revision_id = $revision->getId(); $text_id = $revision->getTextId(); if ($revision_id > 0 && $text_id > 0) { return [$revision_id, $text_id]; } } throw new MWException("Could not determine revision id (" . $status->getWikiText(false, false, 'en') . ")"); }
function __construct(Page $article) { global $wgUser; // Set instance variables. $this->mArticle = $article; $this->mTitle = $article->getTitle(); $this->mApplicableTypes = $this->mTitle->getRestrictionTypes(); // Check if the form should be disabled. // If it is, the form will be available in read-only to show levels. $this->mPermErrors = $this->mTitle->getUserPermissionsErrors('protect', $wgUser); $this->disabled = wfReadOnly() || $this->mPermErrors != array(); $this->disabledAttrib = $this->disabled ? array('disabled' => 'disabled') : array(); $this->loadData(); }
/** * @return bool */ public function doWork() { global $wgUseFileCache; // @todo several of the methods called on $this->page are not declared in Page, but present // in WikiPage and delegated by Article. $isCurrent = $this->revid === $this->page->getLatest(); if ($this->content !== null) { $content = $this->content; } elseif ($isCurrent) { // XXX: why use RAW audience here, and PUBLIC (default) below? $content = $this->page->getContent(Revision::RAW); } else { $rev = Revision::newFromTitle($this->page->getTitle(), $this->revid); if ($rev === null) { $content = null; } else { // XXX: why use PUBLIC audience here (default), and RAW above? $content = $rev->getContent(); } } if ($content === null) { return false; } // Reduce effects of race conditions for slow parses (bug 46014) $cacheTime = wfTimestampNow(); $time = -microtime(true); $this->parserOutput = $content->getParserOutput($this->page->getTitle(), $this->revid, $this->parserOptions); $time += microtime(true); // Timing hack if ($time > 3) { // TODO: Use Parser's logger (once it has one) $logger = MediaWiki\Logger\LoggerFactory::getInstance('slow-parse'); $logger->info('{time} {title}', array('time' => number_format($time, 2), 'title' => $this->page->getTitle()->getPrefixedDBkey())); } if ($this->cacheable && $this->parserOutput->isCacheable() && $isCurrent) { ParserCache::singleton()->save($this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid); } // Make sure file cache is not used on uncacheable content. // Output that has magic words in it can still use the parser cache // (if enabled), though it will generally expire sooner. if (!$this->parserOutput->isCacheable()) { $wgUseFileCache = false; } if ($isCurrent) { $this->page->triggerOpportunisticLinksUpdate($this->parserOutput); } return true; }
/** * @return bool */ public function doWork() { global $wgUseFileCache; // @todo several of the methods called on $this->page are not declared in Page, but present // in WikiPage and delegated by Article. $isCurrent = $this->revid === $this->page->getLatest(); if ($this->content !== null) { $content = $this->content; } elseif ($isCurrent) { // XXX: why use RAW audience here, and PUBLIC (default) below? $content = $this->page->getContent(Revision::RAW); } else { $rev = Revision::newFromTitle($this->page->getTitle(), $this->revid); if ($rev === null) { $content = null; } else { // XXX: why use PUBLIC audience here (default), and RAW above? $content = $rev->getContent(); } } if ($content === null) { return false; } // Reduce effects of race conditions for slow parses (bug 46014) $cacheTime = wfTimestampNow(); $time = -microtime(true); $this->parserOutput = $content->getParserOutput($this->page->getTitle(), $this->revid, $this->parserOptions); $time += microtime(true); // Timing hack if ($time > 3) { wfDebugLog('slow-parse', sprintf("%-5.2f %s", $time, $this->page->getTitle()->getPrefixedDBkey())); } if ($this->cacheable && $this->parserOutput->isCacheable() && $isCurrent) { ParserCache::singleton()->save($this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid); } // Make sure file cache is not used on uncacheable content. // Output that has magic words in it can still use the parser cache // (if enabled), though it will generally expire sooner. if (!$this->parserOutput->isCacheable() || $this->parserOutput->containsOldMagic()) { $wgUseFileCache = false; } if ($isCurrent) { $this->page->doCascadeProtectionUpdates($this->parserOutput); } return true; }
/** * @param Page $page */ public function render(Page $page) { $this->config = $page->getConfig(); $header = '<!DOCTYPE html>' . PHP_EOL; $header .= '<html >' . PHP_EOL; $header .= '<head lang = "en">' . PHP_EOL; $header .= '<meta charset = "UTF-8">' . PHP_EOL; $header .= '<meta name = "viewport" content = "initial-scale=1.0"/>' . PHP_EOL; $style_sheets = array_merge($this->config->getGlobalStyleSheets(), $page->getStyleSheets()); foreach ($style_sheets as $style_sheet) { $header .= '<link href="' . $this->getStyleSheetPath($style_sheet) . '" type="text/css" rel="stylesheet">' . PHP_EOL; } $java_scripts = array_merge($this->config->getGlobalJavaScripts(), $page->getJavaScripts()); foreach ($java_scripts as $java_script) { $header .= '<script src="' . $this->getJavaScriptPath($java_script) . '" type="text/JavaScript"></script>' . PHP_EOL; } $header .= '<title>' . $page->getTitle() . '</title>' . PHP_EOL; $header .= '</head>' . PHP_EOL; $header .= '<body>' . PHP_EOL; echo $header; }
function estetico_vision_func($atts) { extract(shortcode_atts(array("title" => "", "content_text" => "", "icon" => "", "custom_icon" => null, "content_pull" => null, "page_id" => null), $atts)); if ($content_pull == "current_pages" && $page_id != null) { try { $page = new Page($page_id); $title = !empty($title) ? $title : $page->getTitle(); $content_text = !empty($content_text) ? $content_text : $page->getExcerpt(); } catch (Exception $ex) { } } if ($custom_icon) { $custom_icon = wp_get_attachment_image($custom_icon, array(70, 70), true); $icon = 'custom-icon'; } $output = ''; $output .= '<div class="vision">'; $output .= '<b class="icon rounded ' . $icon . '">' . $custom_icon . '</b>'; $output .= '<h6>' . $title . '</h6>'; $output .= '<p>' . $content_text . '</p>'; $output .= '</div>'; return $output; }
$s = new Page($title); // adding to ttcs.tex if ($s->discussion != '') { $ttcsTex .= '\\ttcdwiki{' . $pureTitle . '}' . PHP_EOL; } else { if ($s->technologies != '') { $ttcsTex .= '\\ttcdtwiki{' . $pureTitle . '}' . PHP_EOL; } else { $ttcsTex .= '\\ttcwiki{' . $pureTitle . '}' . PHP_EOL; } } $fTtcMacro = fopen($ttcsFolder . $ttcTexTit, 'w+'); echo 'Saving macro for "' . $title . '"... '; $ttcMacroTex = $s->toTexMacro(); $ttcMacroTex = formatter::intLinks($ttcMacroTex, $titles); $ttcMacroTex .= "\\newcommand{\\" . str_replace('_', '', str_replace(' ', '', $s->getTitle())) . "TtcLabel}{" . str_replace('_', '', str_replace(' ', '', $s->getTitle())) . "}" . PHP_EOL; //var_dump($links); fwrite($fTtcMacro, $ttcMacroTex); fclose($fTtcMacro); echo 'DONE' . PHP_EOL; echo 'Getting BibTex... '; foreach ($s->bibs as $bib) { $newbib = ''; $i = 0; foreach (preg_split('/\\r\\n|\\r|\\n/', $bib) as $bibline) { if ($i != 0 && startsWith('title', ltrim($bibline))) { $bibline = preg_replace('/([A-Z]+)/', '{\\1}', $bibline); } $newbib .= $bibline . PHP_EOL; $i += 1; }
/** * Shortcut to get the Title object from the page * @return Title */ final public function getTitle() { return $this->page->getTitle(); }
/** * Attempt to cache PST content and corresponding parser output in passing * * This method can be called when the output was already generated for other * reasons. Parsing should not be done just to call this method, however. * $pstOpts must be that of the user doing the edit preview. If $pOpts does * not match the options of WikiPage::makeParserOptions( 'canonical' ), this * will do nothing. Provided the values are cacheable, they will be stored * in memcached so that final edit submission might make use of them. * * @param Article|WikiPage $page Page title * @param Content $content Proposed page content * @param Content $pstContent The result of preSaveTransform() on $content * @param ParserOutput $pOut The result of getParserOutput() on $pstContent * @param ParserOptions $pstOpts Options for $pstContent (MUST be for prospective author) * @param ParserOptions $pOpts Options for $pOut * @param string $timestamp TS_MW timestamp of parser output generation * @return bool Success */ public static function stashEditFromPreview(Page $page, Content $content, Content $pstContent, ParserOutput $pOut, ParserOptions $pstOpts, ParserOptions $pOpts, $timestamp) { global $wgMemc; // getIsPreview() controls parser function behavior that references things // like user/revision that don't exists yet. The user/text should already // be set correctly by callers, just double check the preview flag. if (!$pOpts->getIsPreview()) { return false; // sanity } elseif ($pOpts->getIsSectionPreview()) { return false; // short-circuit (need the full content) } // PST parser options are for the user (handles signatures, etc...) $user = $pstOpts->getUser(); // Get a key based on the source text, format, and user preferences $key = self::getStashKey($page->getTitle(), $content, $user); // Parser output options must match cannonical options. // Treat some options as matching that are different but don't matter. $canonicalPOpts = $page->makeParserOptions('canonical'); $canonicalPOpts->setIsPreview(true); // force match $canonicalPOpts->setTimestamp($pOpts->getTimestamp()); // force match if (!$pOpts->matches($canonicalPOpts)) { wfDebugLog('StashEdit', "Uncacheable preview output for key '{$key}' (options)."); return false; } // Build a value to cache with a proper TTL list($stashInfo, $ttl) = self::buildStashValue($pstContent, $pOut, $timestamp); if (!$stashInfo) { wfDebugLog('StashEdit', "Uncacheable parser output for key '{$key}' (rev/TTL)."); return false; } $ok = $wgMemc->set($key, $stashInfo, $ttl); if (!$ok) { wfDebugLog('StashEdit', "Failed to cache preview parser output for key '{$key}'."); } else { wfDebugLog('StashEdit', "Cached preview output for key '{$key}'."); } return $ok; }
/** * Add a required page * @param Page $page */ public function addRequiredPage(Page $page) { if (!$page->isGlobal()) { throw new \Jazzee\Exception("{$page->getTitle()} (#{$page->getId()}) is not a global page and cannot be a required page for a cycle"); } $this->requiredPages[] = $page; }
/** * Returns page counts that would be too "expensive" to retrieve by normal means. * * @param WikiPage|Article|Page $page * @return array */ protected function pageCounts(Page $page) { $fname = __METHOD__; $config = $this->context->getConfig(); return ObjectCache::getMainWANInstance()->getWithSetCallback(self::getCacheKey($page->getTitle(), $page->getLatest()), WANObjectCache::TTL_WEEK, function ($oldValue, &$ttl, &$setOpts) use($page, $config, $fname) { $title = $page->getTitle(); $id = $title->getArticleID(); $dbr = wfGetDB(DB_REPLICA); $dbrWatchlist = wfGetDB(DB_REPLICA, 'watchlist'); $setOpts += Database::getCacheSetOptions($dbr, $dbrWatchlist); $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore(); $result = []; $result['watchers'] = $watchedItemStore->countWatchers($title); if ($config->get('ShowUpdatedMarker')) { $updated = wfTimestamp(TS_UNIX, $page->getTimestamp()); $result['visitingWatchers'] = $watchedItemStore->countVisitingWatchers($title, $updated - $config->get('WatchersMaxAge')); } // Total number of edits $edits = (int) $dbr->selectField('revision', 'COUNT(*)', ['rev_page' => $id], $fname); $result['edits'] = $edits; // Total number of distinct authors if ($config->get('MiserMode')) { $result['authors'] = 0; } else { $result['authors'] = (int) $dbr->selectField('revision', 'COUNT(DISTINCT rev_user_text)', ['rev_page' => $id], $fname); } // "Recent" threshold defined by RCMaxAge setting $threshold = $dbr->timestamp(time() - $config->get('RCMaxAge')); // Recent number of edits $edits = (int) $dbr->selectField('revision', 'COUNT(rev_page)', ['rev_page' => $id, "rev_timestamp >= " . $dbr->addQuotes($threshold)], $fname); $result['recent_edits'] = $edits; // Recent number of distinct authors $result['recent_authors'] = (int) $dbr->selectField('revision', 'COUNT(DISTINCT rev_user_text)', ['rev_page' => $id, "rev_timestamp >= " . $dbr->addQuotes($threshold)], $fname); // Subpages (if enabled) if (MWNamespace::hasSubpages($title->getNamespace())) { $conds = ['page_namespace' => $title->getNamespace()]; $conds[] = 'page_title ' . $dbr->buildLike($title->getDBkey() . '/', $dbr->anyString()); // Subpages of this page (redirects) $conds['page_is_redirect'] = 1; $result['subpages']['redirects'] = (int) $dbr->selectField('page', 'COUNT(page_id)', $conds, $fname); // Subpages of this page (non-redirects) $conds['page_is_redirect'] = 0; $result['subpages']['nonredirects'] = (int) $dbr->selectField('page', 'COUNT(page_id)', $conds, $fname); // Subpages of this page (total) $result['subpages']['total'] = $result['subpages']['redirects'] + $result['subpages']['nonredirects']; } // Counts for the number of transclusion links (to/from) if ($config->get('MiserMode')) { $result['transclusion']['to'] = 0; } else { $result['transclusion']['to'] = (int) $dbr->selectField('templatelinks', 'COUNT(tl_from)', ['tl_namespace' => $title->getNamespace(), 'tl_title' => $title->getDBkey()], $fname); } $result['transclusion']['from'] = (int) $dbr->selectField('templatelinks', 'COUNT(*)', ['tl_from' => $title->getArticleID()], $fname); return $result; }); }
<?php printPageContent(); printCodeblock(1); $subpages = $_zp_current_page->getPages(); if ($subpages) { ?> <ul data-role="listview" data-inset="true" data-theme="a" class="ui-listview ui-group-theme-a"> <?php foreach ($subpages as $subpage) { $obj = new Page($subpage['titlelink']); ?> <li><a href="<?php echo html_encode($obj->getLink()); ?> " title="<?php echo html_encode($obj->getTitle()); ?> "><?php echo html_encode($obj->getTitle()); ?> </a></li> <?php } ?> </ul> <?php } printTags('links', gettext('<strong>Tags:</strong>') . ' ', 'taglist', ', '); ?> <?php if (function_exists('printCommentForm')) {
} else { echo "Add page"; } ?> </span> <a href="#" id="properties" class="activeLinkInAdd">Properties</a> <a href="#" id="seo">SEO</a> </th> </tr> </thead> <tbody class="properties" style="display:table-header-group;"> <tr> <td>Title:</td> <td><input type="text" placeholder="Title for the browser title bar" class="validatedInput" name="title" value="<?php if (isset($_GET['code'])) { echo $pageToEdit->getTitle(); } ?> "></td> </tr> <tr> <td>Navigation Name :</td> <td><input type="text" placeholder="Page name for displaying in navigation" class="validatedInput" name="pageName" value="<?php if (isset($_GET['code'])) { echo $pageToEdit->getPageName(); } ?> "></td> </tr> <tr> <td>Page Layout :</td>
public function testSetAndGetTitleShouldProduceValidPage() { $page = new Page(); $title = 'asdjkASDFSnsbdifbs'; $page->setTitle($title); $this->assertEquals($title, $page->getTitle()); $this->assertTrue($page->isValid()); }
<!DOCTYPE html> <html id="root" lang="<?php echo $page->getLang(); ?> " prefix="<?php echo $page->getNamespaces(); ?> "> <head> <!--[if (IE 9)&!(IEMobile)]><meta http-equiv="X-UA-Compatible" content="IE=9"/><![endif]--> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width,maximum-scale=1,user-scalable=no"/> <title><?php echo $page->getTitle(); ?> </title> <meta name="keywords" content="<?php echo $page->getKeywords(); ?> "/> <meta name="description" content="<?php echo $page->getDescription(); ?> "/> <meta name="robots" content="all"/> <meta name="revisit-after" content="7 days"/> <meta name="format-detection" content="telephone=no"/> <meta name="SKYPE_TOOLBAR" content="SKYPE_TOOLBAR_PARSER_COMPATIBLE"/>
/** * @param Page $article * @param parserOutput $stableOut * Updates the stable-only cache dependency table */ public static function updateStableOnlyDeps(Page $article, ParserOutput $stableOut) { wfProfileIn(__METHOD__); if (!wfReadOnly()) { $frDepUpdate = new FRDependencyUpdate($article->getTitle(), $stableOut); $frDepUpdate->doUpdate(); } wfProfileOut(__METHOD__); }
/** * Returns page counts that would be too "expensive" to retrieve by normal means. * * @param WikiPage|Article|Page $page * @return array */ protected function pageCounts(Page $page) { $fname = __METHOD__; $config = $this->context->getConfig(); return ObjectCache::getMainWANInstance()->getWithSetCallback(self::getCacheKey($page->getTitle(), $page->getLatest()), 86400 * 7, function ($oldValue, &$ttl, &$setOpts) use($page, $config, $fname) { $title = $page->getTitle(); $id = $title->getArticleID(); $dbr = wfGetDB(DB_SLAVE); $dbrWatchlist = wfGetDB(DB_SLAVE, 'watchlist'); $setOpts += Database::getCacheSetOptions($dbr, $dbrWatchlist); $result = array(); // Number of page watchers $watchers = (int) $dbrWatchlist->selectField('watchlist', 'COUNT(*)', array('wl_namespace' => $title->getNamespace(), 'wl_title' => $title->getDBkey()), $fname); $result['watchers'] = $watchers; if ($config->get('ShowUpdatedMarker')) { // Threshold: last visited about 26 weeks before latest edit $updated = wfTimestamp(TS_UNIX, $page->getTimestamp()); $age = $config->get('WatchersMaxAge'); $threshold = $dbrWatchlist->timestamp($updated - $age); // Number of page watchers who also visited a "recent" edit $visitingWatchers = (int) $dbrWatchlist->selectField('watchlist', 'COUNT(*)', array('wl_namespace' => $title->getNamespace(), 'wl_title' => $title->getDBkey(), 'wl_notificationtimestamp >= ' . $dbrWatchlist->addQuotes($threshold) . ' OR wl_notificationtimestamp IS NULL'), $fname); $result['visitingWatchers'] = $visitingWatchers; } // Total number of edits $edits = (int) $dbr->selectField('revision', 'COUNT(*)', array('rev_page' => $id), $fname); $result['edits'] = $edits; // Total number of distinct authors if ($config->get('MiserMode')) { $result['authors'] = 0; } else { $result['authors'] = (int) $dbr->selectField('revision', 'COUNT(DISTINCT rev_user_text)', array('rev_page' => $id), $fname); } // "Recent" threshold defined by RCMaxAge setting $threshold = $dbr->timestamp(time() - $config->get('RCMaxAge')); // Recent number of edits $edits = (int) $dbr->selectField('revision', 'COUNT(rev_page)', array('rev_page' => $id, "rev_timestamp >= " . $dbr->addQuotes($threshold)), $fname); $result['recent_edits'] = $edits; // Recent number of distinct authors $result['recent_authors'] = (int) $dbr->selectField('revision', 'COUNT(DISTINCT rev_user_text)', array('rev_page' => $id, "rev_timestamp >= " . $dbr->addQuotes($threshold)), $fname); // Subpages (if enabled) if (MWNamespace::hasSubpages($title->getNamespace())) { $conds = array('page_namespace' => $title->getNamespace()); $conds[] = 'page_title ' . $dbr->buildLike($title->getDBkey() . '/', $dbr->anyString()); // Subpages of this page (redirects) $conds['page_is_redirect'] = 1; $result['subpages']['redirects'] = (int) $dbr->selectField('page', 'COUNT(page_id)', $conds, $fname); // Subpages of this page (non-redirects) $conds['page_is_redirect'] = 0; $result['subpages']['nonredirects'] = (int) $dbr->selectField('page', 'COUNT(page_id)', $conds, $fname); // Subpages of this page (total) $result['subpages']['total'] = $result['subpages']['redirects'] + $result['subpages']['nonredirects']; } // Counts for the number of transclusion links (to/from) if ($config->get('MiserMode')) { $result['transclusion']['to'] = 0; } else { $result['transclusion']['to'] = (int) $dbr->selectField('templatelinks', 'COUNT(tl_from)', array('tl_namespace' => $title->getNamespace(), 'tl_title' => $title->getDBkey()), $fname); } $result['transclusion']['from'] = (int) $dbr->selectField('templatelinks', 'COUNT(*)', array('tl_from' => $title->getArticleID()), $fname); return $result; }); }
exit; } $page = null; $view->setTitle("Viewing Page"); try { $page = new Page($id); } catch (Exception $e) { if ($e->getCode() == PAGE_NOT_EXIST) { header("Location: " . orongoURL("orongo-admin/manage.php?msg=0&obj=pages")); exit; } else { header("Location: " . orongoURL("orongo-admin/index.php?msg=2")); exit; } } $form = new AdminFrontendForm(100, l("Page") . ": " . $page->getTitle(), "GET", "", false); $form->addInput("ID", "id", "text", $page->getID(), false, true); $form->addInput("Page Title", "title", "text", $page->getTitle(), false, true); $form->addInput("Page Content", "content", "ckeditor", $page->getContent(), false, true); $form->addButton("Delete", false, orongoURL("orongo-admin/delete.php?page." . $id)); $form->addButton("Edit", false, orongoURL("orongo-admin/edit.php?page." . $id)); $view->addObject($form); $view->render(); break; case "user": if ($id != getUser()->getID() && getUser()->getRank() != RANK_ADMIN) { header("Location: " . orongoURL("orongo-admin/index.php?msg=0")); exit; } $user = null; $view->setTitle("Viewing User");
/** * Automatically review an revision and add a log entry in the review log. * * This is called during edit operations after the new revision is added * and the page tables updated, but before LinksUpdate is called. * * $auto is here for revisions checked off to be reviewed. Auto-review * triggers on edit, but we don't want those to count as just automatic. * This also makes it so the user's name shows up in the page history. * * If $flags is given, then they will be the review tags. If not, the one * from the stable version will be used or minimal tags if that's not possible. * If no appropriate tags can be found, then the review will abort. */ public static function autoReviewEdit(Page $article, $user, Revision $rev, array $flags = null, $auto = true) { wfProfileIn(__METHOD__); $title = $article->getTitle(); // convenience # Get current stable version ID (for logging) $oldSv = FlaggedRevision::newFromStable($title, FR_MASTER); $oldSvId = $oldSv ? $oldSv->getRevId() : 0; # Set the auto-review tags from the prior stable version. # Normally, this should already be done and given here... if (!is_array($flags)) { if ($oldSv) { # Use the last stable version if $flags not given if ($user->isAllowed('bot')) { $flags = $oldSv->getTags(); // no change for bot edits } else { # Account for perms/tags... $flags = self::getAutoReviewTags($user, $oldSv->getTags()); } } else { // new page? $flags = self::quickTags(FR_CHECKED); // use minimal level } if (!is_array($flags)) { wfProfileOut(__METHOD__); return false; // can't auto-review this revision } } # Get review property flags $propFlags = $auto ? array('auto') : array(); # Rev ID is not put into parser on edit, so do the same here. # Also, a second parse would be triggered otherwise. $editInfo = $article->prepareTextForEdit($rev->getText()); $poutput = $editInfo->output; // revision HTML output # If this is an image page, store corresponding file info $fileData = array('name' => null, 'timestamp' => null, 'sha1' => null); if ($title->getNamespace() == NS_FILE) { # We must use WikiFilePage process cache on upload or get bitten by slave lag $file = $article instanceof WikiFilePage || $article instanceof ImagePage ? $article->getFile() : wfFindFile($title, array('bypassCache' => true)); // skip cache; bug 31056 if (is_object($file) && $file->exists()) { $fileData['name'] = $title->getDBkey(); $fileData['timestamp'] = $file->getTimestamp(); $fileData['sha1'] = $file->getSha1(); } } # Our review entry $flaggedRevision = new FlaggedRevision(array('rev' => $rev, 'user_id' => $user->getId(), 'timestamp' => $rev->getTimestamp(), 'quality' => FlaggedRevs::getQualityTier($flags, 0), 'tags' => FlaggedRevision::flattenRevisionTags($flags), 'img_name' => $fileData['name'], 'img_timestamp' => $fileData['timestamp'], 'img_sha1' => $fileData['sha1'], 'templateVersions' => $poutput->getTemplateIds(), 'fileVersions' => $poutput->getFileSearchOptions(), 'flags' => implode(',', $propFlags))); $flaggedRevision->insert(); # Update the article review log FlaggedRevsLog::updateReviewLog($title, $flags, array(), '', $rev->getId(), $oldSvId, true, $auto); # Update page and tracking tables and clear cache FlaggedRevs::stableVersionUpdates($title); wfProfileOut(__METHOD__); return true; }
/** * @param $page WikiPage object to work on * @param $user User doing the action * @param $token * @param $oldimage * @param $reason * @param $suppress bool * @return \type|array|Title */ public static function deleteFile(Page $page, User $user, $token, $oldimage, &$reason = null, $suppress = false) { $title = $page->getTitle(); $errors = self::getPermissionsError($title, $user, $token); if (count($errors)) { return $errors; } $file = $page->getFile(); if (!$file->exists() || !$file->isLocal() || $file->getRedirected()) { return self::delete($page, $user, $token, $reason); } if ($oldimage) { if (!FileDeleteForm::isValidOldSpec($oldimage)) { return array(array('invalidoldimage')); } $oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName($title, $oldimage); if (!$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected()) { return array(array('nodeleteablefile')); } } else { $oldfile = false; } if (is_null($reason)) { // Log and RC don't like null reasons $reason = ''; } $status = FileDeleteForm::doDelete($title, $file, $oldimage, $reason, $suppress); if (!$status->isGood()) { return array(array('cannotdelete', $title->getPrefixedText())); } return array(); }
/** * Hook function for PageContentSaveComplete * Clear local spam blacklist caches on page save. * * @param Page $wikiPage * @param User $user * @param Content $content * @param string $summary * @param bool $isMinor * @param bool $isWatch * @param string $section * @param int $flags * @param int $revision * @param Status $status * @param int $baseRevId * * @return bool */ static function pageSaveContent(Page $wikiPage, User $user, Content $content, $summary, $isMinor, $isWatch, $section, $flags, $revision, Status $status, $baseRevId) { if (!BaseBlacklist::isLocalSource($wikiPage->getTitle())) { return true; } global $wgMemc, $wgDBname; // This sucks because every Blacklist needs to be cleared foreach (BaseBlacklist::getBlacklistTypes() as $type => $class) { $wgMemc->delete("{$wgDBname}:{$type}_blacklist_regexes"); } return true; }
/** * @param Page $page Object to work on * @param User $user User doing the action * @param string $oldimage Archive name * @param string $reason Reason for the deletion. Autogenerated if null. * @param bool $suppress Whether to mark all deleted versions as restricted * @return Status|array */ protected static function deleteFile(Page $page, User $user, $oldimage, &$reason = null, $suppress = false) { $title = $page->getTitle(); $file = $page->getFile(); if (!$file->exists() || !$file->isLocal() || $file->getRedirected()) { return self::delete($page, $user, $reason); } if ($oldimage) { if (!FileDeleteForm::isValidOldSpec($oldimage)) { return array(array('invalidoldimage')); } $oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName($title, $oldimage); if (!$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected()) { return array(array('nodeleteablefile')); } } if (is_null($reason)) { // Log and RC don't like null reasons $reason = ''; } return FileDeleteForm::doDelete($title, $file, $oldimage, $reason, $suppress, $user); }
/** * Deletes the form definition associated with the given wiki page * from the main cache. * * Hooks: ArticlePurge, ArticleSave * * @param Page $wikipage * @return bool */ public static function purgeCache(Page $wikipage) { if (!$wikipage->getTitle()->inNamespace(SF_NS_FORM)) { return true; } $cache = self::getFormCache(); $cacheKeyForList = self::getCacheKey($wikipage->getId()); // get references to stored datasets $listOfFormKeys = $cache->get($cacheKeyForList); if (!is_array($listOfFormKeys)) { return true; } // delete stored datasets foreach ($listOfFormKeys as $key) { $cache->delete($key); wfDebug("Deleted cached form definition {$key}.\n"); } // delete references to datasets $cache->delete($cacheKeyForList); wfDebug("Deleted cached form definition references {$cacheKeyForList}.\n"); return true; }