protected function parseUserValue($value)
 {
     global $wgContLang;
     // support inputs like " [[Test]] ";
     // note that this only works in pages if $smwgLinksInValues is set to true
     $value = ltrim(rtrim($value, ' ]'), ' [');
     // #1066, Manipulate the output only for when the value has no caption
     // assigned and only if a single :Foo is being present, ::Foo is not permitted
     if ($this->m_caption === false && isset($value[2]) && $value[0] === ':' && $value[1] !== ':') {
         $value = substr($value, 1);
     }
     if ($this->m_caption === false) {
         $this->m_caption = $value;
     }
     if ($value === '') {
         return $this->addErrorMsg(array('smw-datavalue-wikipage-empty'), Message::ESCAPED);
     }
     // #1701 If the DV is part of a Description and an approximate search
     // (e.g. ~foo* / ~Foo*) then use the value as-is and avoid being
     // transformed by the Title object
     // If the vaue contains a valid NS then use the Title to create a correct
     // instance to distinguish [[~Foo*]] from [[Help:~Foo*]]
     if ($this->getOptionBy(self::OPT_QUERY_COMP_CONTEXT)) {
         if (($title = Title::newFromText($value)) !== null && $title->getNamespace() !== NS_MAIN) {
             return $this->m_dataitem = SMWDIWikiPage::newFromTitle($title);
         } else {
             return $this->m_dataitem = new SMWDIWikiPage($value, NS_MAIN);
         }
     }
     if ($value[0] == '#') {
         if (is_null($this->m_contextPage)) {
             $this->addErrorMsg(array('smw-datavalue-wikipage-missing-fragment-context', $value));
             return;
         } else {
             $this->m_title = Title::makeTitle($this->m_contextPage->getNamespace(), $this->m_contextPage->getDBkey(), substr($value, 1), $this->m_contextPage->getInterwiki());
         }
     } else {
         $this->m_title = Title::newFromText($value, $this->m_fixNamespace);
     }
     /// TODO: Escape the text so users can see punctuation problems (bug 11666).
     if (is_null($this->m_title)) {
         $this->addErrorMsg(array('smw-datavalue-wikipage-invalid-title', $value));
     } elseif ($this->m_fixNamespace != NS_MAIN && $this->m_fixNamespace != $this->m_title->getNamespace()) {
         $this->addErrorMsg(array('smw_wrong_namespace', $wgContLang->getNsText($this->m_fixNamespace)));
     } else {
         $this->m_fragment = str_replace(' ', '_', $this->m_title->getFragment());
         $this->m_prefixedtext = '';
         $this->m_id = -1;
         // unset id
         $this->m_dataitem = SMWDIWikiPage::newFromTitle($this->m_title, $this->m_typeid);
     }
 }
Example #2
0
 /**
  * Extract inexpensive information from a Title object for return to Lua
  *
  * @param $title Title Title to return
  * @return array Lua data
  */
 private function getInexpensiveTitleData(Title $title)
 {
     $ns = $title->getNamespace();
     $ret = array('isLocal' => (bool) $title->isLocal(), 'interwiki' => $title->getInterwiki(), 'namespace' => $ns, 'nsText' => $title->getNsText(), 'text' => $title->getText(), 'fragment' => $title->getFragment(), 'thePartialUrl' => $title->getPartialURL());
     if ($ns === NS_SPECIAL) {
         // Core doesn't currently record special page links, but it may in the future.
         if ($this->getParser() && !$title->equals($this->getTitle())) {
             $this->getParser()->getOutput()->addLink($title);
         }
         $ret['exists'] = (bool) SpecialPageFactory::exists($title->getDBkey());
     }
     if ($ns !== NS_FILE && $ns !== NS_MEDIA) {
         $ret['file'] = false;
     }
     return $ret;
 }
 protected function parseUserValue($value)
 {
     global $wgContLang;
     // support inputs like " [[Test]] ";
     // note that this only works in pages if $smwgLinksInValues is set to true
     $value = ltrim(rtrim($value, ' ]'), ' [');
     // #1066, Manipulate the output only for when the value has no caption
     // assigned and only if a single :Foo is being present, ::Foo is not permitted
     if ($this->m_caption === false && isset($value[2]) && $value[0] === ':' && $value[1] !== ':') {
         $value = substr($value, 1);
     }
     if ($this->m_caption === false) {
         $this->m_caption = $value;
     }
     if ($value !== '') {
         if ($value[0] == '#') {
             if (is_null($this->m_contextPage)) {
                 $this->addError(wfMessage('smw_notitle', $value)->inContentLanguage()->text());
                 return;
             } else {
                 $this->m_title = Title::makeTitle($this->m_contextPage->getNamespace(), $this->m_contextPage->getDBkey(), substr($value, 1), $this->m_contextPage->getInterwiki());
             }
         } else {
             $this->m_title = Title::newFromText($value, $this->m_fixNamespace);
         }
         /// TODO: Escape the text so users can see punctuation problems (bug 11666).
         if (is_null($this->m_title)) {
             $this->addError(wfMessage('smw_notitle', $value)->inContentLanguage()->text());
         } elseif ($this->m_fixNamespace != NS_MAIN && $this->m_fixNamespace != $this->m_title->getNamespace()) {
             $this->addError(wfMessage('smw_wrong_namespace', $wgContLang->getNsText($this->m_fixNamespace))->inContentLanguage()->text());
         } else {
             $this->m_fragment = str_replace(' ', '_', $this->m_title->getFragment());
             $this->m_prefixedtext = '';
             $this->m_id = -1;
             // unset id
             $this->m_dataitem = SMWDIWikiPage::newFromTitle($this->m_title, $this->m_typeid);
         }
     } else {
         $this->addError(wfMessage('smw_notitle', $value)->inContentLanguage()->text());
     }
 }
Example #4
0
 protected function parseUserValue($value)
 {
     global $wgContLang;
     // support inputs like " [[Test]] ";
     // note that this only works in pages if $smwgLinksInValues is set to true
     $value = ltrim(rtrim($value, ' ]'), ' [');
     if ($this->m_caption === false) {
         $this->m_caption = $value;
     }
     if ($value !== '') {
         if ($value[0] == '#') {
             if (is_null($this->m_contextPage)) {
                 $this->addError(wfMsgForContent('smw_notitle', $value));
                 return;
             } else {
                 $this->m_title = Title::makeTitle($this->m_contextPage->getNamespace(), $this->m_contextPage->getDBkey(), substr($value, 1), $this->m_contextPage->getInterwiki());
             }
         } else {
             $this->m_title = Title::newFromText($value, $this->m_fixNamespace);
         }
         /// TODO: Escape the text so users can see punctuation problems (bug 11666).
         if (is_null($this->m_title)) {
             $this->addError(wfMsgForContent('smw_notitle', $value));
         } elseif ($this->m_fixNamespace != NS_MAIN && $this->m_fixNamespace != $this->m_title->getNamespace()) {
             $this->addError(wfMsgForContent('smw_wrong_namespace', $wgContLang->getNsText($this->m_fixNamespace)));
         } else {
             $this->m_fragment = str_replace(' ', '_', $this->m_title->getFragment());
             $this->m_prefixedtext = '';
             $this->m_id = -1;
             // unset id
             $this->m_dataitem = SMWDIWikiPage::newFromTitle($this->m_title, $this->m_typeid);
         }
     } else {
         $this->addError(wfMsgForContent('smw_notitle', $value));
     }
 }
Example #5
0
 /**
  * @param $title Title
  * @return Title
  */
 static function normaliseSpecialPage(Title $title)
 {
     if ($title->getNamespace() == NS_SPECIAL) {
         list($name, $subpage) = SpecialPageFactory::resolveAlias($title->getDBkey());
         if (!$name) {
             return $title;
         }
         $ret = SpecialPage::getTitleFor($name, $subpage);
         $ret->mFragment = $title->getFragment();
         return $ret;
     } else {
         return $title;
     }
 }
Example #6
0
 /**
  * Insert or update the redirect table entry for this page to indicate it redirects to $rt
  * @param Title $rt Redirect target
  * @param int|null $oldLatest Prior page_latest for check and set
  */
 public function insertRedirectEntry(Title $rt, $oldLatest = null)
 {
     $dbw = wfGetDB(DB_MASTER);
     $dbw->startAtomic(__METHOD__);
     if (!$oldLatest || $oldLatest == $this->lockAndGetLatest()) {
         $dbw->replace('redirect', ['rd_from'], ['rd_from' => $this->getId(), 'rd_namespace' => $rt->getNamespace(), 'rd_title' => $rt->getDBkey(), 'rd_fragment' => $rt->getFragment(), 'rd_interwiki' => $rt->getInterwiki()], __METHOD__);
     }
     $dbw->endAtomic(__METHOD__);
 }
Example #7
0
File: Linker.php Project: paladox/2
 /**
  * Generates a link to the given Title
  *
  * @note This is only public for technical reasons. It's not intended for use outside Linker.
  *
  * @param Title $title
  * @param string $text
  * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
  *  as used by WikiMap.
  * @param string|string[] $options See the $options parameter in Linker::link.
  *
  * @return string HTML link
  */
 public static function makeCommentLink(Title $title, $text, $wikiId = null, $options = array())
 {
     if ($wikiId !== null && !$title->isExternal()) {
         $link = Linker::makeExternalLink(WikiMap::getForeignURL($wikiId, $title->getPrefixedText(), $title->getFragment()), $text, false);
     } else {
         $link = Linker::link($title, $text, array(), array(), $options);
     }
     return $link;
 }
Example #8
0
 /**
  * Insert or update the redirect table entry for this page to indicate
  * it redirects to $rt .
  * @param Title $rt Redirect target
  */
 public function insertRedirectEntry($rt)
 {
     $dbw = wfGetDB(DB_MASTER);
     $dbw->replace('redirect', array('rd_from'), array('rd_from' => $this->getId(), 'rd_namespace' => $rt->getNamespace(), 'rd_title' => $rt->getDBkey(), 'rd_fragment' => $rt->getFragment(), 'rd_interwiki' => $rt->getInterwiki()), __METHOD__);
 }
Example #9
0
 /**
  * Create a data item from a MediaWiki Title.
  *
  * @param $title Title
  * @return SMWDIWikiPage
  */
 public static function newFromTitle(Title $title)
 {
     return new SMWDIWikiPage($title->getDBkey(), $title->getNamespace(), $title->getInterwiki(), str_replace(' ', '_', $title->getFragment()));
 }
Example #10
0
 /**
  * @param Title $title
  * @return Title
  */
 static function normaliseSpecialPage(Title $title)
 {
     if ($title->isSpecialPage()) {
         list($name, $subpage) = SpecialPageFactory::resolveAlias($title->getDBkey());
         if (!$name) {
             return $title;
         }
         $ret = SpecialPage::getTitleFor($name, $subpage, $title->getFragment());
         return $ret;
     } else {
         return $title;
     }
 }