Withoutaname has uploaded a new change for review.
https://gerrit.wikimedia.org/r/146985
Change subject: Move MediaWiki::parseTitle() to Title::newFromRequest()
......................................................................
Move MediaWiki::parseTitle() to Title::newFromRequest()
Also changed RequestContext::getTitle() so that it's
no longer dependent on $wgTitle.
Change-Id: I7b8288cdc2784310d1b2028ccdd31dcf04065b45
---
M includes/MediaWiki.php
M includes/Title.php
M includes/context/RequestContext.php
3 files changed, 49 insertions(+), 83 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/85/146985/1
diff --git a/includes/MediaWiki.php b/includes/MediaWiki.php
index a8bafa3..1917147 100644
--- a/includes/MediaWiki.php
+++ b/includes/MediaWiki.php
@@ -64,85 +64,6 @@
}
/**
- * Parse the request to get the Title object
- *
- * @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', 'view' );
-
- 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() ) ) {
- $ret = SpecialPage::getTitleFor( 'Badtitle' );
- }
-
- return $ret;
- }
-
- /**
- * Get the Title object that we'll be acting on, as specified in the
WebRequest
- * @return Title
- */
- public function getTitle() {
- if ( $this->context->getTitle() === null ) {
- $this->context->setTitle( $this->parseTitle() );
- }
- return $this->context->getTitle();
- }
-
- /**
* Returns the name of the action that will be executed.
*
* @return string Action
@@ -523,7 +444,7 @@
// Get title from request parameters,
// is set on the fly by parseTitle the first time.
- $title = $this->getTitle();
+ $title = $this->context->getTitle();
$action = $this->getAction();
$wgTitle = $title;
@@ -643,7 +564,7 @@
if ( $wgJobRunRate <= 0 || wfReadOnly() ) {
return;
- } elseif ( $this->getTitle()->isSpecial( 'RunJobs' ) ) {
+ } elseif ( $this->context->getTitle()->isSpecial( 'RunJobs' ) )
{
return; // recursion guard
}
diff --git a/includes/Title.php b/includes/Title.php
index 477373a..1edb4ba 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -506,6 +506,49 @@
}
/**
+ * Create a new Title from a WebRequest
+ *
+ * @param WebRequest $request
+ */
+ public static function newFromRequest( WebRequest $request ) {
+ $pagename = $request->getVal( 'title' );
+ $curid = $request->getInt( 'curid' );
+ $search = $request->getVal( 'search', '' );
+ if ( $pagename ) {
+ $title = self::newFromText( $pagename );
+ if ( $title ) {
+ if ( $title->getNamespace() === NS_MEDIA ) {
+ $title = self::makeTitleSafe( NS_FILE,
$title->getDBkey() );
+ }
+ global $wgContLang;
+ if ( $wgContLang->hasVariants() &&
$title->getArticleID() === 0 ) {
+
$wgContLang->getConverter()->findVariantLink( $pagename, $title );
+ }
+ }
+ } elseif ( $curid ) {
+ $title = self::newFromID( $curid );
+ } elseif ( $search ) {
+ // Back-compat (bug 8054)
+ $title = SpecialPage::getTitleFor( 'Search' );
+ }
+
+ if ( !( $title && $title->getNamespace() === NS_SPECIAL ) ) {
+ $oldid = $request->getInt( 'oldid' );
+ $oldid = $oldid ?: $request->getInt( 'diff' );
+ if ( $oldid ) {
+ $revision = Revision::newFromId( $oldid );
+ $title = $revision ? $revision->getTitle() :
$title;
+ }
+ }
+
+ if ( !$title && ( $request->getVal( 'action', 'view' ) !==
'delete' ) ) {
+ $title = self::newMainPage();
+ }
+
+ return $title;
+ }
+
+ /**
* Create a new Title for the Main Page
*
* @return Title The new object
diff --git a/includes/context/RequestContext.php
b/includes/context/RequestContext.php
index efdc6db..faa1f46 100644
--- a/includes/context/RequestContext.php
+++ b/includes/context/RequestContext.php
@@ -138,8 +138,10 @@
*/
public function getTitle() {
if ( $this->title === null ) {
- global $wgTitle; # fallback to $wg till we can improve
this
- $this->title = $wgTitle;
+ $this->title = Title::newFromRequest(
$this->getRequest() );
+ // Back-compat
+ global $wgTitle;
+ $wgTitle = $this->title;
}
return $this->title;
--
To view, visit https://gerrit.wikimedia.org/r/146985
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7b8288cdc2784310d1b2028ccdd31dcf04065b45
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Withoutaname <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits