Various tweaks for last commit, including a merge of the functions to determine if an image/page is cascade-protected; message changes, et cetera

This commit is contained in:
Andrew Garrett 2007-01-12 08:37:07 +00:00
parent 1d95a6efa9
commit ff67bbdda8
5 changed files with 49 additions and 86 deletions

View file

@ -962,9 +962,10 @@ class EditPage {
}
}
$cascadeSources = $this->mTitle->getCascadeProtectionSources();
if( $this->mTitle->isProtected( 'edit' ) ) {
$cascadeSources = $this->mTitle->getCascadeProtectionSources( true );
# Is the protection due to the namespace, e.g. interface text?
if( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
# Yes; remind the user
@ -975,15 +976,15 @@ class EditPage {
if( wfEmptyMsg( 'semiprotectedpagewarning', $notice ) || $notice == '-' ) {
$notice = '';
}
} elseif (count($cascadeSources) > 0) {
} elseif ($cascadeSources && count($cascadeSources) > 0) {
# Cascaded protection: warn the user.
$titles = '';
foreach ( $cascadeSources as $title ) {
$titles .= '* ' . $title->getPrefixedText() . "\r\n";
}
$notice = wfMsgForContent( 'cascadeprotectedwarning', $titles );
$notice = wfMsg( 'cascadeprotectedwarning' ) . "\r\n$titles";
} else {
# No; regular protection
$notice = wfMsg( 'protectedpagewarning' );

View file

@ -899,14 +899,16 @@ class OutputPage {
# and show an appropriate explanation
if( $wgTitle->getNamespace() == NS_MEDIAWIKI ) {
$this->addWikiText( wfMsg( 'protectedinterface' ) );
} if ( count($cascadeSources) ) {
} if ( $cascadeSources && count($cascadeSources) > 0 ) {
$titles = '';
foreach ( $cascadeSources as $title ) {
$titles .= '* ' . $title->getPrefixedText() . "\r\n";
}
$this->addWikiText( wfMsgForContent( 'cascadeprotected', $titles ) );
$notice = wfMsg( 'cascadeprotected' ) . "\r\n$titles";
$this->addWikiText( $notice );
} else {
$this->addWikiText( wfMsg( 'protectedpagetext' ) );
}

View file

@ -75,14 +75,16 @@ class ProtectionForm {
$cascadeSources = $this->mTitle->getCascadeProtectionSources();
if ( count($cascadeSources) > 0 ) {
if ( $cascadeSources && count($cascadeSources) > 0 ) {
$titles = '';
foreach ( $cascadeSources as $title ) {
$titles .= '* ' . $title->getPrefixedText() . "\r\n";
}
$wgOut->addWikiText( wfMsgForContent( 'protect-cascadeon', $titles ) );
$notice = wfMsg( 'protect-cascadeon' ) . "\r\n$titles";
$wgOut->addWikiText( $notice );
}
if( $this->save() ) {

View file

@ -1348,6 +1348,9 @@ class Title {
* @access public
*/
function getCascadeProtectionSources( $get_pages = true ) {
global $wgEnableCascadingProtection;
if (!$wgEnableCascadingProtection)
return false;
if ( isset( $this->mCascadeSources ) && $get_pages ) {
return $this->mCascadeSources;
@ -1355,94 +1358,52 @@ class Title {
return $this->mHasCascadingRestrictions;
}
$sources = NULL;
wfProfileIn( __METHOD__ );
$dbr =& wfGetDb( DB_SLAVE );
if ( $this->getNamespace() == NS_IMAGE ) {
$sources = $this->getCascadeProtectedImageSources( $get_pages );
$cols = $get_pages ? array('pr_page', 'page_namespace', 'page_title') : array( '1' );
$tables = array ('imagelinks', 'page_restrictions', 'page');
$where_clauses = array( 'il_to' => $this->getDBkey(), 'il_from=pr_page', 'pr_cascade' => 1 );
} else {
$sources = $this->getCascadeProtectedPageSources( $get_pages );
$cols = $get_pages ? array( 'pr_page', 'page_namespace', 'page_title' ) : array( '1' );
$tables = array ('templatelinks', 'page_restrictions', 'page');
$where_clauses = array( 'tl_namespace' => $this->getNamespace(), 'tl_title' => $this->getDBkey(), 'tl_from=pr_page', 'pr_cascade' => 1 );
}
if ( $get_pages ) { $this->mCascadeSources = $sources; }
else { $this->mHasCascadingRestrictions = $sources; }
return $sources;
}
/**
* Cascading protects: Check if the current image is protected due to a cascading restriction
*
* @param $get_pages bool Whether or not to retrieve the actual pages that the restrictions have come from.
* @return mixed Array of the Title objects of the pages from which cascading restrictions have come, false for none, or true if such restrictions exist, but $get_pages was not set.
* @access public
*/
function getCascadeProtectedImageSources( $get_pages = true ) {
global $wgEnableCascadingProtection;
if (!$wgEnableCascadingProtection)
return false;
wfProfileIn(__METHOD__);
$dbr =& wfGetDb( DB_SLAVE );
$cols = $get_pages ? array('pr_page') : array( 'il_to' );
$tables = array ('imagelinks', 'page_restrictions');
$where_clauses = array( 'il_to' => $this->getDBkey(), 'il_from=pr_page', 'pr_cascade' => 1 );
$res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__);
if ( $dbr->numRows($res) ) {
if ($get_pages) {
$culprits = array ();
while ($row = $dbr->fetchObject($res)) {
$page_id = $row->pr_page;
$culprits[$page_id] = Title::newFromId($page_id);
}
} else { return true; }
wfProfileOut(__METHOD__);
return $culprits;
} else {
wfProfileOut(__METHOD__);
return false;
if ( $get_pages ) {
$where_clauses[] = 'page_id=pr_page';
}
}
/**
* Cascading protects: Check if the current page is protected due to a cascading restriction.
*
* @param $get_pages bool Whether or not to retrieve the actual pages that the restrictions have come from.
* @return mixed Array of the Title objects of the pages from which cascading restrictions have come, false for none, or true if such restrictions exist, but $get_pages was not set.
* @access public
*/
function getCascadeProtectedPageSources( $get_pages = true ) {
global $wgEnableCascadingProtection;
if (!$wgEnableCascadingProtection)
return false;
wfProfileIn(__METHOD__);
$dbr =& wfGetDb( DB_SLAVE );
$cols = $get_pages ? array( 'pr_page' ) : array( 'tl_title' );
$tables = array ('templatelinks', 'page_restrictions');
$where_clauses = array( 'tl_namespace' => $this->getNamespace(), 'tl_title' => $this->getDBkey(), 'tl_from=pr_page', 'pr_cascade' => 1 );
#!$get_pages or die( var_dump( array( $cols, $tables, $where_clauses ) ) );
$res = $dbr->select( $tables, $cols, $where_clauses, __METHOD__);
if ($dbr->numRows($res)) {
if ($get_pages) {
$culprits = array ();
$sources = array ();
while ($row = $dbr->fetchObject($res)) {
$page_id = $row->pr_page;
$culprits[$page_id] = Title::newFromId($page_id);
$page_ns = $row->page_namespace;
$page_title = $row->page_title;
$sources[$page_id] = Title::makeTitle($page_ns, $page_title);
}
} else { return true; }
wfProfileOut(__METHOD__);
return $culprits;
} else { $sources = true; }
} else {
wfProfileOut(__METHOD__);
return false;
$sources = false;
}
wfProfileOut( __METHOD__ );
if ( $get_pages ) {
$this->mCascadeSources = $sources;
}
else {
$this->mHasCascadingRestrictions = $sources;
}
return $sources;
}
function areRestrictionsCascading() {

View file

@ -780,8 +780,7 @@ Query: $2',
'protectedinterface' => 'This page provides interface text for the software, and is locked to prevent abuse.',
'editinginterface' => "'''Warning:''' You are editing a page which is used to provide interface text for the software. Changes to this page will affect the appearance of the user interface for other users.",
'sqlhidden' => '(SQL query hidden)',
'cascadeprotected' => 'This page has been protected from editing, because it is included in the following pages, which are protected with the "cascading" option turned on:
$1',
'cascadeprotected' => 'This page has been protected from editing, because it is included in the following pages, which are protected with the "cascading" option turned on:',
# Login and logout pages
#
@ -1016,8 +1015,7 @@ so you will not be able to save your edits right now. You may wish to cut-n-past
the text into a text file and save it for later.</strong>',
'protectedpagewarning' => "<strong>WARNING: This page has been locked so that only users with sysop privileges can edit it.</strong>",
'semiprotectedpagewarning' => "'''Note:''' This page has been locked so that only registered users can edit it.",
'cascadeprotectedwarning' => "<strong>WARNING: This page has been locked so that only users with sysop privileges can edit it, because it is included in the following pages, which are protected with the 'cascading protection' option turned on.</strong>:
$1",
'cascadeprotectedwarning' => "<strong>WARNING: This page has been locked so that only users with sysop privileges can edit it, because it is included in the following pages, which are protected with the 'cascading protection' option turned on.</strong>:",
'templatesused' => 'Templates used on this page:',
'templatesusedpreview' => 'Templates used in this preview:',
'templatesusedsection' => 'Templates used in this section:',
@ -1747,8 +1745,7 @@ Please hit "back" and reload the page you came from, then try again.',
'protect-text' => 'You may view and change the protection level here for the page <strong>$1</strong>.',
'protect-viewtext' => 'Your account does not have permission to change
page protection levels. Here are the current settings for the page <strong>$1</strong>:',
'protect-cascadeon' => 'This page is currently subject to cascading protection, because it is included in the following pages, which are protected with the "cascading protection" option turned on. You can change the protection level for this page here, but it will not affect the cascading protection:
$1',
'protect-cascadeon' => 'This page is currently subject to cascading protection, because it is included in the following pages, which are protected with the "cascading protection" option turned on. You can change the protection level for this page here, but it will not affect the cascading protection:',
'protect-default' => '(default)',
'protect-level-autoconfirmed' => 'Block unregistered users',
'protect-level-sysop' => 'Sysops only',