当前位置: 首页>>代码示例>>PHP>>正文


PHP Article::newFromTitle方法代码示例

本文整理汇总了PHP中Article::newFromTitle方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::newFromTitle方法的具体用法?PHP Article::newFromTitle怎么用?PHP Article::newFromTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Article的用法示例。


在下文中一共展示了Article::newFromTitle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getDetails

 protected function getDetails()
 {
     $article = \Article::newFromTitle($this->commentTitle, \RequestContext::getMain());
     $service = new \ArticleService($article);
     $snippet = $service->getTextSnippet();
     return $snippet;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:7,代码来源:CommentController.class.php

示例2: purgeMainPage

 public static function purgeMainPage($args)
 {
     if ($args['name'] === 'wgEnableNjordExt') {
         Article::newFromTitle(Title::newFromText(self::MAINPAGE_PAGE), RequestContext::getMain())->doPurge();
     }
     return true;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:7,代码来源:NjordHooks.class.php

示例3: wfTalkHereAjaxEditor

function wfTalkHereAjaxEditor( $page, $section, $returnto ) {
	global $wgRequest, $wgTitle, $wgOut;

	$title = Title::newFromText( $page );
	if ( !$title ) {
		return false;
	}

	//fake editor environment
	$args = array(
		'wpTalkHere' => '1',
		'wpReturnTo' => $returnto,
		'action' => 'edit',
		'section' => $section
	);

	$wgRequest = new FauxRequest( $args );
	$wgTitle = $title;

	$article = Article::newFromTitle( $title, RequestContext::getMain() );
	$editor = new TalkHereEditPage( $article );

	//generate form
	$editor->importFormData( $wgRequest );
	$editor->showEditForm();

	$response = new AjaxResponse();
	$response->addText( $wgOut->getHTML() );
	$response->setCacheDuration( false ); //don't cache, because of tokens etc

	return $response;
}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:32,代码来源:TalkHere.php

示例4: runOnPageSet

 protected function runOnPageSet(ApiPageSet $pageSet)
 {
     $articles = array_map(function (Title $item) {
         return Article::newFromTitle($item, RequestContext::getMain());
     }, $pageSet->getGoodTitles());
     /**
      * @var Article $article
      */
     foreach ($articles as $id => $article) {
         $d = $article->getParserOutput()->getProperty(PortableInfoboxDataService::INFOBOXES_PROPERTY_NAME);
         if (is_array($d)) {
             $inf = [];
             foreach (array_keys($d) as $k => $v) {
                 $inf[$k] = [];
             }
             $pageSet->getResult()->setIndexedTagName($inf, 'infobox');
             $pageSet->getResult()->addValue(['query', 'pages', $id], 'infoboxes', $inf);
             foreach ($d as $count => $infobox) {
                 $s = isset($infobox['sources']) ? $infobox['sources'] : [];
                 $pageSet->getResult()->addValue(['query', 'pages', $id, 'infoboxes', $count], 'id', $count);
                 $pageSet->getResult()->setIndexedTagName($s, "source");
                 $pageSet->getResult()->addValue(['query', 'pages', $id, 'infoboxes', $count], 'sources', $s);
             }
         }
     }
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:26,代码来源:ApiQueryPortableInfobox.class.php

示例5: getDetails

 protected function getDetails()
 {
     $article = \Article::newFromTitle($this->postTitle, \RequestContext::getMain());
     $service = new \ArticleService($article);
     // Include +3 characters here for the ellipsis added when we have to truncate
     $snippet = $service->getTextSnippet($length = 303, $breakLimit = 500);
     return $snippet;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:8,代码来源:BlogPostController.class.php

示例6: getData

 /**
  * Returns infobox data
  *
  * @return array in format [ 'data' => [], 'sources' => [] ] or [] will be returned
  */
 public function getData()
 {
     if ($this->title && $this->title->exists()) {
         $parserOutput = Article::newFromTitle($this->title, RequestContext::getMain())->getParserOutput();
         $data = $parserOutput ? $parserOutput->getProperty(self::INFOBOXES_PROPERTY_NAME) : false;
         //return empty [] to prevent false on non existing infobox data
         return $data ? $data : [];
     }
     return [];
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:15,代码来源:PortableInfoboxDataService.class.php

示例7: execute

 /**
  * Purges the cache of a page
  */
 public function execute()
 {
     global $wgUser;
     $params = $this->extractRequestParams();
     if (!$wgUser->isAllowed('purge') && !$this->getMain()->isInternalMode() && !$this->getMain()->getRequest()->wasPosted()) {
         $this->dieUsageMsg(array('mustbeposted', $this->getModuleName()));
     }
     $forceLinkUpdate = $params['forcelinkupdate'];
     $result = array();
     foreach ($params['titles'] as $t) {
         $r = array();
         $title = Title::newFromText($t);
         if (!$title instanceof Title) {
             $r['title'] = $t;
             $r['invalid'] = '';
             $result[] = $r;
             continue;
         }
         ApiQueryBase::addTitleInfo($r, $title);
         if (!$title->exists()) {
             $r['missing'] = '';
             $result[] = $r;
             continue;
         }
         $context = $this->createContext();
         $context->setTitle($title);
         $article = Article::newFromTitle($title, $context);
         $article->doPurge();
         // Directly purge and skip the UI part of purge().
         $r['purged'] = '';
         if ($forceLinkUpdate) {
             if (!$wgUser->pingLimiter()) {
                 global $wgParser, $wgEnableParserCache;
                 $popts = new ParserOptions();
                 $p_result = $wgParser->parse($article->getContent(), $title, $popts);
                 # Update the links tables
                 $u = new LinksUpdate($title, $p_result);
                 $u->doUpdate();
                 $r['linkupdate'] = '';
                 if ($wgEnableParserCache) {
                     $pcache = ParserCache::singleton();
                     $pcache->save($p_result, $article, $popts);
                 }
             } else {
                 $this->setWarning($this->parseMsg(array('actionthrottledtext')));
                 $forceLinkUpdate = false;
             }
         }
         $result[] = $r;
     }
     $apiResult = $this->getResult();
     $apiResult->setIndexedTagName($result, 'page');
     $apiResult->addValue(null, $this->getModuleName(), $result);
 }
开发者ID:tuxmania87,项目名称:GalaxyAdventures,代码行数:57,代码来源:ApiPurge.php

示例8: fnLastModified

/**
 * @param $out OutputPage
 * @param $sk Skin
 * @return bool
 */
function fnLastModified(&$out, &$sk)
{
    global $wgLastModifiedRange;
    $context = $out->getContext();
    $title = $context->getTitle();
    $article = Article::newFromTitle($title, $context);
    if ($article && ($title instanceof Title && $title->getNamespace() == 0)) {
        $timestamp = wfTimestamp(TS_UNIX, $article->getTimestamp());
        $out->addMeta('http:last-modified', date('r', $timestamp));
        $out->addMeta('last-modified-timestamp', $timestamp);
        $out->addMeta('last-modified-range', $wgLastModifiedRange);
        $out->addModules('last.modified');
    }
    return true;
}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:20,代码来源:LastModified.php

示例9: prepareDocumentation


//.........这里部分代码省略.........
             $wgOut->addHTML('<br><span class="' . $helpClass . '"><i>' . '* Topic tags must be part of an unordered list.' . ' Use {{#topic:Display Name}} after a * (list item markup) to create topics.</i></span>');
         } elseif (sizeof($pieces) >= 2 && PonyDocsProductManual::IsManual($pieces[1], $pieces[2])) {
             $pManual = PonyDocsProductManual::GetManualByShortName($pieces[1], $pieces[2]);
             if ($pManual) {
                 $this->data['manualname'] = $pManual->getLongName();
             } else {
                 $this->data['manualname'] = $pieces[2];
             }
             $this->data['topicname'] = $pieces[3];
             $this->data['titletext'] = $pieces[2];
         } else {
             $this->data['topicname'] = $pieces[2];
         }
     } else {
         $pManual = PonyDocsProductManual::GetManualByShortName($pieces[1], $pieces[2]);
         if ($pManual) {
             $this->data['manualname'] = $pManual->getLongName();
         } else {
             $this->data['manualname'] = $pieces[2];
         }
         $this->data['topicname'] = $pieces[3];
         $h1 = PonyDocsTopic::FindH1ForTitle($wgTitle->__toString());
         if ($h1 !== FALSE) {
             $this->data['titletext'] = $h1;
         }
     }
     /**
      * Get current topic, passing it our global Article object.
      * From this, generate our TOC based on the current topic selected.
      * This generates our left sidebar TOC plus our prev/next/start navigation links.
      * This should ONLY be done if we actually are WITHIN a manual, so special pages like TOC, etc. should not do this!
      */
     if ($pManual) {
         $p = PonyDocsProduct::GetProductByShortName($this->data['selectedProduct']);
         $v = PonyDocsProductVersion::GetVersionByName($this->data['selectedProduct'], $this->data['selectedVersion']);
         $toc = new PonyDocsTOC($pManual, $v, $p);
         list($this->data['manualtoc'], $this->data['tocprev'], $this->data['tocnext'], $this->data['tocstart']) = $toc->loadContent();
         $this->data['toctitle'] = $toc->getTOCPageTitle();
     }
     /**
      * Create a PonyDocsTopic from our article. From this we populate:
      *
      * topicversions:  List of version names topic is tagged with.
      * inlinetoc:  Inline TOC shown above article body.
      * catcode:  Special category code.
      * cattext:  Category description.
      * basetopicname:  Base topic name (w/o :<version> at end).
      * basetopiclink:  Link to special TopicList page to view all same topics.
      */
     $context = $this->skin->getContext();
     $article = Article::newFromTitle($context->getTitle(), $context);
     $topic = new PonyDocsTopic($article);
     if (preg_match('/^' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':(.*):(.*):(.*):(.*)/', $wgTitle->__toString()) || preg_match('/^' . PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':.*:.*TOC.*/', $wgTitle->__toString())) {
         $this->data['topicversions'] = PonyDocsWiki::getVersionsForTopic($topic);
         $this->data['inlinetoc'] = $topic->getSubContents();
         $this->data['versionclasses'] = $topic->getVersionClasses();
         $this->data['versionGroupMessage'] = $this->data['pVersion']->getVersionGroupMessage();
         /**
          * Sort of a hack -- we only use this right now when loading a TOC page which is new/does not exist.
          * When this happens a hook (AlternateEdit) adds an inline script to define this JS function,
          * which populates the edit box with the proper Category tag based on the currently selected version.
          */
         $this->data['body_onload'] = 'ponyDocsOnLoad();';
         switch ($this->data['catcode']) {
             case 0:
                 $this->data['cattext'] = 'Applies to latest version which is currently unreleased.';
                 break;
             case 1:
                 $this->data['cattext'] = 'Applies to latest version.';
                 break;
             case 2:
                 $this->data['cattext'] = 'Applies to released version(s) but not the latest.';
                 break;
             case 3:
                 $this->data['cattext'] = 'Applies to latest preview version.';
                 break;
             case 4:
                 $this->data['cattext'] = 'Applies to one or more preview version(s) only.';
                 break;
             case 5:
                 $this->data['cattext'] = 'Applies to one or more unreleased version(s) only.';
                 break;
             case -2:
                 /** Means its not a a title name which should be checked. */
                 break;
             default:
                 $this->data['cattext'] = 'Does not apply to any version of PonyDocs.';
                 break;
         }
     }
     $this->data['basetopicname'] = $topic->getBaseTopicName();
     if (strlen($this->data['basetopicname'])) {
         $this->data['basetopiclink'] = '<a href="' . $wgScriptPath . '/index.php?title=Special:TopicList&topic=' . $this->data['basetopicname'] . '">View All</a>';
     }
     $temp = PonyDocsTopic::FindH1ForTitle(PONYDOCS_DOCUMENTATION_NAMESPACE_NAME . ':' . $topic->getTitle()->getText());
     if ($temp !== false) {
         // We got an H1!
         $this->data['pagetitle'] = $temp;
     }
 }
开发者ID:Velody,项目名称:ponydocs,代码行数:101,代码来源:PonyDocsTemplate.php

示例10: resolveWikitext

 /**
  * Perform reverse parsing on given HTML (when needed)
  */
 private static function resolveWikitext($content, $mode, $page, $method, $section)
 {
     global $wgRequest, $wgTitle, $wgOut, $wgEnableSlowPagesBlacklistExt;
     wfProfileIn(__METHOD__);
     if (!empty($wgEnableSlowPagesBlacklistExt)) {
         global $wgSlowPagesBlacklist;
         if (in_array($wgTitle->getFullURL(), $wgSlowPagesBlacklist)) {
             wfProfileOut(__METHOD__);
             return ['html' => wfMessage('slowpagesblacklist-preview-unavailable')->plain(), 'catbox' => '', 'interlanglinks' => ''];
         }
     }
     if ($wgTitle && class_exists($page)) {
         $pageObj = new $page();
         if (is_a($pageObj, 'SpecialCustomEditPage')) {
             $wikitext = $pageObj->getWikitextFromRequestForPreview($wgRequest->getVal('title', 'empty'));
             $service = new EditPageService($wgTitle);
             $html = $pageObj->getOwnPreviewDiff($wikitext, $method);
             /**
              * @val String $type - partial or full - whether to return full skin along with css and js or just a content
              */
             $type = $wgRequest->getVal('type', 'partial');
             $res = [];
             if ($html === false) {
                 $html = '';
                 if ($method == 'preview') {
                     list($html, $catbox, $interlanglinks) = $service->getPreview($wikitext);
                     // allow extensions to modify preview (BugId:8354) - this hook should only be run on article's content
                     wfRunHooks('OutputPageBeforeHTML', array(&$wgOut, &$html));
                     if (F::app()->checkSkin('wikiamobile')) {
                         if ($type === 'full') {
                             $res['html'] = F::app()->renderView('WikiaMobileService', 'preview', ['content' => $html, 'section' => $section]);
                         } else {
                             $res['html'] = $html;
                         }
                     } elseif (F::app()->checkSkin('venus')) {
                         if ($type === 'full') {
                             $res['html'] = F::app()->renderView('VenusController', 'preview', ['content' => $html, 'section' => $section]);
                         } else {
                             $res['html'] = $html;
                         }
                     } else {
                         // add page title when not in section edit mode
                         if ($section === '') {
                             $html = '<h1 class="pagetitle">' . $wgTitle->getPrefixedText() . '</h1>' . $html;
                         }
                         // allow extensions to modify preview (BugId:6721)
                         wfRunHooks('EditPageLayoutModifyPreview', array($wgTitle, &$html, $wikitext));
                         /**
                          * bugid: 11407
                          * Provide an appropriate preview for a redirect, based on wikitext, not revision.
                          */
                         if (preg_match('/^#REDIRECT /m', $wikitext)) {
                             $article = Article::newFromTitle($wgTitle, RequestContext::getMain());
                             $matches = array();
                             if (preg_match_all('/^#REDIRECT \\[\\[([^\\]]+)\\]\\]/Um', $wikitext, $matches)) {
                                 $redirectTitle = Title::newFromText($matches[1][0]);
                                 if ($redirectTitle) {
                                     $html = $article->viewRedirect(array($redirectTitle));
                                 } else {
                                     \Wikia\Logger\WikiaLogger::instance()->info('No redirect title', ['titleText' => $matches[1][0]]);
                                     $html = '';
                                 }
                             }
                         }
                         $html = '<div class="WikiaArticle">' . $html . '</div>';
                         $res = ['html' => $html, 'catbox' => $catbox, 'interlanglinks' => $interlanglinks];
                     }
                 } elseif ($method == 'diff') {
                     $res['html'] = $service->getDiff($wikitext, intval($section));
                 }
             }
             wfProfileOut(__METHOD__);
             return $res;
         }
     }
     wfProfileOut(__METHOD__);
     return ['html' => ''];
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:81,代码来源:EditPageLayoutAjax.class.php

示例11: skinTemplateOutputPageBeforeExec

 /**
  * skinTemplateOutputPageBeforeExec hook
  * 
  * Cooks the skin template Seizam-Style!
  * 
  * @param SkinSkinzam $skin
  * @param SkinzamTemplate $tpl
  */
 public static function skinTemplateOutputPageBeforeExec(&$skin, &$tpl)
 {
     $background['url'] = false;
     $navigation['content'] = false;
     $title = $skin->getRelevantTitle();
     $ns = $title->getNamespace();
     if (WpPage::isInWikiplaceNamespaces($ns)) {
         $explosion = WpWikiplace::explodeWikipageKey($title->getText(), $ns);
         $wikiplaceKey = $explosion[0];
         // Wikiplace Background?g|png|gif)$/i';
         $background['url'] = self::getBackgroundUrlForWikiPlace($wikiplaceKey);
         // Wikiplace Navigation Menu
         $navigationKey = $wikiplaceKey . '/' . WPNAVIGATIONKEY;
         /** @todo i18n */
         $navigationTitle = Title::newFromText($navigationKey, NS_WIKIPLACE);
         $navigationPage = WikiPage::factory($navigationTitle);
         $navigationText = $navigationPage->getText();
         if ($navigationText) {
             $navigationArticle = Article::newFromTitle($navigationTitle, $skin->getContext());
             $navigation['content'] = $navigationArticle->getOutputFromWikitext($navigationText)->getText();
         }
     } else {
         $background['url'] = self::getBackgroundUrlForOther($title);
     }
     $tpl->set('wp_background', $background);
     $tpl->set('wp_navigation', $navigation);
     return true;
 }
开发者ID:eFFemeer,项目名称:seizamcore,代码行数:36,代码来源:Wikiplaces.hooks.php

示例12: execute

 public function execute()
 {
     global $wgRequestTime;
     if (!$this->enabled) {
         $this->error("Nothing to do -- \$wgUseFileCache is disabled.", true);
     }
     $start = $this->getOption('start', "0");
     if (!ctype_digit($start)) {
         $this->error("Invalid value for start parameter.", true);
     }
     $start = intval($start);
     $end = $this->getOption('end', "0");
     if (!ctype_digit($end)) {
         $this->error("Invalid value for end parameter.", true);
     }
     $end = intval($end);
     $this->output("Building content page file cache from page {$start}!\n");
     $dbr = $this->getDB(DB_REPLICA);
     $overwrite = $this->getOption('overwrite', false);
     $start = $start > 0 ? $start : $dbr->selectField('page', 'MIN(page_id)', false, __METHOD__);
     $end = $end > 0 ? $end : $dbr->selectField('page', 'MAX(page_id)', false, __METHOD__);
     if (!$start) {
         $this->error("Nothing to do.", true);
     }
     $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip';
     // hack, no real client
     # Do remaining chunk
     $end += $this->mBatchSize - 1;
     $blockStart = $start;
     $blockEnd = $start + $this->mBatchSize - 1;
     $dbw = $this->getDB(DB_MASTER);
     // Go through each page and save the output
     while ($blockEnd <= $end) {
         // Get the pages
         $res = $dbr->select('page', ['page_namespace', 'page_title', 'page_id'], ['page_namespace' => MWNamespace::getContentNamespaces(), "page_id BETWEEN {$blockStart} AND {$blockEnd}"], __METHOD__, ['ORDER BY' => 'page_id ASC', 'USE INDEX' => 'PRIMARY']);
         $this->beginTransaction($dbw, __METHOD__);
         // for any changes
         foreach ($res as $row) {
             $rebuilt = false;
             $title = Title::makeTitleSafe($row->page_namespace, $row->page_title);
             if (null == $title) {
                 $this->output("Page {$row->page_id} has bad title\n");
                 continue;
                 // broken title?
             }
             $context = new RequestContext();
             $context->setTitle($title);
             $article = Article::newFromTitle($title, $context);
             $context->setWikiPage($article->getPage());
             // If the article is cacheable, then load it
             if ($article->isFileCacheable(HTMLFileCache::MODE_REBUILD)) {
                 $viewCache = new HTMLFileCache($title, 'view');
                 $historyCache = new HTMLFileCache($title, 'history');
                 if ($viewCache->isCacheGood() && $historyCache->isCacheGood()) {
                     if ($overwrite) {
                         $rebuilt = true;
                     } else {
                         $this->output("Page '{$title}' (id {$row->page_id}) already cached\n");
                         continue;
                         // done already!
                     }
                 }
                 MediaWiki\suppressWarnings();
                 // header notices
                 // Cache ?action=view
                 $wgRequestTime = microtime(true);
                 # bug 22852
                 ob_start();
                 $article->view();
                 $context->getOutput()->output();
                 $context->getOutput()->clearHTML();
                 $viewHtml = ob_get_clean();
                 $viewCache->saveToFileCache($viewHtml);
                 // Cache ?action=history
                 $wgRequestTime = microtime(true);
                 # bug 22852
                 ob_start();
                 Action::factory('history', $article, $context)->show();
                 $context->getOutput()->output();
                 $context->getOutput()->clearHTML();
                 $historyHtml = ob_get_clean();
                 $historyCache->saveToFileCache($historyHtml);
                 MediaWiki\restoreWarnings();
                 if ($rebuilt) {
                     $this->output("Re-cached page '{$title}' (id {$row->page_id})...");
                 } else {
                     $this->output("Cached page '{$title}' (id {$row->page_id})...");
                 }
                 $this->output("[view: " . strlen($viewHtml) . " bytes; " . "history: " . strlen($historyHtml) . " bytes]\n");
             } else {
                 $this->output("Page '{$title}' (id {$row->page_id}) not cacheable\n");
             }
         }
         $this->commitTransaction($dbw, __METHOD__);
         // commit any changes (just for sanity)
         $blockStart += $this->mBatchSize;
         $blockEnd += $this->mBatchSize;
     }
     $this->output("Done!\n");
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:100,代码来源:rebuildFileCache.php

示例13: getAsJson

 public function getAsJson()
 {
     $articleId = $this->getRequest()->getInt(self::SIMPLE_JSON_ARTICLE_ID_PARAMETER_NAME, NULL);
     $articleTitle = $this->getRequest()->getVal(self::SIMPLE_JSON_ARTICLE_TITLE_PARAMETER_NAME, NULL);
     $redirect = $this->request->getVal('redirect');
     if (!empty($articleId) && !empty($articleTitle)) {
         throw new BadRequestApiException('Can\'t use id and title in the same request');
     }
     if (empty($articleId) && empty($articleTitle)) {
         throw new BadRequestApiException('You need to pass title or id of an article');
     }
     if (!empty($articleId)) {
         $article = Article::newFromID($articleId);
     } else {
         $title = Title::newFromText($articleTitle, NS_MAIN);
         if ($title instanceof Title && $title->exists()) {
             $article = Article::newFromTitle($title, RequestContext::getMain());
         }
     }
     if (empty($article)) {
         throw new NotFoundApiException("Unable to find any article");
     }
     if ($redirect !== 'no' && $article->getPage()->isRedirect()) {
         // false, Title object of local target or string with URL
         $followRedirect = $article->getPage()->followRedirect();
         if ($followRedirect && !is_string($followRedirect)) {
             $article = Article::newFromTitle($followRedirect, RequestContext::getMain());
         }
     }
     //Response is based on wikiamobile skin as this already removes inline style
     //and make response smaller
     RequestContext::getMain()->setSkin(Skin::newFromKey('wikiamobile'));
     global $wgArticleAsJson;
     $wgArticleAsJson = true;
     $parsedArticle = $article->getParserOutput();
     if ($parsedArticle instanceof ParserOutput) {
         $articleContent = json_decode($parsedArticle->getText());
     } else {
         throw new ArticleAsJsonParserException('Parser is currently not available');
     }
     $wgArticleAsJson = false;
     $categories = [];
     foreach (array_keys($parsedArticle->getCategories()) as $category) {
         $categoryTitle = Title::newFromText($category, NS_CATEGORY);
         if ($categoryTitle) {
             $categories[] = ['title' => $categoryTitle->getText(), 'url' => $categoryTitle->getLocalURL()];
         }
     }
     $result = ['content' => $articleContent->content, 'media' => $articleContent->media, 'users' => $articleContent->users, 'categories' => $categories];
     $this->setResponseData($result, '', self::SIMPLE_JSON_VARNISH_CACHE_EXPIRATION);
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:51,代码来源:ArticlesApiController.class.php

示例14: execute

 public function execute()
 {
     $user = $this->getUser();
     $params = $this->extractRequestParams();
     if (is_null($params['text']) && is_null($params['appendtext']) && is_null($params['prependtext']) && $params['undo'] == 0) {
         $this->dieUsageMsg('missingtext');
     }
     $titleObj = Title::newFromText($params['title']);
     if (!$titleObj || $titleObj->isExternal()) {
         $this->dieUsageMsg(array('invalidtitle', $params['title']));
     }
     $apiResult = $this->getResult();
     if ($params['redirect']) {
         if ($titleObj->isRedirect()) {
             $oldTitle = $titleObj;
             $titles = Title::newFromRedirectArray(Revision::newFromTitle($oldTitle)->getText(Revision::FOR_THIS_USER));
             // array_shift( $titles );
             $redirValues = array();
             foreach ($titles as $id => $newTitle) {
                 if (!isset($titles[$id - 1])) {
                     $titles[$id - 1] = $oldTitle;
                 }
                 $redirValues[] = array('from' => $titles[$id - 1]->getPrefixedText(), 'to' => $newTitle->getPrefixedText());
                 $titleObj = $newTitle;
             }
             $apiResult->setIndexedTagName($redirValues, 'r');
             $apiResult->addValue(null, 'redirects', $redirValues);
         }
     }
     if ($params['createonly'] && $titleObj->exists()) {
         $this->dieUsageMsg('createonly-exists');
     }
     if ($params['nocreate'] && !$titleObj->exists()) {
         $this->dieUsageMsg('nocreate-missing');
     }
     // Now let's check whether we're even allowed to do this
     $errors = $titleObj->getUserPermissionsErrors('edit', $user);
     if (!$titleObj->exists()) {
         $errors = array_merge($errors, $titleObj->getUserPermissionsErrors('create', $user));
     }
     if (count($errors)) {
         $this->dieUsageMsg($errors[0]);
     }
     $articleObj = Article::newFromTitle($titleObj, $this->getContext());
     $toMD5 = $params['text'];
     if (!is_null($params['appendtext']) || !is_null($params['prependtext'])) {
         // For non-existent pages, Article::getContent()
         // returns an interface message rather than ''
         // We do want getContent()'s behavior for non-existent
         // MediaWiki: pages, though
         if ($articleObj->getID() == 0 && $titleObj->getNamespace() != NS_MEDIAWIKI) {
             $content = '';
         } else {
             $content = $articleObj->getContent();
         }
         if (!is_null($params['section'])) {
             // Process the content for section edits
             global $wgParser;
             $section = intval($params['section']);
             $content = $wgParser->getSection($content, $section, false);
             if ($content === false) {
                 $this->dieUsage("There is no section {$section}.", 'nosuchsection');
             }
         }
         $params['text'] = $params['prependtext'] . $content . $params['appendtext'];
         $toMD5 = $params['prependtext'] . $params['appendtext'];
     }
     if ($params['undo'] > 0) {
         if ($params['undoafter'] > 0) {
             if ($params['undo'] < $params['undoafter']) {
                 list($params['undo'], $params['undoafter']) = array($params['undoafter'], $params['undo']);
             }
             $undoafterRev = Revision::newFromID($params['undoafter']);
         }
         $undoRev = Revision::newFromID($params['undo']);
         if (is_null($undoRev) || $undoRev->isDeleted(Revision::DELETED_TEXT)) {
             $this->dieUsageMsg(array('nosuchrevid', $params['undo']));
         }
         if ($params['undoafter'] == 0) {
             $undoafterRev = $undoRev->getPrevious();
         }
         if (is_null($undoafterRev) || $undoafterRev->isDeleted(Revision::DELETED_TEXT)) {
             $this->dieUsageMsg(array('nosuchrevid', $params['undoafter']));
         }
         if ($undoRev->getPage() != $articleObj->getID()) {
             $this->dieUsageMsg(array('revwrongpage', $undoRev->getID(), $titleObj->getPrefixedText()));
         }
         if ($undoafterRev->getPage() != $articleObj->getID()) {
             $this->dieUsageMsg(array('revwrongpage', $undoafterRev->getID(), $titleObj->getPrefixedText()));
         }
         $newtext = $articleObj->getUndoText($undoRev, $undoafterRev);
         if ($newtext === false) {
             $this->dieUsageMsg('undo-failure');
         }
         $params['text'] = $newtext;
         // If no summary was given and we only undid one rev,
         // use an autosummary
         if (is_null($params['summary']) && $titleObj->getNextRevisionID($undoafterRev->getID()) == $params['undo']) {
             $params['summary'] = wfMsgForContent('undo-summary', $params['undo'], $undoRev->getUserText());
         }
//.........这里部分代码省略.........
开发者ID:Tjorriemorrie,项目名称:app,代码行数:101,代码来源:ApiEditPage.php

示例15: execute

    function execute($par)
    {
        global $wgRequest, $wgSitename, $wgLanguageCode, $IP;
        global $wgDeferredUpdateList, $wgOut, $wgUser, $wgServer;
        $this->setHeaders();
        if ($wgUser->isBlocked()) {
            $wgOut->blockedPage();
            return;
        }
        $target = isset($par) ? $par : $wgRequest->getVal('target');
        if (!$target) {
            $wgOut->addHTML(wfMsg('notarget'));
            return;
        }
        $titleObj = Title::newFromUrl(urldecode($target));
        if (!$titleObj || !$titleObj->exists()) {
            $wgOut->addHTML('Error: bad target');
            return;
        }
        $whow = WikihowArticleEditor::newFromTitle($titleObj);
        $rev = Revision::newFromTitle($titleObj);
        $article = Article::newFromTitle($titleObj, $this->getContext());
        $text = $rev->getText();
        if ($wgRequest->wasPosted()) {
            // protect from users who can't edit
            if (!$titleObj->userCan('edit')) {
                $wgOut->readOnlyPage($article->getContent(), true);
                return;
            }
            // construct the related wikihow section
            $rel_array = split("\\|", $wgRequest->getVal('related_list'));
            $result = "";
            foreach ($rel_array as $rel) {
                $rel = urldecode(trim($rel));
                if (!$rel) {
                    continue;
                }
                $result .= "*  [[" . $rel . "|" . wfMsg('howto', $rel) . "]]\n";
            }
            if (strpos($text, "\n== " . wfMsg('relatedwikihows') . " ==\n") !== false) {
                // no newline neeeded to start with
                $result = "== " . wfMsg('relatedwikihows') . " ==\n" . $result;
            } else {
                $result = "\n== " . wfMsg('relatedwikihows') . " ==\n" . $result;
            }
            $text = "";
            $index = 0;
            $content = $article->getContent();
            $last_heading = "";
            $inserted = false;
            $section = -1;
            $ext_links_section = -1;
            if ($article->getSection($content, $index) == null) {
                $index++;
                // weird where there's no summary
            }
            while (($sectiontext = $article->getSection($content, $index)) != null) {
                $i = strpos($sectiontext, "\n");
                if ($i > 0) {
                    $heading = substr($sectiontext, 0, $i);
                    $heading = trim(str_replace("==", "", $heading));
                    if ($heading == wfMsg('relatedwikihows')) {
                        $section = $index;
                        break;
                    }
                    if ($heading == wfMsg('sources')) {
                        $ext_links_section = $index;
                    }
                }
                $index++;
            }
            $text = $result;
            $tail = '';
            $text = $article->getContent();
            // figure out which section to replace if related wikihows
            // don't exist
            $just_append = false;
            if ($section <= 0) {
                if ($ext_links_section > 0) {
                    // related wikihows have to go before external links
                    $section = $ext_links_section;
                    // glue external links and related wikihows together
                    // and replace external links
                    $result = $result . "\n" . $article->getSection($content, $section);
                } else {
                    $section = $index;
                    $result = "\n" . $result;
                    // make it a bit prettier
                    $just_append = true;
                }
            } else {
                $s = $article->getSection($content, $section);
                $lines = split("\n", $s);
                for ($i = 1; $i < sizeof($lines); $i++) {
                    $line = $lines[$i];
                    if (strpos($line, "*") !== 0) {
                        // not a list item
                        $tail .= "\n" . $line;
                    }
                }
//.........这里部分代码省略.........
开发者ID:biribogos,项目名称:wikihow-src,代码行数:101,代码来源:ManageRelated.body.php


注:本文中的Article::newFromTitle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。