X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FTitle.php;h=24f4331fa89dd6394a9a6eb077a3f1754a050e46;hb=fc505d4fa538c933cd1e2637454bbd2ccb8bcaae;hp=f913859fdd7f0533b849aedbe894f85609104848;hpb=1b4f6c04bef5c957c0063d04c137f9237535f84b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Title.php b/includes/Title.php index f913859fdd..24f4331fa8 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -614,28 +614,13 @@ class Title { * Note that this doesn't pick up many things that could be wrong with titles, but that * replacing this regex with something valid will make many titles valid. * - * @todo move this into MediaWikiTitleCodec + * @deprecated since 1.25, use MediaWikiTitleCodec::getTitleInvalidRegex() instead * * @return string Regex string */ static function getTitleInvalidRegex() { - static $rxTc = false; - if ( !$rxTc ) { - # Matching titles will be held as illegal. - $rxTc = '/' . - # Any character not allowed is forbidden... - '[^' . self::legalChars() . ']' . - # URL percent encoding sequences interfere with the ability - # to round-trip titles -- you can't link to them consistently. - '|%[0-9A-Fa-f]{2}' . - # XML/HTML character references produce similar issues. - '|&[A-Za-z0-9\x80-\xff]+;' . - '|&#[0-9]+;' . - '|&#x[0-9A-Fa-f]+;' . - '/S'; - } - - return $rxTc; + wfDeprecated( __METHOD__, '1.25' ); + return MediaWikiTitleCodec::getTitleInvalidRegex(); } /** @@ -747,7 +732,7 @@ class Title { * @param string $title The DB key form the title * @param string $fragment The link fragment (after the "#") * @param string $interwiki The interwiki prefix - * @param boolean $canoncialNamespace If true, use the canonical name for + * @param bool $canoncialNamespace If true, use the canonical name for * $ns instead of the localized version. * @return string The prefixed form of the title */ @@ -1044,7 +1029,6 @@ class Title { * Is this in a namespace that allows actual pages? * * @return bool - * @internal note -- uses hardcoded namespace index instead of constants */ public function canExist() { return $this->mNamespace >= NS_MAIN; @@ -1180,7 +1164,7 @@ class Title { } $result = true; - wfRunHooks( 'TitleIsMovable', array( $this, &$result ) ); + Hooks::run( 'TitleIsMovable', array( $this, &$result ) ); return $result; } @@ -1250,9 +1234,9 @@ class Title { # @note This hook is also called in ContentHandler::getDefaultModel. # It's called here again to make sure hook functions can force this - # method to return true even outside the mediawiki namespace. + # method to return true even outside the MediaWiki namespace. - wfRunHooks( 'TitleIsCssOrJsPage', array( $this, &$isCssOrJsPage ) ); + Hooks::run( 'TitleIsCssOrJsPage', array( $this, &$isCssOrJsPage ), '1.25' ); return $isCssOrJsPage; } @@ -1335,6 +1319,25 @@ class Title { return Title::makeTitle( $subjectNS, $this->getDBkey() ); } + /** + * Get the other title for this page, if this is a subject page + * get the talk page, if it is a subject page get the talk page + * + * @since 1.25 + * @throws MWException + * @return Title + */ + public function getOtherPage() { + if ( $this->isSpecialPage() ) { + throw new MWException( 'Special pages cannot have other pages' ); + } + if ( $this->isTalkPage() ) { + return $this->getSubjectPage(); + } else { + return $this->getTalkPage(); + } + } + /** * Get the default namespace index, for when there is no namespace * @@ -1659,7 +1662,7 @@ class Title { # Finally, add the fragment. $url .= $this->getFragmentForURL(); - wfRunHooks( 'GetFullURL', array( &$this, &$url, $query ) ); + Hooks::run( 'GetFullURL', array( &$this, &$url, $query ) ); return $url; } @@ -1705,7 +1708,7 @@ class Title { $dbkey = wfUrlencode( $this->getPrefixedDBkey() ); if ( $query == '' ) { $url = str_replace( '$1', $dbkey, $wgArticlePath ); - wfRunHooks( 'GetLocalURL::Article', array( &$this, &$url ) ); + Hooks::run( 'GetLocalURL::Article', array( &$this, &$url ) ); } else { global $wgVariantArticlePath, $wgActionPaths, $wgContLang; $url = false; @@ -1750,7 +1753,7 @@ class Title { } } - wfRunHooks( 'GetLocalURL::Internal', array( &$this, &$url, $query ) ); + Hooks::run( 'GetLocalURL::Internal', array( &$this, &$url, $query ) ); // @todo FIXME: This causes breakage in various places when we // actually expected a local URL and end up with dupe prefixes. @@ -1758,7 +1761,7 @@ class Title { $url = $wgServer . $url; } } - wfRunHooks( 'GetLocalURL', array( &$this, &$url, $query ) ); + Hooks::run( 'GetLocalURL', array( &$this, &$url, $query ) ); return $url; } @@ -1808,7 +1811,7 @@ class Title { $query = self::fixUrlQueryArgs( $query, $query2 ); $server = $wgInternalServer !== false ? $wgInternalServer : $wgServer; $url = wfExpandUrl( $server . $this->getLocalURL( $query ), PROTO_HTTP ); - wfRunHooks( 'GetInternalURL', array( &$this, &$url, $query ) ); + Hooks::run( 'GetInternalURL', array( &$this, &$url, $query ) ); return $url; } @@ -1826,7 +1829,7 @@ class Title { public function getCanonicalURL( $query = '', $query2 = false ) { $query = self::fixUrlQueryArgs( $query, $query2 ); $url = wfExpandUrl( $this->getLocalURL( $query ) . $this->getFragmentForURL(), PROTO_CANONICAL ); - wfRunHooks( 'GetCanonicalURL', array( &$this, &$url, $query ) ); + Hooks::run( 'GetCanonicalURL', array( &$this, &$url, $query ) ); return $url; } @@ -1945,7 +1948,7 @@ class Title { private function checkQuickPermissions( $action, $user, $errors, $doExpensiveQueries, $short ) { - if ( !wfRunHooks( 'TitleQuickPermissions', + if ( !Hooks::run( 'TitleQuickPermissions', array( $this, $user, $action, &$errors, $doExpensiveQueries, $short ) ) ) { return $errors; @@ -2045,18 +2048,18 @@ class Title { private function checkPermissionHooks( $action, $user, $errors, $doExpensiveQueries, $short ) { // Use getUserPermissionsErrors instead $result = ''; - if ( !wfRunHooks( 'userCan', array( &$this, &$user, $action, &$result ) ) ) { + if ( !Hooks::run( 'userCan', array( &$this, &$user, $action, &$result ) ) ) { return $result ? array() : array( array( 'badaccess-group0' ) ); } // Check getUserPermissionsErrors hook - if ( !wfRunHooks( 'getUserPermissionsErrors', array( &$this, &$user, $action, &$result ) ) ) { + if ( !Hooks::run( 'getUserPermissionsErrors', array( &$this, &$user, $action, &$result ) ) ) { $errors = $this->resultToError( $errors, $result ); } // Check getUserPermissionsErrorsExpensive hook if ( $doExpensiveQueries && !( $short && count( $errors ) > 0 ) - && !wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) ) + && !Hooks::run( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) ) ) { $errors = $this->resultToError( $errors, $result ); } @@ -2389,7 +2392,7 @@ class Title { if ( !$whitelisted ) { # If the title is not whitelisted, give extensions a chance to do so... - wfRunHooks( 'TitleReadWhitelist', array( $this, $user, &$whitelisted ) ); + Hooks::run( 'TitleReadWhitelist', array( $this, $user, &$whitelisted ) ); if ( !$whitelisted ) { $errors[] = $this->missingPermissionError( $action, $short ); } @@ -2523,7 +2526,7 @@ class Title { $types = array_diff( $types, array( 'upload' ) ); } - wfRunHooks( 'TitleGetRestrictionTypes', array( $this, &$types ) ); + Hooks::run( 'TitleGetRestrictionTypes', array( $this, &$types ) ); wfDebug( __METHOD__ . ': applicable restrictions to [[' . $this->getPrefixedText() . ']] are {' . implode( ',', $types ) . "}\n" ); @@ -2813,8 +2816,10 @@ class Title { * Accessor/initialisation for mRestrictions * * @param string $action Action that permission needs to be checked for - * @return array Restriction levels needed to take the action. All levels - * are required. + * @return array Restriction levels needed to take the action. All levels are + * required. Note that restriction levels are normally user rights, but 'sysop' + * and 'autoconfirmed' are also allowed for backwards compatibility. These should + * be mapped to 'editprotected' and 'editsemiprotected' respectively. */ public function getRestrictions( $action ) { if ( !$this->mRestrictionsLoaded ) { @@ -3576,7 +3581,7 @@ class Title { $urls[] = $this->getInternalUrl( 'action=raw&ctype=text/css' ); } - wfRunHooks( 'TitleSquidURLs', array( $this, &$urls ) ); + Hooks::run( 'TitleSquidURLs', array( $this, &$urls ) ); return $urls; } @@ -4041,7 +4046,7 @@ class Title { if ( $this->mIsBigDeletion === null ) { $dbr = wfGetDB( DB_SLAVE ); - $innerQuery = $dbr->selectSQLText( + $revCount = $dbr->selectRowCount( 'revision', '1', array( 'rev_page' => $this->getArticleID() ), @@ -4049,13 +4054,6 @@ class Title { array( 'LIMIT' => $wgDeleteRevisionsLimit + 1 ) ); - $revCount = $dbr->query( - 'SELECT COUNT(*) FROM (' . $innerQuery . ') AS innerQuery', - __METHOD__ - ); - $revCount = $revCount->fetchRow(); - $revCount = $revCount['COUNT(*)']; - $this->mIsBigDeletion = $revCount > $wgDeleteRevisionsLimit; } @@ -4247,7 +4245,7 @@ class Title { */ public function exists() { $exists = $this->getArticleID() != 0; - wfRunHooks( 'TitleExists', array( $this, &$exists ) ); + Hooks::run( 'TitleExists', array( $this, &$exists ) ); return $exists; } @@ -4280,7 +4278,7 @@ class Title { * @param Title $title * @param bool|null $isKnown */ - wfRunHooks( 'TitleIsAlwaysKnown', array( $this, &$isKnown ) ); + Hooks::run( 'TitleIsAlwaysKnown', array( $this, &$isKnown ) ); if ( !is_null( $isKnown ) ) { return $isKnown; @@ -4603,7 +4601,7 @@ class Title { // on the Title object passed in, and should probably // tell the users to run updateCollations.php --force // in order to re-sort existing category relations. - wfRunHooks( 'GetDefaultSortkey', array( $this, &$unprefixed ) ); + Hooks::run( 'GetDefaultSortkey', array( $this, &$unprefixed ) ); if ( $prefix !== '' ) { # Separate with a line feed, so the unprefixed part is only used as # a tiebreaker when two pages have the exact same prefix. @@ -4724,7 +4722,7 @@ class Title { } } - wfRunHooks( 'TitleGetEditNotices', array( $this, $oldid, &$notices ) ); + Hooks::run( 'TitleGetEditNotices', array( $this, $oldid, &$notices ) ); return $notices; } }