bug #868.
$this->mCounter = $s->cur_counter;
$this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
$this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
- $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) );
- $this->mTitle->mRestrictionsLoaded = true;
+ $this->mTitle->loadRestrictions( $s->cur_restrictions );
} else { # oldid set, retrieve historical version
$s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ),
$fname, $this->getSelectOptions() );
$this->mCounter = $s->cur_counter;
$this->mTimestamp = wfTimestamp(TS_MW,$s->cur_timestamp);
$this->mTouched = wfTimestamp(TS_MW,$s->cur_touched);
- $this->mTitle->mRestrictions = explode( ',', trim( $s->cur_restrictions ) );
- $this->mTitle->mRestrictionsLoaded = true;
+ $this->mTitle->loadRestrictions( $s->cur_restrictions );
} else { # oldid set, retrieve historical version
$s = $dbr->selectRow( 'old', $this->getOldContentFields(), array( 'old_id' => $oldid ),
$fname, $this->getSelectOptions() );
}
$confirm = $wgRequest->getBool( 'wpConfirmProtect' ) && $wgRequest->wasPosted();
+ $moveonly = $wgRequest->getBool( 'wpMoveOnly' );
$reason = $wgRequest->getText( 'wpReasonProtect' );
if ( $confirm ) {
+ $restrictions = "move=" . $limit;
+ if( !$moveonly ) {
+ $restrictions .= ":edit=" . $limit;
+ }
+
$dbw =& wfGetDB( DB_MASTER );
$dbw->update( 'cur',
array( /* SET */
'cur_touched' => $dbw->timestamp(),
- 'cur_restrictions' => (string)$limit
+ 'cur_restrictions' => $restrictions
), array( /* WHERE */
'cur_id' => $id
), 'Article::protect'
$check = '';
$protcom = '';
+ $moveonly = '';
if ( $limit === '' ) {
$wgOut->setPageTitle( wfMsg( 'confirmunprotect' ) );
$wgOut->setSubtitle( wfMsg( 'protectsub', $sub ) );
$wgOut->addWikiText( wfMsg( 'confirmprotecttext' ) );
$check = htmlspecialchars( wfMsg( 'confirmprotect' ) );
+ $moveonly = htmlspecialchars( wfMsg( 'protectmoveonly' ) );
$protcom = htmlspecialchars( wfMsg( 'protectcomment' ) );
$formaction = $this->mTitle->escapeLocalURL( 'action=protect' . $par );
}
<td>
<label for='wpConfirmProtect'>{$check}</label>
</td>
- </tr>
+ </tr> " );
+ if($moveonly != '') {
+ $wgOut->AddHTML( "
+ <tr>
+ <td align='right'>
+ <input type='checkbox' name='wpMoveOnly' value='1' id='wpMoveOnly' />
+ </td>
+ <td>
+ <label for='wpMoveOnly'>{$moveonly}</label>
+ </td>
+ </tr> " );
+ }
+ $wgOut->addHTML( "
<tr>
<td> </td>
<td>
} else if ( $isCssJsSubpage and 'preview' != $formtype) {
$wgOut->addHTML( wfMsg( 'usercssjsyoucanpreview' ));
}
- if( $this->mTitle->isProtected() ) {
+ if( $this->mTitle->isProtected('edit') ) {
$wgOut->addHTML( '<strong>' . wfMsg( 'protectedpagewarning' ) .
"</strong><br />\n" );
}
function moveThisPage() {
global $wgTitle, $wgContLang;
- if ( $wgTitle->userCanEdit() ) {
+ if ( $wgTitle->userCanMove() ) {
$s = $this->makeKnownLink( $wgContLang->specialPage( 'Movepage' ),
wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
} // no message if page is protected - would be redundant
$tpl->set( "editable", ($wgTitle->getNamespace() != NS_SPECIAL ) );
$tpl->set( "exists", $wgTitle->getArticleID() != 0 );
$tpl->set( "watch", $wgTitle->userIsWatching() ? "unwatch" : "watch" );
- $tpl->set( "protect", count($wgTitle->getRestrictions()) ? "unprotect" : "protect" );
+ $tpl->set( "protect", count($wgTitle->isProtected()) ? "unprotect" : "protect" );
$tpl->set( "helppage", wfMsg('helppage'));
*/
$tpl->set( 'searchaction', $this->escapeSearchLink() );
);
}
if ( $wgUser->getID() != 0 ) {
- if ( $wgTitle->userCanEdit()) {
+ if ( $wgTitle->userCanMove()) {
$content_actions['move'] = array(
'class' => ($wgTitle->getDbKey() == 'Movepage' and $wgTitle->getNamespace == Namespace::getSpecial()) ? 'selected' : false,
'text' => wfMsg('move'),
/**
* Does the title correspond to a protected article?
+ * @param string $what the action the page is protected from,
+ * by default checks move and edit
* @return boolean
* @access public
*/
- function isProtected() {
+ function isProtected($action = '') {
if ( -1 == $this->mNamespace ) { return true; }
- $a = $this->getRestrictions();
- if ( in_array( 'sysop', $a ) ) { return true; }
+ if($action == 'edit' || $action == '') {
+ $a = $this->getRestrictions("edit");
+ if ( in_array( 'sysop', $a ) ) { return true; }
+ }
+ if($action == 'move' || $action == '') {
+ $a = $this->getRestrictions("move");
+ if ( in_array( 'sysop', $a ) ) { return true; }
+ }
return false;
}
return $wgUser->isWatched( $this );
}
- /**
- * Can $wgUser edit this page?
+ /**
+ * Is $wgUser perform $action this page?
+ * @param string $action action that permission needs to be checked for
* @return boolean
- * @access public
- */
- function userCanEdit() {
+ * @access private
+ */
+ function userCan($action) {
$fname = 'Title::userCanEdit';
wfProfileIn( $fname );
return false;
}
- foreach( $this->getRestrictions() as $right ) {
+ foreach( $this->getRestrictions($action) as $right ) {
if( '' != $right && !$wgUser->isAllowed( $right ) ) {
wfProfileOut( $fname );
return false;
return true;
}
+ /**
+ * Can $wgUser edit this page?
+ * @return boolean
+ * @access public
+ */
+ function userCanEdit() {
+ return $this->userCan('edit');
+ }
+
+ /**
+ * Can $wgUser move this page?
+ * @return boolean
+ * @access public
+ */
+ function userCanMove() {
+ return $this->userCan('move');
+ }
+
/**
* Can $wgUser read this page?
* @return boolean
return ( $wgUser->isAllowed('editinterface') or preg_match('/^'.preg_quote($wgUser->getName(), '/').'\//', $this->mTextform) );
}
+ /**
+ * Loads a string into mRestrictions array
+ * @param string $res restrictions in string format
+ * @access public
+ */
+ function loadRestrictions( $res ) {
+ foreach( explode( ':', trim( $res ) ) as $restrict ) {
+ $temp = explode( '=', trim( $restrict ) );
+ if(count($temp) == 1) {
+ // old format should be treated as edit/move restriction
+ $this->mRestrictions["edit"] = explode( ',', trim( $temp[0] ) );
+ $this->mRestrictions["move"] = explode( ',', trim( $temp[0] ) );
+ } else {
+ $this->mRestrictions[$temp[0]] = explode( ',', trim( $temp[1] ) );
+ }
+ }
+ $this->mRestrictionsLoaded = true;
+ }
+
/**
* Accessor/initialisation for mRestrictions
+ * @param string $action action that permission needs to be checked for
* @return array the array of groups allowed to edit this article
* @access public
*/
- function getRestrictions() {
+ function getRestrictions($action) {
$id = $this->getArticleID();
if ( 0 == $id ) { return array(); }
if ( ! $this->mRestrictionsLoaded ) {
$dbr =& wfGetDB( DB_SLAVE );
$res = $dbr->selectField( 'cur', 'cur_restrictions', 'cur_id='.$id );
- $this->mRestrictions = explode( ',', trim( $res ) );
- $this->mRestrictionsLoaded = true;
+ $this->loadRestrictions( $res );
}
- return $this->mRestrictions;
+ $result = $this->mRestrictions[$action];
+ return $result ? $result : array();
}
/**
'protectsub' =>"(Protecting \"$1\")",
'confirmprotecttext' => 'Do you really want to protect this page?',
'confirmprotect' => 'Confirm protection',
+'protectmoveonly' => 'Protect from moves only',
'protectcomment' => 'Reason for protecting',
'unprotectsub' =>"(Unprotecting \"$1\")",
'confirmunprotecttext' => 'Do you really want to unprotect this page?',