// and URL-decode links
if ( strpos( $m[1], '%' ) !== false ) {
// Match behavior of inline link parsing here;
- // don't interpret + as " " most of the time!
- // It might be safe to just use rawurldecode instead, though.
- $m[1] = urldecode( ltrim( $m[1], ':' ) );
+ $m[1] = rawurldecode( ltrim( $m[1], ':' ) );
}
$title = Title::newFromText( $m[1] );
// If the title is a redirect to bad special pages or is invalid, return null
}
/**
- * Determines if $wgUser is unable to edit this page because it has been protected
+ * Determines if $user is unable to edit this page because it has been protected
* by $wgNamespaceProtection.
*
+ * @param $user User object, $wgUser will be used if not passed
* @return \type{\bool}
*/
- public function isNamespaceProtected() {
- global $wgNamespaceProtection, $wgUser;
+ public function isNamespaceProtected( User $user = null ) {
+ global $wgNamespaceProtection;
+
+ if ( $user === null ) {
+ global $wgUser;
+ $user = $wgUser;
+ }
+
if ( isset( $wgNamespaceProtection[$this->mNamespace] ) ) {
foreach ( (array)$wgNamespaceProtection[$this->mNamespace] as $right ) {
- if ( $right != '' && !$wgUser->isAllowed( $right ) ) {
+ if ( $right != '' && !$user->isAllowed( $right ) ) {
return true;
}
}
}
# Check $wgNamespaceProtection for restricted namespaces
- if ( $this->isNamespaceProtected() ) {
+ if ( $this->isNamespaceProtected( $user ) ) {
$ns = $this->mNamespace == NS_MAIN ?
wfMsg( 'nstab-main' ) : $this->getNsText();
$errors[] = $this->mNamespace == NS_MEDIAWIKI ?
* Uses link cache, adding it if necessary
*
* @param $flags \type{\int} a bit field; may be Title::GAID_FOR_UPDATE to select for update
- * @return \type{\bool}
+ * @return \type{\int}
*/
public function getLength( $flags = 0 ) {
if ( $this->mLength != -1 ) {
* This clears some fields in this object, and clears any associated
* keys in the "bad links" section of the link cache.
*
- * - This is called from Article::insertNewArticle() to allow
+ * - This is called from Article::doEdit() and Article::insertOn() to allow
* loading of the new page_id. It's also called from
* Article::doDeleteArticle()
*
*/
public function countRevisionsBetween( $old, $new ) {
$dbr = wfGetDB( DB_SLAVE );
- return (int)$dbr->selectField( 'revision', 'count(*)',
- 'rev_page' => intval( $this->getArticleId() ) .
- ' AND rev_id > ' . intval( $old ) .
- ' AND rev_id < ' . intval( $new ),
- __METHOD__
+ return (int)$dbr->selectField( 'revision', 'count(*)', array(
+ 'rev_page' => intval( $this->getArticleId() ),
+ 'rev_id > ' . intval( $old ),
+ 'rev_id < ' . intval( $new )
+ ), __METHOD__
);
}