/** @name Static cache variables */
// @{
static private $titleCache = array();
- static private $interwikiCache = array();
// @}
/**
public static function newFromDBkey( $key ) {
$t = new Title();
$t->mDbkeyform = $key;
- if ( $t->secureAndSplit() )
+ if ( $t->secureAndSplit() ) {
return $t;
- else
+ } else {
return null;
+ }
}
/**
return array();
}
$dbr = wfGetDB( DB_SLAVE );
- $res = $dbr->select( 'page', array( 'page_namespace', 'page_title' ),
- 'page_id IN (' . $dbr->makeList( $ids ) . ')', __METHOD__ );
+
+ $res = $dbr->select(
+ 'page',
+ array(
+ 'page_namespace', 'page_title', 'page_id',
+ 'page_len', 'page_is_redirect', 'page_latest',
+ ),
+ array( 'page_id' => $ids ),
+ __METHOD__
+ );
$titles = array();
foreach ( $res as $row ) {
- $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
+ $titles[] = Title::newFromRow( $row );
}
return $titles;
}
$t->mArticleID = isset( $row->page_id ) ? intval( $row->page_id ) : -1;
$t->mLength = isset( $row->page_len ) ? intval( $row->page_len ) : -1;
$t->mRedirect = isset( $row->page_is_redirect ) ? (bool)$row->page_is_redirect : null;
- $t->mLatestID = isset( $row->page_latest ) ? $row->page_latest : false;
+ $t->mLatestID = isset( $row->page_latest ) ? intval( $row->page_latest ) : false;
return $t;
}
* @param $ns \type{\int} the namespace of the article
* @param $title \type{\string} the unprefixed database key form
* @param $fragment \type{\string} The link fragment (after the "#")
+ * @param $interwiki \type{\string} The interwiki prefix
* @return \type{Title} the new object
*/
- public static function &makeTitle( $ns, $title, $fragment = '' ) {
+ public static function &makeTitle( $ns, $title, $fragment = '', $interwiki = '' ) {
$t = new Title();
- $t->mInterwiki = '';
+ $t->mInterwiki = $interwiki;
$t->mFragment = $fragment;
$t->mNamespace = $ns = intval( $ns );
$t->mDbkeyform = str_replace( ' ', '_', $title );
* @param $ns \type{\int} the namespace of the article
* @param $title \type{\string} the database key form
* @param $fragment \type{\string} The link fragment (after the "#")
+ * @param $interwiki \type{\string} The interwiki prefix
* @return \type{Title} the new object, or NULL on an error
*/
- public static function makeTitleSafe( $ns, $title, $fragment = '' ) {
+ public static function makeTitleSafe( $ns, $title, $fragment = '', $interwiki = '' ) {
$t = new Title();
- $t->mDbkeyform = Title::makeName( $ns, $title, $fragment );
+ $t->mDbkeyform = Title::makeName( $ns, $title, $fragment, $interwiki );
if ( $t->secureAndSplit() ) {
return $t;
} else {
public static function newFromRedirectArray( $text ) {
global $wgMaxRedirects;
// are redirects disabled?
- if ( $wgMaxRedirects < 1 )
+ if ( $wgMaxRedirects < 1 ) {
return null;
+ }
$title = self::newFromRedirectInternal( $text );
- if ( is_null( $title ) )
+ if ( is_null( $title ) ) {
return null;
+ }
// recursive check to follow double redirects
$recurse = $wgMaxRedirects;
$titles = array( $title );
public static function nameOf( $id ) {
$dbr = wfGetDB( DB_SLAVE );
- $s = $dbr->selectRow( 'page',
+ $s = $dbr->selectRow(
+ 'page',
array( 'page_namespace', 'page_title' ),
array( 'page_id' => $id ),
- __METHOD__ );
- if ( $s === false ) { return null; }
+ __METHOD__
+ );
+ if ( $s === false ) {
+ return null;
+ }
$n = self::makeName( $s->page_namespace, $s->page_title );
return $n;
* @param $ns \type{\int} numerical representation of the namespace
* @param $title \type{\string} the DB key form the title
* @param $fragment \type{\string} The link fragment (after the "#")
+ * @param $interwiki \type{\string} The interwiki prefix
* @return \type{\string} the prefixed form of the title
*/
- public static function makeName( $ns, $title, $fragment = '' ) {
+ public static function makeName( $ns, $title, $fragment = '', $interwiki = '' ) {
global $wgContLang;
$namespace = $wgContLang->getNsText( $ns );
$name = $namespace == '' ? $title : "$namespace:$title";
+ if ( strval( $interwiki ) != '' ) {
+ $name = "$interwiki:$name";
+ }
if ( strval( $fragment ) != '' ) {
$name .= '#' . $fragment;
}
* @return \type{\bool} TRUE if this is transcludable
*/
public function isTrans() {
- if ( $this->mInterwiki == '' )
+ if ( $this->mInterwiki == '' ) {
return false;
+ }
return Interwiki::fetch( $this->mInterwiki )->isTranscludable();
}
+ /**
+ * Returns the DB name of the distant wiki
+ * which owns the object.
+ *
+ * @return \type{\string} the DB name
+ */
+ public function getTransWikiID() {
+ if ( $this->mInterwiki == '' ) {
+ return false;
+ }
+
+ return Interwiki::fetch( $this->mInterwiki )->getWikiID();
+ }
+
/**
* Escape a text fragment, say from a link, for a URL
*
$parts = explode( '/', $this->getText() );
# Don't discard the real title if there's no subpage involved
- if ( count( $parts ) > 1 )
- unset( $parts[ count( $parts ) - 1 ] );
+ if ( count( $parts ) > 1 ) {
+ unset( $parts[count( $parts ) - 1] );
+ }
return implode( '/', $parts );
}
return( $this->mTextform );
}
$parts = explode( '/', $this->mTextform );
- return( $parts[ count( $parts ) - 1 ] );
+ return( $parts[count( $parts ) - 1] );
}
/**
* @return \type{\string} the URL
*/
public function getFullURL( $query = '', $variant = false ) {
- global $wgContLang, $wgServer, $wgRequest;
+ global $wgServer, $wgRequest;
if ( is_array( $query ) ) {
$query = wfArrayToCGI( $query );
$url = $wgServer . $url;
}
} else {
- $baseUrl = $interwiki->getURL( );
+ $baseUrl = $interwiki->getURL();
$namespace = wfUrlencode( $this->getNsText() );
if ( $namespace != '' ) {
}
// internal links should point to same variant as current page (only anonymous users)
- if ( $variant == false && $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) {
+ if ( !$variant && $wgContLang->hasVariants() && !$wgUser->isLoggedIn() ) {
$pref = $wgContLang->getPreferredVariant( false );
- if ( $pref != $wgContLang->getCode() )
+ if ( $pref != $wgContLang->getCode() ) {
$variant = $pref;
+ }
}
if ( $this->isExternal() ) {
$dbkey = wfUrlencode( $this->getPrefixedDBkey() );
if ( $query == '' ) {
if ( $variant != false && $wgContLang->hasVariants() ) {
- if ( $wgVariantArticlePath == false ) {
+ if ( !$wgVariantArticlePath ) {
$variantArticlePath = "$wgScript?title=$1&variant=$2"; // default
} else {
$variantArticlePath = $wgVariantArticlePath;
$action = urldecode( $matches[2] );
if ( isset( $wgActionPaths[$action] ) ) {
$query = $matches[1];
- if ( isset( $matches[4] ) ) $query .= $matches[4];
+ if ( isset( $matches[4] ) ) {
+ $query .= $matches[4];
+ }
$url = str_replace( '$1', $dbkey, $wgActionPaths[$action] );
if ( $query != '' ) {
$url = wfAppendQuery( $url, $query );
* interwiki link
*/
public function getEditURL() {
- if ( $this->mInterwiki != '' ) { return ''; }
+ if ( $this->mInterwiki != '' ) {
+ return '';
+ }
$s = $this->getLocalURL( 'action=edit' );
return $s;
*
* @return \type{\bool}
*/
- public function isExternal() { return ( $this->mInterwiki != '' ); }
+ public function isExternal() {
+ return ( $this->mInterwiki != '' );
+ }
/**
* Is this page "semi-protected" - the *only* protection is autoconfirm?
$restrictions = $this->getRestrictions( $action );
if ( count( $restrictions ) > 0 ) {
foreach ( $restrictions as $restriction ) {
- if ( strtolower( $restriction ) != 'autoconfirmed' )
+ if ( strtolower( $restriction ) != 'autoconfirmed' ) {
return false;
+ }
}
} else {
# Not protected
$restrictionTypes = $this->getRestrictionTypes();
# Special pages have inherent protection
- if( $this->getNamespace() == NS_SPECIAL )
+ if( $this->getNamespace() == NS_SPECIAL ) {
return true;
+ }
# Check regular protection levels
foreach ( $restrictionTypes as $type ) {
* @return \type{\bool}
*/
public function isConversionTable() {
- if($this->getNamespace() == NS_MEDIAWIKI
- && strpos( $this->getText(), 'Conversiontable' ) !== false ) {
+ if(
+ $this->getNamespace() == NS_MEDIAWIKI &&
+ strpos( $this->getText(), 'Conversiontable' ) !== false
+ )
+ {
return true;
}
*/
public function isNamespaceProtected() {
global $wgNamespaceProtection, $wgUser;
- if ( isset( $wgNamespaceProtection[ $this->mNamespace ] ) ) {
- foreach ( (array)$wgNamespaceProtection[ $this->mNamespace ] as $right ) {
- if ( $right != '' && !$wgUser->isAllowed( $right ) )
+ if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
+ foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
+ if ( $right != '' && !$wgUser->isAllowed( $right ) ) {
return true;
+ }
}
}
return false;
if ( $action == 'create' ) {
if ( ( $this->isTalkPage() && !$user->isAllowed( 'createtalk' ) ) ||
( !$this->isTalkPage() && !$user->isAllowed( 'createpage' ) ) ) {
- $errors[] = $user->isAnon() ? array ( 'nocreatetext' ) : array ( 'nocreate-loggedin' );
+ $errors[] = $user->isAnon() ? array( 'nocreatetext' ) : array( 'nocreate-loggedin' );
}
} elseif ( $action == 'move' ) {
if ( !$user->isAllowed( 'move-rootuserpages' )
}
if ( $user->isAnon() && ( $userCanMove || $autoconfirmedCanMove ) ) {
// custom message if logged-in users without any special rights can move
- $errors[] = array ( 'movenologintext' );
+ $errors[] = array( 'movenologintext' );
} else {
- $errors[] = array ( 'movenotallowed' );
+ $errors[] = array( 'movenotallowed' );
}
}
} elseif ( $action == 'move-target' ) {
if ( !$user->isAllowed( 'move' ) ) {
// User can't move anything
- $errors[] = array ( 'movenotallowed' );
+ $errors[] = array( 'movenotallowed' );
} elseif ( !$user->isAllowed( 'move-rootuserpages' )
&& $this->mNamespace == NS_USER && !$this->isSubpage() ) {
// Show user page-specific message only if the user can move other pages
count( $groups )
);
} else {
- $return = array( "badaccess-group0" );
+ $return = array( 'badaccess-group0' );
}
$errors[] = $return;
}
}
// Check getUserPermissionsErrors hook
if ( !wfRunHooks( 'getUserPermissionsErrors', array( &$this, &$user, $action, &$result ) ) ) {
- $errors[] = $this->resultToError( $errors, $result );
+ $errors = $this->resultToError( $errors, $result );
}
// Check getUserPermissionsErrorsExpensive hook
if ( $doExpensiveQueries && !( $short && count( $errors ) > 0 ) &&
!wfRunHooks( 'getUserPermissionsErrorsExpensive', array( &$this, &$user, $action, &$result ) ) ) {
- $errors[] = $this->resultToError( $errors, $result );
+ $errors = $this->resultToError( $errors, $result );
}
return $errors;
return $errors;
}
- global $wgContLang;
- global $wgLang;
- global $wgEmailConfirmToEdit;
+ global $wgContLang, $wgLang, $wgEmailConfirmToEdit;
if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' ) {
$errors[] = array( 'confirmedittext' );
$scBlockExpiryOptions = wfMsg( 'ipboptions' );
foreach ( explode( ',', $scBlockExpiryOptions ) as $option ) {
- if ( strpos( $option, ':' ) == false )
+ if ( !strpos( $option, ':' ) )
continue;
- list ( $show, $value ) = explode( ":", $option );
+ list( $show, $value ) = explode( ':', $option );
if ( $value == 'infinite' || $value == 'indefinite' ) {
$blockExpiry = $show;
wfProfileIn( __METHOD__ );
$errors = array();
- $checks = array( 'checkQuickPermissions',
+ $checks = array(
+ 'checkQuickPermissions',
'checkPermissionHooks',
'checkSpecialsAndNSPermissions',
'checkCSSandJSPermissions',
'checkPageRestrictions',
'checkCascadingSourcesRestrictions',
'checkActionPermissions',
- 'checkUserBlock' );
+ 'checkUserBlock'
+ );
while( count( $checks ) > 0 &&
!( $short && count( $errors ) > 0 ) ) {
if ( $encodedExpiry != 'infinity' ) {
$expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ),
$wgContLang->date( $expiry ) , $wgContLang->time( $expiry ) ) . ')';
- }
- else {
+ } else {
$expiry_description .= ' (' . wfMsgForContent( 'protect-expiry-indefinite' ) . ')';
}
public function deleteTitleProtection() {
$dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'protected_titles',
+ $dbw->delete(
+ 'protected_titles',
array( 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ),
- __METHOD__ );
+ __METHOD__
+ );
}
/**
}
# Shortcut for public wikis, allows skipping quite a bit of code
- if ( $useShortcut )
+ if ( $useShortcut ) {
return true;
+ }
if ( $wgUser->isAllowed( 'read' ) ) {
return true;
* a colon for main-namespace pages
*/
if ( $this->getNamespace() == NS_MAIN ) {
- if ( in_array( ':' . $name, $wgWhitelistRead ) )
+ if ( in_array( ':' . $name, $wgWhitelistRead ) ) {
return true;
+ }
}
/**
}
$pure = SpecialPage::getTitleFor( $name )->getPrefixedText();
- if ( in_array( $pure, $wgWhitelistRead, true ) )
+ if ( in_array( $pure, $wgWhitelistRead, true ) ) {
return true;
+ }
}
}
}
$subpages = $this->getSubpages( 1 );
- if ( $subpages instanceof TitleArray )
+ if ( $subpages instanceof TitleArray ) {
return $this->mHasSubpages = (bool)$subpages->count();
+ }
return $this->mHasSubpages = false;
}
* doesn't allow subpages
*/
public function getSubpages( $limit = -1 ) {
- if ( !MWNamespace::hasSubpages( $this->getNamespace() ) )
+ if ( !MWNamespace::hasSubpages( $this->getNamespace() ) ) {
return array();
+ }
$dbr = wfGetDB( DB_SLAVE );
$conds['page_namespace'] = $this->getNamespace();
$conds[] = 'page_title ' . $dbr->buildLike( $this->getDBkey() . '/', $dbr->anyString() );
$options = array();
- if ( $limit > -1 )
+ if ( $limit > -1 ) {
$options['LIMIT'] = $limit;
+ }
return $this->mSubpages = TitleArray::newFromResult(
$dbr->select( 'page',
array( 'page_id', 'page_namespace', 'page_title', 'page_is_redirect' ),
public function isValidCssJsSubpage() {
if ( $this->isCssJsSubpage() ) {
$name = $this->getSkinFromCssJsSubpage();
- if ( $name == 'common' ) return true;
+ if ( $name == 'common' ) {
+ return true;
+ }
$skinNames = Skin::getSkinNames();
return array_key_exists( $name, $skinNames );
} else {
return ( ( $wgUser->isAllowed( 'editusercssjs' ) && $wgUser->isAllowed( 'editusercss' ) )
|| preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
}
+
/**
* Protect js subpages of user pages: can $wgUser edit
* this page?
$dbr = wfGetDB( DB_SLAVE );
if ( $this->getNamespace() == NS_FILE ) {
- $tables = array ( 'imagelinks', 'page_restrictions' );
+ $tables = array( 'imagelinks', 'page_restrictions' );
$where_clauses = array(
'il_to' => $this->getDBkey(),
'il_from=pr_page',
- 'pr_cascade' => 1 );
+ 'pr_cascade' => 1
+ );
} else {
- $tables = array ( 'templatelinks', 'page_restrictions' );
+ $tables = array( 'templatelinks', 'page_restrictions' );
$where_clauses = array(
'tl_namespace' => $this->getNamespace(),
'tl_title' => $this->getDBkey(),
'tl_from=pr_page',
- 'pr_cascade' => 1 );
+ 'pr_cascade' => 1
+ );
}
if ( $getPages ) {
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select( 'page_restrictions', '*',
- array ( 'pr_page' => $this->getArticleId() ), __METHOD__ );
+ array( 'pr_page' => $this->getArticleId() ), __METHOD__ );
$this->loadRestrictionsFromResultWrapper( $res, $oldFashionedRestrictions );
} else {
*/
static function purgeExpiredRestrictions() {
$dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'page_restrictions',
+ $dbw->delete(
+ 'page_restrictions',
array( 'pr_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
- __METHOD__ );
+ __METHOD__
+ );
- $dbw->delete( 'protected_titles',
+ $dbw->delete(
+ 'protected_titles',
array( 'pt_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
- __METHOD__ );
+ __METHOD__
+ );
}
/**
* @return \type{\bool}
*/
public function isRedirect( $flags = 0 ) {
- if ( !is_null( $this->mRedirect ) )
+ if ( !is_null( $this->mRedirect ) ) {
return $this->mRedirect;
+ }
# Calling getArticleID() loads the field from cache as needed
if ( !$this->getArticleID( $flags ) ) {
return $this->mRedirect = false;
* @return \type{\bool}
*/
public function getLength( $flags = 0 ) {
- if ( $this->mLength != -1 )
+ if ( $this->mLength != -1 ) {
return $this->mLength;
+ }
# Calling getArticleID() loads the field from cache as needed
if ( !$this->getArticleID( $flags ) ) {
return $this->mLength = 0;
* What is the page_latest field for this page?
*
* @param $flags \type{\int} a bit field; may be GAID_FOR_UPDATE to select for update
- * @return \type{\int} or false if the page doesn't exist
+ * @return \type{\int} or 0 if the page doesn't exist
*/
public function getLatestRevID( $flags = 0 ) {
- if ( $this->mLatestID !== false )
- return $this->mLatestID;
+ if ( $this->mLatestID !== false ) {
+ return intval( $this->mLatestID );
+ }
+ # Calling getArticleID() loads the field from cache as needed
+ if ( !$this->getArticleID( $flags ) ) {
+ return $this->mLatestID = 0;
+ }
+ $linkCache = LinkCache::singleton();
+ $this->mLatestID = intval( $linkCache->getGoodLinkFieldObj( $this, 'revision' ) );
- $db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
- $this->mLatestID = (int)$db->selectField(
- 'page', 'page_latest', $this->pageCond(), __METHOD__ );
return $this->mLatestID;
}
return;
}
$dbw = wfGetDB( DB_MASTER );
- $success = $dbw->update( 'page',
+ $success = $dbw->update(
+ 'page',
array( 'page_touched' => $dbw->timestamp() ),
$this->pageCond(),
__METHOD__
public static function capitalize( $text, $ns = NS_MAIN ) {
global $wgContLang;
- if ( MWNamespace::isCapitalized( $ns ) )
+ if ( MWNamespace::isCapitalized( $ns ) ) {
return $wgContLang->ucfirst( $text );
- else
+ } else {
return $text;
+ }
}
/**
$this->mNamespace = $ns;
# For Talk:X pages, check if X has a "namespace" prefix
if ( $ns == NS_TALK && preg_match( $prefixRegexp, $dbkey, $x ) ) {
- if ( $wgContLang->getNsIndex( $x[1] ) )
+ if ( $wgContLang->getNsIndex( $x[1] ) ) {
return false; # Disallow Talk:File:x type titles...
- else if ( Interwiki::isValidInterwiki( $x[1] ) )
+ } else if ( Interwiki::isValidInterwiki( $x[1] ) ) {
return false; # Disallow Talk:Interwiki:x type titles...
+ }
}
} elseif ( Interwiki::isValidInterwiki( $p ) ) {
if ( !$firstPass ) {
}
$fragment = strstr( $dbkey, '#' );
if ( false !== $fragment ) {
- $this->setFragment( $fragment );
+ $this->setFragment( preg_replace( '/^#_*/', '#', $fragment ) );
$dbkey = substr( $dbkey, 0, strlen( $dbkey ) - strlen( $fragment ) );
# remove whitespace again: prevents "Foo_bar_#"
# becoming "Foo_bar_"
* site might be case-sensitive.
*/
$this->mUserCaseDBKey = $dbkey;
- if ( $this->mInterwiki == '' ) {
+ if ( $this->mInterwiki == '' ) {
$dbkey = self::capitalize( $dbkey, $this->mNamespace );
}
$db = wfGetDB( DB_SLAVE );
}
- $res = $db->select( array( 'page', $table ),
- array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect' ),
+ $res = $db->select(
+ array( 'page', $table ),
+ array( 'page_namespace', 'page_title', 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ),
array(
"{$prefix}_from=page_id",
"{$prefix}_namespace" => $this->getNamespace(),
"{$prefix}_title" => $this->getDBkey() ),
__METHOD__,
- $options );
+ $options
+ );
$retVal = array();
if ( $db->numRows( $res ) ) {
foreach ( $res as $row ) {
if ( $titleObj = Title::makeTitle( $row->page_namespace, $row->page_title ) ) {
- $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect );
+ $linkCache->addGoodLinkObj( $row->page_id, $titleObj, $row->page_len, $row->page_is_redirect, $row->page_latest );
$retVal[] = $titleObj;
}
}
}
- $db->freeResult( $res );
return $retVal;
}
if ( $wgContLang->hasVariants() ) {
$variants = $wgContLang->getVariants();
foreach ( $variants as $vCode ) {
- if ( $vCode == $wgContLang->getCode() ) continue; // we don't want default variant
$urls[] = $this->getInternalURL( '', $vCode );
}
}
// Image-specific checks
if ( $this->getNamespace() == NS_FILE ) {
+ if ( $nt->getNamespace() != NS_FILE ) {
+ $errors[] = array( 'imagenocrossnamespace' );
+ }
$file = wfLocalFile( $this );
if ( $file->exists() ) {
- if ( $nt->getNamespace() != NS_FILE ) {
- $errors[] = array( 'imagenocrossnamespace' );
- }
if ( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) {
$errors[] = array( 'imageinvalidfilename' );
}
if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) {
$errors[] = array( 'file-exists-sharedrepo' );
}
+ }
+ if ( $nt->getNamespace() == NS_FILE && $this->getNamespace() != NS_FILE ) {
+ $errors[] = array( 'nonfile-cannot-move-to-file' );
}
if ( $auth ) {
# (so we can undo bad moves right after they're done).
if ( 0 != $newid ) { # Target exists; check for validity
- if ( ! $this->isValidMoveTarget( $nt ) ) {
+ if ( !$this->isValidMoveTarget( $nt ) ) {
$errors[] = array( 'articleexists' );
}
} else {
$errors[] = array( 'cantmove-titleprotected' );
}
}
- if ( empty( $errors ) )
+ if ( empty( $errors ) ) {
return true;
+ }
return $errors;
}
* @return \type{\mixed} true on success, getUserPermissionsErrors()-like array on failure
*/
public function moveTo( &$nt, $auth = true, $reason = '', $createRedirect = true ) {
+ global $wgContLang;
+
$err = $this->isValidMoveOperation( $nt, $auth, $reason );
if ( is_array( $err ) ) {
return $err;
}
$redirid = $this->getArticleID();
- // Category memberships include a sort key which may be customized.
- // If it's left as the default (the page title), we need to update
- // the sort key to match the new title.
- //
- // Be careful to avoid resetting cl_timestamp, which may disturb
- // time-based lists on some sites.
- //
- // Warning -- if the sort key is *explicitly* set to the old title,
- // we can't actually distinguish it from a default here, and it'll
- // be set to the new title even though it really shouldn't.
- // It'll get corrected on the next edit, but resetting cl_timestamp.
+ // Refresh the sortkey for this row. Be careful to avoid resetting
+ // cl_timestamp, which may disturb time-based lists on some sites.
+ $prefix = $dbw->selectField(
+ 'categorylinks',
+ 'cl_sortkey_prefix',
+ array( 'cl_from' => $pageid ),
+ __METHOD__
+ );
$dbw->update( 'categorylinks',
array(
- 'cl_sortkey' => $nt->getPrefixedText(),
+ 'cl_sortkey' => $wgContLang->convertToSortkey( $nt->getCategorySortkey( $prefix ) ),
'cl_timestamp=cl_timestamp' ),
- array(
- 'cl_from' => $pageid,
- 'cl_sortkey' => $this->getPrefixedText() ),
+ array( 'cl_from' => $pageid ),
__METHOD__ );
if ( $protected ) {
# Update the protection log
$log = new LogPage( 'protect' );
$comment = wfMsgForContent( 'prot_1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
- if ( $reason ) $comment .= wfMsgForContent( 'colon-separator' ) . $reason;
+ if ( $reason ) {
+ $comment .= wfMsgForContent( 'colon-separator' ) . $reason;
+ }
$log->addEntry( 'move_prot', $nt, $comment, array( $this->getPrefixedText() ) ); // FIXME: $params?
}
# Nothing special
$u = false;
}
- if ( $u )
+ if ( $u ) {
$u->doUpdate();
+ }
# Update message cache for interface messages
- if ( $nt->getNamespace() == NS_MEDIAWIKI ) {
- global $wgMessageCache;
-
+ global $wgMessageCache;
+ if ( $this->getNamespace() == NS_MEDIAWIKI ) {
# @bug 17860: old article can be deleted, if this the case,
# delete it from message cache
if ( $this->getArticleID() === 0 ) {
$oldarticle = new Article( $this );
$wgMessageCache->replace( $this->getDBkey(), $oldarticle->getContent() );
}
-
+ }
+ if ( $nt->getNamespace() == NS_MEDIAWIKI ) {
$newarticle = new Article( $nt );
$wgMessageCache->replace( $nt->getDBkey(), $newarticle->getContent() );
}
if ( !$dbw->cascadingDeletes() ) {
$dbw->delete( 'revision', array( 'rev_page' => $newid ), __METHOD__ );
global $wgUseTrackbacks;
- if ( $wgUseTrackbacks )
+ if ( $wgUseTrackbacks ) {
$dbw->delete( 'trackbacks', array( 'tb_page' => $newid ), __METHOD__ );
+ }
$dbw->delete( 'pagelinks', array( 'pl_from' => $newid ), __METHOD__ );
$dbw->delete( 'imagelinks', array( 'il_from' => $newid ), __METHOD__ );
$dbw->delete( 'categorylinks', array( 'cl_from' => $newid ), __METHOD__ );
* Ignored if the user doesn't have the suppressredirect right
*/
private function moveToNewTitle( &$nt, $reason = '', $createRedirect = true ) {
- global $wgUseSquid, $wgUser, $wgContLang;
+ global $wgUser, $wgContLang;
$comment = wfMsgForContent( '1movedto2', $this->getPrefixedText(), $nt->getPrefixedText() );
if ( $reason ) {
# Purge old title from squid
# The new title, and links to the new title, are purged in Article::onArticleCreate()
$this->purgeSquid();
-
}
/**
public function moveSubpages( $nt, $auth = true, $reason = '', $createRedirect = true ) {
global $wgMaximumMovedPages;
// Check permissions
- if ( !$this->userCan( 'move-subpages' ) )
+ if ( !$this->userCan( 'move-subpages' ) ) {
return array( 'cant-move-subpages' );
+ }
// Do the source and target namespaces support subpages?
- if ( !MWNamespace::hasSubpages( $this->getNamespace() ) )
+ if ( !MWNamespace::hasSubpages( $this->getNamespace() ) ) {
return array( 'namespace-nosubpages',
MWNamespace::getCanonicalName( $this->getNamespace() ) );
- if ( !MWNamespace::hasSubpages( $nt->getNamespace() ) )
+ }
+ if ( !MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
return array( 'namespace-nosubpages',
MWNamespace::getCanonicalName( $nt->getNamespace() ) );
+ }
$subpages = $this->getSubpages( $wgMaximumMovedPages + 1 );
$retval = array();
// $this and $nt
if ( $oldSubpage->getArticleId() == $this->getArticleId() ||
$oldSubpage->getArticleID() == $nt->getArticleId() )
+ {
// When moving a page to a subpage of itself,
// don't move it twice
continue;
+ }
$newPageName = preg_replace(
'#^' . preg_quote( $this->getDBkey(), '#' ) . '#',
StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
* @return \type{\bool} TRUE or FALSE
*/
public function isValidMoveTarget( $nt ) {
- $dbw = wfGetDB( DB_MASTER );
- # Is it an existsing file?
+ # Is it an existing file?
if ( $nt->getNamespace() == NS_FILE ) {
$file = wfLocalFile( $nt );
if ( $file->exists() ) {
foreach ( $res as $row )
// $data[] = Title::newFromText($wgContLang->getNSText ( NS_CATEGORY ).':'.$row->cl_to);
$data[$wgContLang->getNSText( NS_CATEGORY ) . ':' . $row->cl_to] = $this->getFullText();
- $dbr->freeResult( $res );
} else {
$data = array();
}
public function getFirstRevision( $flags = 0 ) {
$db = ( $flags & GAID_FOR_UPDATE ) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
$pageId = $this->getArticleId( $flags );
- if ( !$pageId ) return null;
+ if ( !$pageId ) {
+ return null;
+ }
$row = $db->selectRow( 'revision', '*',
array( 'rev_page' => $pageId ),
__METHOD__,
switch( $this->mNamespace ) {
case NS_MEDIA:
case NS_FILE:
- return wfFindFile( $this ); // file exists, possibly in a foreign repo
+ return (bool)wfFindFile( $this ); // file exists, possibly in a foreign repo
case NS_SPECIAL:
return SpecialPage::exists( $this->getDBkey() ); // valid special page
case NS_MAIN:
* @return \type{\bool}
*/
public function isKnown() {
- return $this->exists() || $this->isAlwaysKnown();
+ return $this->isAlwaysKnown() || $this->exists();
}
/**
* @return Boolean
*/
public function hasSourceText() {
- if ( $this->exists() )
+ if ( $this->exists() ) {
return true;
+ }
if ( $this->mNamespace == NS_MEDIAWIKI ) {
// If the page doesn't exist but is a known system message, default
}
/**
- * Is this in a namespace that allows actual pages?
- *
- * @return \type{\bool}
- * @internal note -- uses hardcoded namespace index instead of constants
- */
+ * Is this in a namespace that allows actual pages?
+ *
+ * @return \type{\bool}
+ * @internal note -- uses hardcoded namespace index instead of constants
+ */
public function canExist() {
return $this->mNamespace >= 0 && $this->mNamespace != NS_MEDIA;
}
public function getNotificationTimestamp( $user = null ) {
global $wgUser, $wgShowUpdatedMarker;
// Assume current user if none given
- if ( !$user ) $user = $wgUser;
+ if ( !$user ) {
+ $user = $wgUser;
+ }
// Check cache first
$uid = $user->getId();
if ( isset( $this->mNotificationTimestamp[$uid] ) ) {
*
* @return boolean
*/
- public function isSpecialPage( ) {
+ public function isSpecialPage() {
return $this->getNamespace() == NS_SPECIAL;
}
'rd_title' => $this->getDBkey(),
'rd_from = page_id'
);
- if ( !is_null( $ns ) ) $where['page_namespace'] = $ns;
+ if ( !is_null( $ns ) ) {
+ $where['page_namespace'] = $ns;
+ }
$res = $dbr->select(
array( 'redirect', 'page' ),
* @return Boolean
*/
public function canUseNoindex() {
- global $wgArticleRobotPolicies, $wgContentNamespaces,
- $wgExemptFromUserRobotsControl;
+ global $wgContentNamespaces, $wgExemptFromUserRobotsControl;
$bannedNamespaces = is_null( $wgExemptFromUserRobotsControl )
? $wgContentNamespaces
return $types;
}
+
+ /**
+ * Returns the raw sort key to be used for categories, with the specified
+ * prefix. This will be fed to Language::convertToSortkey() to get a
+ * binary sortkey that can be used for actual sorting.
+ *
+ * @param $prefix string The prefix to be used, specified using
+ * {{defaultsort:}} or like [[Category:Foo|prefix]]. Empty for no
+ * prefix.
+ * @return string
+ */
+ public function getCategorySortkey( $prefix = '' ) {
+ $unprefixed = $this->getText();
+ if ( $prefix !== '' ) {
+ # Separate with a null byte, so the unprefixed part is only used as
+ # a tiebreaker when two pages have the exact same prefix -- null
+ # sorts before everything else (hopefully).
+ return "$prefix\0$unprefixed";
+ }
+ return $unprefixed;
+ }
}