X-Git-Url: https://git.cyclocoop.org/%28%28?a=blobdiff_plain;f=includes%2FTitle.php;h=0687a1558958e85cba569ba4b74bce9937b23247;hb=c0af3c9e39caedd509985a2d5315dc0ef2ddae64;hp=083a725d98376af9418a31192d896fbce2670d38;hpb=f4a53c54065c385172363416eb3cb44b67585ca2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Title.php b/includes/Title.php index 083a725d98..0687a15589 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -272,7 +272,7 @@ class Title implements LinkTarget { } try { - return Title::newFromTextThrow( strval( $text ), $defaultNamespace ); + return self::newFromTextThrow( strval( $text ), $defaultNamespace ); } catch ( MalformedTitleException $ex ) { return null; } @@ -411,7 +411,7 @@ class Title implements LinkTarget { __METHOD__ ); if ( $row !== false ) { - $title = Title::newFromRow( $row ); + $title = self::newFromRow( $row ); } else { $title = null; } @@ -439,7 +439,7 @@ class Title implements LinkTarget { $titles = []; foreach ( $res as $row ) { - $titles[] = Title::newFromRow( $row ); + $titles[] = self::newFromRow( $row ); } return $titles; } @@ -541,7 +541,7 @@ class Title implements LinkTarget { } $t = new Title(); - $t->mDbkeyform = Title::makeName( $ns, $title, $fragment, $interwiki, true ); + $t->mDbkeyform = self::makeName( $ns, $title, $fragment, $interwiki, true ); try { $t->secureAndSplit(); @@ -557,10 +557,10 @@ class Title implements LinkTarget { * @return Title The new object */ public static function newMainPage() { - $title = Title::newFromText( wfMessage( 'mainpage' )->inContentLanguage()->text() ); + $title = self::newFromText( wfMessage( 'mainpage' )->inContentLanguage()->text() ); // Don't give fatal errors if the message is broken if ( !$title ) { - $title = Title::newFromText( 'Main Page' ); + $title = self::newFromText( 'Main Page' ); } return $title; } @@ -748,6 +748,8 @@ class Title implements LinkTarget { /** * Escape a text fragment, say from a link, for a URL * + * @deprecated since 1.30, use Sanitizer::escapeIdForLink() or escapeIdForExternalInterwiki() + * * @param string $fragment Containing a URL or link fragment (after the "#") * @return string Escaped string */ @@ -933,7 +935,7 @@ class Title implements LinkTarget { */ public function getContentModel( $flags = 0 ) { if ( !$this->mForcedContentModel - && ( !$this->mContentModel || $flags === Title::GAID_FOR_UPDATE ) + && ( !$this->mContentModel || $flags === self::GAID_FOR_UPDATE ) && $this->getArticleID( $flags ) ) { $linkCache = LinkCache::singleton(); @@ -1034,6 +1036,7 @@ class Title implements LinkTarget { * Can this title have a corresponding talk page? * * @see MWNamespace::hasTalkNamespace + * @since 1.30 * * @return bool True if this title either is a talk page or can have a talk page associated. */ @@ -1096,7 +1099,7 @@ class Title implements LinkTarget { if ( $canonicalName ) { $localName = SpecialPageFactory::getLocalNameFor( $canonicalName, $par ); if ( $localName != $this->mDbkeyform ) { - return Title::makeTitle( NS_SPECIAL, $localName ); + return self::makeTitle( NS_SPECIAL, $localName ); } } } @@ -1195,7 +1198,7 @@ class Title implements LinkTarget { * @return bool */ public function isMainPage() { - return $this->equals( Title::newMainPage() ); + return $this->equals( self::newMainPage() ); } /** @@ -1313,7 +1316,24 @@ class Title implements LinkTarget { * @return Title The object for the talk page */ public function getTalkPage() { - return Title::makeTitle( MWNamespace::getTalk( $this->getNamespace() ), $this->getDBkey() ); + return self::makeTitle( MWNamespace::getTalk( $this->getNamespace() ), $this->getDBkey() ); + } + + /** + * Get a Title object associated with the talk page of this article, + * if such a talk page can exist. + * + * @since 1.30 + * + * @return Title|null The object for the talk page, + * or null if no associated talk page can exist, according to canHaveTalkPage(). + */ + public function getTalkPageIfDefined() { + if ( !$this->canHaveTalkPage() ) { + return null; + } + + return $this->getTalkPage(); } /** @@ -1328,7 +1348,7 @@ class Title implements LinkTarget { if ( $this->getNamespace() == $subjectNS ) { return $this; } - return Title::makeTitle( $subjectNS, $this->getDBkey() ); + return self::makeTitle( $subjectNS, $this->getDBkey() ); } /** @@ -1382,14 +1402,16 @@ class Title implements LinkTarget { /** * Get the fragment in URL form, including the "#" character if there is one + * * @return string Fragment in URL form */ public function getFragmentForURL() { if ( !$this->hasFragment() ) { return ''; - } else { - return '#' . Title::escapeFragmentForURL( $this->getFragment() ); + } elseif ( $this->isExternal() && !$this->getTransWikiID() ) { + return '#' . Sanitizer::escapeIdForExternalInterwiki( $this->getFragment() ); } + return '#' . Sanitizer::escapeIdForLink( $this->getFragment() ); } /** @@ -1535,7 +1557,7 @@ class Title implements LinkTarget { * @since 1.20 */ public function getRootTitle() { - return Title::makeTitle( $this->getNamespace(), $this->getRootText() ); + return self::makeTitle( $this->getNamespace(), $this->getRootText() ); } /** @@ -1575,7 +1597,7 @@ class Title implements LinkTarget { * @since 1.20 */ public function getBaseTitle() { - return Title::makeTitle( $this->getNamespace(), $this->getBaseText() ); + return self::makeTitle( $this->getNamespace(), $this->getBaseText() ); } /** @@ -1611,7 +1633,7 @@ class Title implements LinkTarget { * @since 1.20 */ public function getSubpage( $text ) { - return Title::makeTitleSafe( $this->getNamespace(), $this->getText() . '/' . $text ); + return self::makeTitleSafe( $this->getNamespace(), $this->getText() . '/' . $text ); } /** @@ -1875,6 +1897,8 @@ class Title implements LinkTarget { * protocol-relative, the URL will be expanded to http:// * * @see self::getLocalURL for the arguments. + * @param string $query + * @param string|bool $query2 * @return string The URL */ public function getInternalURL( $query = '', $query2 = false ) { @@ -2646,24 +2670,33 @@ class Title implements LinkTarget { if ( $this->mTitleProtection === null ) { $dbr = wfGetDB( DB_REPLICA ); + $commentStore = new CommentStore( 'pt_reason' ); + $commentQuery = $commentStore->getJoin(); $res = $dbr->select( - 'protected_titles', + [ 'protected_titles' ] + $commentQuery['tables'], [ 'user' => 'pt_user', - 'reason' => 'pt_reason', 'expiry' => 'pt_expiry', 'permission' => 'pt_create_perm' - ], + ] + $commentQuery['fields'], [ 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ], - __METHOD__ + __METHOD__, + [], + $commentQuery['joins'] ); // fetchRow returns false if there are no rows. $row = $dbr->fetchRow( $res ); if ( $row ) { - $row['expiry'] = $dbr->decodeExpiry( $row['expiry'] ); + $this->mTitleProtection = [ + 'user' => $row['user'], + 'expiry' => $dbr->decodeExpiry( $row['expiry'] ), + 'permission' => $row['permission'], + 'reason' => $commentStore->getComment( $row )->text, + ]; + } else { + $this->mTitleProtection = false; } - $this->mTitleProtection = $row; } return $this->mTitleProtection; } @@ -2847,7 +2880,7 @@ class Title implements LinkTarget { $page_id = $row->pr_page; $page_ns = $row->page_namespace; $page_title = $row->page_title; - $sources[$page_id] = Title::makeTitle( $page_ns, $page_title ); + $sources[$page_id] = self::makeTitle( $page_ns, $page_title ); # Add groups needed for each restriction type if its not already there # Make sure this restriction type still exists @@ -3172,7 +3205,7 @@ class Title implements LinkTarget { if ( $limit > -1 ) { $options['LIMIT'] = $limit; } - $this->mSubpages = TitleArray::newFromResult( + return TitleArray::newFromResult( $dbr->select( 'page', [ 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ], $conds, @@ -3180,7 +3213,6 @@ class Title implements LinkTarget { $options ) ); - return $this->mSubpages; } /** @@ -3329,7 +3361,7 @@ class Title implements LinkTarget { * @return int Int or 0 if the page doesn't exist */ public function getLatestRevID( $flags = 0 ) { - if ( !( $flags & Title::GAID_FOR_UPDATE ) && $this->mLatestID !== false ) { + if ( !( $flags & self::GAID_FOR_UPDATE ) && $this->mLatestID !== false ) { return intval( $this->mLatestID ); } if ( !$this->getArticleID( $flags ) ) { @@ -3489,7 +3521,7 @@ class Title implements LinkTarget { if ( $res->numRows() ) { $linkCache = LinkCache::singleton(); foreach ( $res as $row ) { - $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ); + $titleObj = self::makeTitle( $row->page_namespace, $row->page_title ); if ( $titleObj ) { $linkCache->addGoodLinkObjFromRow( $titleObj, $row ); $retVal[] = $titleObj; @@ -3557,9 +3589,9 @@ class Title implements LinkTarget { $linkCache = LinkCache::singleton(); foreach ( $res as $row ) { if ( $row->page_id ) { - $titleObj = Title::newFromRow( $row ); + $titleObj = self::newFromRow( $row ); } else { - $titleObj = Title::makeTitle( $row->$blNamespace, $row->$blTitle ); + $titleObj = self::makeTitle( $row->$blNamespace, $row->$blTitle ); $linkCache->addBadLinkObj( $titleObj ); } $retVal[] = $titleObj; @@ -3615,7 +3647,7 @@ class Title implements LinkTarget { $retVal = []; foreach ( $res as $row ) { - $retVal[] = Title::makeTitle( $row->pl_namespace, $row->pl_title ); + $retVal[] = self::makeTitle( $row->pl_namespace, $row->pl_title ); } return $retVal; } @@ -3673,7 +3705,7 @@ class Title implements LinkTarget { * Returns true if ok, or a getUserPermissionsErrors()-like array otherwise * * @deprecated since 1.25, use MovePage's methods instead - * @param Title $nt The new title + * @param Title &$nt The new title * @param bool $auth Whether to check user permissions (uses $wgUser) * @param string $reason Is the log summary of the move, used for spam checking * @return array|bool True on success, getUserPermissionsErrors()-like array on failure @@ -3725,7 +3757,7 @@ class Title implements LinkTarget { * Move a title to a new location * * @deprecated since 1.25, use the MovePage class instead - * @param Title $nt The new title + * @param Title &$nt The new title * @param bool $auth Indicates whether $wgUser's permissions * should be checked * @param string $reason The reason for the move @@ -3827,7 +3859,7 @@ class Title implements LinkTarget { } # T16385: we need makeTitleSafe because the new page names may # be longer than 255 characters. - $newSubpage = Title::makeTitleSafe( $newNs, $newPageName ); + $newSubpage = self::makeTitleSafe( $newNs, $newPageName ); $success = $oldSubpage->moveTo( $newSubpage, $auth, $reason, $createRedirect, $changeTags ); if ( $success === true ) { @@ -3989,7 +4021,7 @@ class Title implements LinkTarget { # Circular reference $stack[$parent] = []; } else { - $nt = Title::newFromText( $parent ); + $nt = self::newFromText( $parent ); if ( $nt ) { $stack[$parent] = $nt->getParentCategoryTree( $children + [ $parent => 1 ] ); }