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


PHP Title::newFromTextThrow方法代码示例

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


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

示例1: validateTitle

 public function validateTitle($title)
 {
     if (!$title) {
         // No form input yet
         return true;
     }
     try {
         $titleObj = Title::newFromTextThrow($title);
     } catch (MalformedTitleException $e) {
         $msg = $this->msg($e->getErrorMessage());
         $params = $e->getErrorMessageParameters();
         if ($params) {
             $msg->params($params);
         }
         return $msg->parse();
     }
     if (!$titleObj->canExist()) {
         return $this->msg('changecontentmodel-title-cantexist', $titleObj->getPrefixedText())->escaped();
     }
     $this->oldRevision = Revision::newFromTitle($titleObj) ?: false;
     if ($this->oldRevision) {
         $oldContent = $this->oldRevision->getContent();
         if (!$oldContent->getContentHandler()->supportsDirectEditing()) {
             return $this->msg('changecontentmodel-nodirectediting')->params(ContentHandler::getLocalizedName($oldContent->getModel()))->escaped();
         }
     }
     return true;
 }
开发者ID:D66Ha,项目名称:mediawiki,代码行数:28,代码来源:SpecialChangeContentModel.php

示例2: testSecureAndSplitInvalid

 /**
  * See also mediawiki.Title.test.js
  * @covers Title::secureAndSplit
  * @dataProvider provideInvalidSecureAndSplit
  * @note This mainly tests MediaWikiTitleCodec::parseTitle().
  */
 public function testSecureAndSplitInvalid($text, $expectedErrorMessage)
 {
     $this->secureAndSplitGlobals();
     try {
         Title::newFromTextThrow($text);
         // should throw
         $this->assertTrue(false, "Invalid: {$text}");
     } catch (MalformedTitleException $ex) {
         $this->assertEquals($expectedErrorMessage, $ex->getErrorMessage(), "Invalid: {$text}");
     }
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:17,代码来源:TitleTest.php

示例3: validateTitle

 public function validateTitle($title)
 {
     if (!$title) {
         // No form input yet
         return true;
     }
     // Already validated by HTMLForm, but if not, throw
     // and exception instead of a fatal
     $titleObj = Title::newFromTextThrow($title);
     $this->oldRevision = Revision::newFromTitle($titleObj) ?: false;
     if ($this->oldRevision) {
         $oldContent = $this->oldRevision->getContent();
         if (!$oldContent->getContentHandler()->supportsDirectEditing()) {
             return $this->msg('changecontentmodel-nodirectediting')->params(ContentHandler::getLocalizedName($oldContent->getModel()))->escaped();
         }
     }
     return true;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:18,代码来源:SpecialChangeContentModel.php

示例4: validate

 public function validate($value, $alldata)
 {
     if ($this->mParent->getMethod() === 'get' && $value === '') {
         // If the form is a GET form and has no value, assume it hasn't been
         // submitted yet, and skip validation
         return parent::validate($value, $alldata);
     }
     try {
         if (!$this->mParams['relative']) {
             $title = Title::newFromTextThrow($value);
         } else {
             // Can't use Title::makeTitleSafe(), because it doesn't throw useful exceptions
             global $wgContLang;
             $namespaceName = $wgContLang->getNsText($this->mParams['namespace']);
             $title = Title::newFromTextThrow($namespaceName . ':' . $value);
         }
     } catch (MalformedTitleException $e) {
         $msg = $this->msg($e->getErrorMessage());
         $params = $e->getErrorMessageParameters();
         if ($params) {
             $msg->params($params);
         }
         return $msg->parse();
     }
     $text = $title->getPrefixedText();
     if ($this->mParams['namespace'] !== false && !$title->inNamespace($this->mParams['namespace'])) {
         return $this->msg('htmlform-title-badnamespace', $this->mParams['namespace'], $text)->parse();
     }
     if ($this->mParams['creatable'] && !$title->canExist()) {
         return $this->msg('htmlform-title-not-creatable', $text)->escaped();
     }
     if ($this->mParams['exists'] && !$title->exists()) {
         return $this->msg('htmlform-title-not-exists', $text)->parse();
     }
     return parent::validate($value, $alldata);
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:36,代码来源:HTMLTitleTextField.php

示例5: validate

 public function validate($value, $alldata)
 {
     try {
         $title = Title::newFromTextThrow($value);
     } catch (MalformedTitleException $e) {
         $msg = $this->msg($e->getErrorMessage());
         $params = $e->getErrorMessageParameters();
         if ($params) {
             $msg->params($params);
         }
         return $msg->parse();
     }
     $text = $title->getPrefixedText();
     if ($this->mParams['namespace'] !== false && !$title->inNamespace($this->mParams['namespace'])) {
         return $this->msg('htmlform-title-badnamespace', $this->mParams['namespace'], $text)->parse();
     }
     if ($this->mParams['creatable'] && !$title->canExist()) {
         return $this->msg('htmlform-title-not-creatable', $text)->escaped();
     }
     if ($this->mParams['exists'] && !$title->exists()) {
         return $this->msg('htmlform-title-not-exists', $text)->parse();
     }
     return parent::validate($value, $alldata);
 }
开发者ID:nanasess,项目名称:mediawiki,代码行数:24,代码来源:HTMLTitleTextField.php

示例6: newFromText

 /**
  * Create a new Title from text, such as what one would find in a link. De-
  * codes any HTML entities in the text.
  *
  * @param string $text The link text; spaces, prefixes, and an
  *   initial ':' indicating the main namespace are accepted.
  * @param int $defaultNamespace The namespace to use if none is specified
  *   by a prefix.  If you want to force a specific namespace even if
  *   $text might begin with a namespace prefix, use makeTitle() or
  *   makeTitleSafe().
  * @throws InvalidArgumentException
  * @return Title|null Title or null on an error.
  */
 public static function newFromText($text, $defaultNamespace = NS_MAIN)
 {
     if (is_object($text)) {
         throw new InvalidArgumentException('$text must be a string.');
     } elseif (!is_string($text)) {
         wfDebugLog('T76305', wfGetAllCallers(5));
         wfWarn(__METHOD__ . ': $text must be a string. This will throw an InvalidArgumentException in future.', 2);
     }
     try {
         return Title::newFromTextThrow($text, $defaultNamespace);
     } catch (MalformedTitleException $ex) {
         return null;
     }
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:27,代码来源:Title.php

示例7: newFromText

 /**
  * Create a new Title from text, such as what one would find in a link. De-
  * codes any HTML entities in the text.
  *
  * @param string|null $text The link text; spaces, prefixes, and an
  *   initial ':' indicating the main namespace are accepted.
  * @param int $defaultNamespace The namespace to use if none is specified
  *   by a prefix.  If you want to force a specific namespace even if
  *   $text might begin with a namespace prefix, use makeTitle() or
  *   makeTitleSafe().
  * @throws InvalidArgumentException
  * @return Title|null Title or null on an error.
  */
 public static function newFromText($text, $defaultNamespace = NS_MAIN)
 {
     if (is_object($text)) {
         throw new InvalidArgumentException('$text must be a string.');
     }
     if ($text !== null && !is_string($text)) {
         wfDebugLog('T76305', wfGetAllCallers(5));
         return null;
     }
     if ($text === null) {
         return null;
     }
     try {
         return Title::newFromTextThrow($text, $defaultNamespace);
     } catch (MalformedTitleException $ex) {
         return null;
     }
 }
开发者ID:scott71,项目名称:mediawiki,代码行数:31,代码来源:Title.php

示例8: newFromText

 /**
  * Create a new Title from text, such as what one would find in a link. De-
  * codes any HTML entities in the text.
  *
  * @param string|int|null $text The link text; spaces, prefixes, and an
  *   initial ':' indicating the main namespace are accepted.
  * @param int $defaultNamespace The namespace to use if none is specified
  *   by a prefix.  If you want to force a specific namespace even if
  *   $text might begin with a namespace prefix, use makeTitle() or
  *   makeTitleSafe().
  * @throws InvalidArgumentException
  * @return Title|null Title or null on an error.
  */
 public static function newFromText($text, $defaultNamespace = NS_MAIN)
 {
     // DWIM: Integers can be passed in here when page titles are used as array keys.
     if ($text !== null && !is_string($text) && !is_int($text)) {
         throw new InvalidArgumentException('$text must be a string.');
     }
     if ($text === null) {
         return null;
     }
     try {
         return Title::newFromTextThrow(strval($text), $defaultNamespace);
     } catch (MalformedTitleException $ex) {
         return null;
     }
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:28,代码来源:Title.php

示例9: parseTitle

 /**
  * Parse the request to get the Title object
  *
  * @throws MalformedTitleException If a title has been provided by the user, but is invalid.
  * @return Title Title object to be $wgTitle
  */
 private function parseTitle()
 {
     global $wgContLang;
     $request = $this->context->getRequest();
     $curid = $request->getInt('curid');
     $title = $request->getVal('title');
     $action = $request->getVal('action');
     if ($request->getCheck('search')) {
         // Compatibility with old search URLs which didn't use Special:Search
         // Just check for presence here, so blank requests still
         // show the search page when using ugly URLs (bug 8054).
         $ret = SpecialPage::getTitleFor('Search');
     } elseif ($curid) {
         // URLs like this are generated by RC, because rc_title isn't always accurate
         $ret = Title::newFromID($curid);
     } else {
         $ret = Title::newFromURL($title);
         // Alias NS_MEDIA page URLs to NS_FILE...we only use NS_MEDIA
         // in wikitext links to tell Parser to make a direct file link
         if (!is_null($ret) && $ret->getNamespace() == NS_MEDIA) {
             $ret = Title::makeTitle(NS_FILE, $ret->getDBkey());
         }
         // Check variant links so that interwiki links don't have to worry
         // about the possible different language variants
         if (count($wgContLang->getVariants()) > 1 && !is_null($ret) && $ret->getArticleID() == 0) {
             $wgContLang->findVariantLink($title, $ret);
         }
     }
     // If title is not provided, always allow oldid and diff to set the title.
     // If title is provided, allow oldid and diff to override the title, unless
     // we are talking about a special page which might use these parameters for
     // other purposes.
     if ($ret === null || !$ret->isSpecialPage()) {
         // We can have urls with just ?diff=,?oldid= or even just ?diff=
         $oldid = $request->getInt('oldid');
         $oldid = $oldid ? $oldid : $request->getInt('diff');
         // Allow oldid to override a changed or missing title
         if ($oldid) {
             $rev = Revision::newFromId($oldid);
             $ret = $rev ? $rev->getTitle() : $ret;
         }
     }
     // Use the main page as default title if nothing else has been provided
     if ($ret === null && strval($title) === '' && !$request->getCheck('curid') && $action !== 'delete') {
         $ret = Title::newMainPage();
     }
     if ($ret === null || $ret->getDBkey() == '' && !$ret->isExternal()) {
         // If we get here, we definitely don't have a valid title; throw an exception.
         // Try to get detailed invalid title exception first, fall back to MalformedTitleException.
         Title::newFromTextThrow($title);
         throw new MalformedTitleException('badtitletext', $title);
     }
     return $ret;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:60,代码来源:MediaWiki.php

示例10: processTitlesArray

 /**
  * Given an array of title strings, convert them into Title objects.
  * Alternatively, an array of Title objects may be given.
  * This method validates access rights for the title,
  * and appends normalization values to the output.
  *
  * @param array $titles Array of Title objects or strings
  * @return LinkBatch
  */
 private function processTitlesArray($titles)
 {
     $usernames = array();
     $linkBatch = new LinkBatch();
     foreach ($titles as $title) {
         if (is_string($title)) {
             try {
                 $titleObj = Title::newFromTextThrow($title, $this->mDefaultNamespace);
             } catch (MalformedTitleException $ex) {
                 // Handle invalid titles gracefully
                 $this->mAllPages[0][$title] = $this->mFakePageId;
                 $this->mInvalidTitles[$this->mFakePageId] = array('title' => $title, 'invalidreason' => $ex->getMessage());
                 $this->mFakePageId--;
                 continue;
                 // There's nothing else we can do
             }
         } else {
             $titleObj = $title;
         }
         $unconvertedTitle = $titleObj->getPrefixedText();
         $titleWasConverted = false;
         if ($titleObj->isExternal()) {
             // This title is an interwiki link.
             $this->mInterwikiTitles[$unconvertedTitle] = $titleObj->getInterwiki();
         } else {
             // Variants checking
             global $wgContLang;
             if ($this->mConvertTitles && count($wgContLang->getVariants()) > 1 && !$titleObj->exists()) {
                 // Language::findVariantLink will modify titleText and titleObj into
                 // the canonical variant if possible
                 $titleText = is_string($title) ? $title : $titleObj->getPrefixedText();
                 $wgContLang->findVariantLink($titleText, $titleObj);
                 $titleWasConverted = $unconvertedTitle !== $titleObj->getPrefixedText();
             }
             if ($titleObj->getNamespace() < 0) {
                 // Handle Special and Media pages
                 $titleObj = $titleObj->fixSpecialName();
                 $this->mSpecialTitles[$this->mFakePageId] = $titleObj;
                 $this->mFakePageId--;
             } else {
                 // Regular page
                 $linkBatch->addObj($titleObj);
             }
         }
         // Make sure we remember the original title that was
         // given to us. This way the caller can correlate new
         // titles with the originally requested when e.g. the
         // namespace is localized or the capitalization is
         // different
         if ($titleWasConverted) {
             $this->mConvertedTitles[$unconvertedTitle] = $titleObj->getPrefixedText();
             // In this case the page can't be Special.
             if (is_string($title) && $title !== $unconvertedTitle) {
                 $this->mNormalizedTitles[$title] = $unconvertedTitle;
             }
         } elseif (is_string($title) && $title !== $titleObj->getPrefixedText()) {
             $this->mNormalizedTitles[$title] = $titleObj->getPrefixedText();
         }
         // Need gender information
         if (MWNamespace::hasGenderDistinction($titleObj->getNamespace())) {
             $usernames[] = $titleObj->getText();
         }
     }
     // Get gender information
     $genderCache = GenderCache::singleton();
     $genderCache->doQuery($usernames, __METHOD__);
     return $linkBatch;
 }
开发者ID:D66Ha,项目名称:mediawiki,代码行数:77,代码来源:ApiPageSet.php


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