Ejemplo n.º 1
0
 /**
  * @return Title
  * @deprecated Internal class use only
  */
 public function getTitle()
 {
     if (!$this->title) {
         $this->title = Title::newFromLinkTarget($this->linkTarget);
     }
     return $this->title;
 }
Ejemplo n.º 2
0
 /**
  * Returns an HTML link to the given page, using the given surface text.
  *
  * @param LinkTarget $linkTarget The link's target
  * @param string $text The link's surface text (will be derived from $page if not given).
  *
  * @return string
  */
 public function renderHtmlLink(LinkTarget $linkTarget, $text = null)
 {
     if ($text === null) {
         $text = $this->formatter->getFullText($linkTarget);
     }
     // TODO: move the logic implemented by Linker here,
     // using $this->formatter and $this->baseUrl, and
     // re-implement Linker to use a HtmlPageLinkRenderer.
     if ($linkTarget instanceof Title) {
         $title = $linkTarget;
     } else {
         $title = Title::newFromLinkTarget($linkTarget);
     }
     $link = Linker::link($title, htmlspecialchars($text));
     return $link;
 }
 public function testCategorizeTypeParameter()
 {
     $user = $this->getLoggedInTestUser();
     $subjectTarget = new TitleValue(0, 'ApiQueryWatchlistIntegrationTestPage');
     $categoryTarget = new TitleValue(NS_CATEGORY, 'ApiQueryWatchlistIntegrationTestCategory');
     $this->doPageEdits($user, [['target' => $categoryTarget, 'content' => 'Some Content', 'summary' => 'Create the category'], ['target' => $subjectTarget, 'content' => 'Some Content [[Category:ApiQueryWatchlistIntegrationTestCategory]]t', 'summary' => 'Create the page and add it to the category']]);
     $title = Title::newFromLinkTarget($subjectTarget);
     $revision = Revision::newFromTitle($title);
     $rc = RecentChange::newForCategorization($revision->getTimestamp(), Title::newFromLinkTarget($categoryTarget), $user, $revision->getComment(), $title, 0, $revision->getId(), null, false);
     $rc->save();
     $this->watchPages($user, [$subjectTarget, $categoryTarget]);
     $result = $this->doListWatchlistRequest(['wlprop' => 'title', 'wltype' => 'categorize']);
     $this->assertEquals([['type' => 'categorize', 'ns' => $categoryTarget->getNamespace(), 'title' => $this->getPrefixedText($categoryTarget)]], $this->getItemsFromApiResponse($result));
 }
 /**
  * Builds an <li> item for an individual template
  *
  * @param LinkTarget $target
  * @return string
  */
 private function formatTemplate(LinkTarget $target)
 {
     // TODO Would be nice if we didn't have to use Title here
     $titleObj = Title::newFromLinkTarget($target);
     $protected = $this->getRestrictionsText($titleObj->getRestrictions('edit'));
     $editLink = $this->buildEditLink($titleObj);
     return '<li>' . $this->linkRenderer->makeLink($target) . $this->context->msg('word-separator')->escaped() . $this->context->msg('parentheses')->rawParams($editLink)->escaped() . $this->context->msg('word-separator')->escaped() . $protected . '</li>';
 }
Ejemplo n.º 5
0
 /**
  * Check if the given title already is watched by the user, and if so
  * add a watch for the new title.
  *
  * To be used for page renames and such.
  *
  * @param LinkTarget $oldTarget
  * @param LinkTarget $newTarget
  */
 public function duplicateAllAssociatedEntries(LinkTarget $oldTarget, LinkTarget $newTarget)
 {
     $oldTarget = Title::newFromLinkTarget($oldTarget);
     $newTarget = Title::newFromLinkTarget($newTarget);
     $this->duplicateEntry($oldTarget->getSubjectPage(), $newTarget->getSubjectPage());
     $this->duplicateEntry($oldTarget->getTalkPage(), $newTarget->getTalkPage());
 }
Ejemplo n.º 6
0
 /**
  * Get the link parameters for MediaTransformOutput::toHtml() from given
  * frame parameters supplied by the Parser.
  * @param array $frameParams The frame parameters
  * @param string $query An optional query string to add to description page links
  * @param Parser|null $parser
  * @return array
  */
 private static function getImageLinkMTOParams($frameParams, $query = '', $parser = null)
 {
     $mtoParams = [];
     if (isset($frameParams['link-url']) && $frameParams['link-url'] !== '') {
         $mtoParams['custom-url-link'] = $frameParams['link-url'];
         if (isset($frameParams['link-target'])) {
             $mtoParams['custom-target-link'] = $frameParams['link-target'];
         }
         if ($parser) {
             $extLinkAttrs = $parser->getExternalLinkAttribs($frameParams['link-url']);
             foreach ($extLinkAttrs as $name => $val) {
                 // Currently could include 'rel' and 'target'
                 $mtoParams['parser-extlink-' . $name] = $val;
             }
         }
     } elseif (isset($frameParams['link-title']) && $frameParams['link-title'] !== '') {
         $mtoParams['custom-title-link'] = Title::newFromLinkTarget(self::normaliseSpecialPage($frameParams['link-title']));
     } elseif (!empty($frameParams['no-link'])) {
         // No link
     } else {
         $mtoParams['desc-link'] = true;
         $mtoParams['desc-query'] = $query;
     }
     return $mtoParams;
 }