<?php
/**
+ * Representation a title within %MediaWiki.
+ *
* See title.txt
*
* This program is free software; you can redistribute it and/or modify
var $mRedirect = null; // /< Is the article at this title a redirect?
var $mNotificationTimestamp = array(); // /< Associative array of user ID -> timestamp/false
var $mBacklinkCache = null; // /< Cache of links to this title
+ var $mHasSubpage; // /< Whether a page has any subpages
// @}
* fied by a prefix. If you want to force a specific namespace even if
* $text might begin with a namespace prefix, use makeTitle() or
* makeTitleSafe().
- * @return Title, or null on an error.
+ * @throws MWException
+ * @return Title|null - Title or null on an error.
*/
public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
if ( is_object( $text ) ) {
* @return Title the new object, or NULL on an error
*/
public static function newFromURL( $url ) {
- global $wgLegalTitleChars;
$t = new Title();
# For compatibility with old buggy URLs. "+" is usually not valid in titles,
# but some URLs used it as a space replacement and they still come
# from some external search tools.
- if ( strpos( $wgLegalTitleChars, '+' ) === false ) {
+ if ( strpos( self::legalChars(), '+' ) === false ) {
$url = str_replace( '+', ' ', $url );
}
* @return Title the new object, or NULL on an error
*/
public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
+ if ( !MWNamespace::exists( $ns ) ) {
+ return null;
+ }
+
$t = new Title();
$t->mDbkeyform = Title::makeName( $ns, $title, $fragment, $interwiki );
if ( $t->secureAndSplit() ) {
}
}
- // Strip off subpages
- $pagename = $this->getText();
- if ( strpos( $pagename, '/' ) !== false ) {
- list( $username , ) = explode( '/', $pagename, 2 );
- } else {
- $username = $pagename;
- }
-
if ( $wgContLang->needsGenderDistinction() &&
MWNamespace::hasGenderDistinction( $this->mNamespace ) ) {
- $gender = GenderCache::singleton()->getGenderOf( $username, __METHOD__ );
+ $gender = GenderCache::singleton()->getGenderOf( $this->getText(), __METHOD__ );
return $wgContLang->getGenderNsText( $this->mNamespace, $gender );
}
* This is MUCH simpler than individually testing for equivilance
* against both NS_USER and NS_USER_TALK, and is also forward compatible.
* @since 1.19
+ * @param $ns int
* @return bool
*/
public function hasSubjectNamespace( $ns ) {
* andthe wfArrayToCGI moved to getLocalURL();
*
* @since 1.19 (r105919)
+ * @param $query
+ * @param $query2 bool
* @return String
*/
private static function fixUrlQueryArgs( $query, $query2 = false ) {
* See getLocalURL for the arguments.
*
* @see self::getLocalURL
+ * @param $query string
+ * @param $query2 bool|string
* @return String the URL
*/
public function escapeLocalURL( $query = '', $query2 = false ) {
/**
* Get the expiry time for the restriction against a given action
*
+ * @param $action
* @return String|Bool 14-char timestamp, or 'infinity' if the page is protected forever
- * or not protected at all, or false if the action is not recognised.
+ * or not protected at all, or false if the action is not recognised.
*/
public function getRestrictionExpiry( $action ) {
if ( !$this->mRestrictionsLoaded ) {
$this->mRestrictions['edit'] = explode( ',', trim( $temp[0] ) );
$this->mRestrictions['move'] = explode( ',', trim( $temp[0] ) );
} else {
- $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );
+ $restriction = trim( $temp[1] );
+ if( $restriction != '' ) { //some old entries are empty
+ $this->mRestrictions[$temp[0]] = explode( ',', $restriction );
+ }
}
}
$protected = $this->isProtected();
// Do the actual move
- $err = $this->moveToInternal( $nt, $reason, $createRedirect );
- if ( is_array( $err ) ) {
- # @todo FIXME: What about the File we have already moved?
- $dbw->rollback( __METHOD__ );
- return $err;
- }
+ $this->moveToInternal( $nt, $reason, $createRedirect );
// Refresh the sortkey for this row. Be careful to avoid resetting
// cl_timestamp, which may disturb time-based lists on some sites.
* @param $reason String The reason for the move
* @param $createRedirect Bool Whether to leave a redirect at the old title. Ignored
* if the user doesn't have the suppressredirect right
+ * @throws MWException
*/
private function moveToInternal( &$nt, $reason = '', $createRedirect = true ) {
global $wgUser, $wgContLang;
*/
public function getPreviousRevisionID( $revId, $flags = 0 ) {
$db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
- return $db->selectField( 'revision', 'rev_id',
+ $revId = $db->selectField( 'revision', 'rev_id',
array(
'rev_page' => $this->getArticleID( $flags ),
'rev_id < ' . intval( $revId )
__METHOD__,
array( 'ORDER BY' => 'rev_id DESC' )
);
+
+ if ( $revId === false ) {
+ return false;
+ } else {
+ return intval( $revId );
+ }
}
/**
*/
public function getNextRevisionID( $revId, $flags = 0 ) {
$db = ( $flags & self::GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
- return $db->selectField( 'revision', 'rev_id',
+ $revId = $db->selectField( 'revision', 'rev_id',
array(
'rev_page' => $this->getArticleID( $flags ),
'rev_id > ' . intval( $revId )
__METHOD__,
array( 'ORDER BY' => 'rev_id' )
);
+
+ if ( $revId === false ) {
+ return false;
+ } else {
+ return intval( $revId );
+ }
}
/**
$dbr = wfGetDB( DB_SLAVE );
$this->mNotificationTimestamp[$uid] = $dbr->selectField( 'watchlist',
'wl_notificationtimestamp',
- array( 'wl_namespace' => $this->getNamespace(),
+ array(
+ 'wl_user' => $user->getId(),
+ 'wl_namespace' => $this->getNamespace(),
'wl_title' => $this->getDBkey(),
- 'wl_user' => $user->getId()
),
__METHOD__
);
* $wgLang (such as special pages, which are in the user language).
*
* @since 1.18
- * @return object Language
+ * @return Language
*/
public function getPageLanguage() {
global $wgLang;