+ /**
+ * Is this title subject to title protection?
+ * @return mixed An associative array representing any existent title
+ * protection, or false if there's none.
+ */
+ private function getTitleProtection() {
+ // Can't protect pages in special namespaces
+ if ( $this->getNamespace() < 0 ) {
+ return false;
+ }
+
+ $dbr = wfGetDB( DB_SLAVE );
+ $res = $dbr->select( 'protected_titles', '*',
+ array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()) );
+
+ if ($row = $dbr->fetchRow( $res )) {
+ return $row;
+ } else {
+ return false;
+ }
+ }
+
+ public function updateTitleProtection( $create_perm, $reason, $expiry ) {
+ global $wgGroupPermissions,$wgUser,$wgContLang;
+
+ if ($create_perm == implode(',',$this->getRestrictions('create'))
+ && $expiry == $this->mRestrictionsExpiry) {
+ // No change
+ return true;
+ }
+
+ list ($namespace, $title) = array( $this->getNamespace(), $this->getDBkey() );
+
+ $dbw = wfGetDB( DB_MASTER );
+
+ $encodedExpiry = Block::encodeExpiry($expiry, $dbw );
+
+ $expiry_description = '';
+ if ( $encodedExpiry != 'infinity' ) {
+ $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ) ).')';
+ }
+
+ # Update protection table
+ if ($create_perm != '' ) {
+ $dbw->replace( 'protected_titles', array(array('pt_namespace', 'pt_title')),
+ array( 'pt_namespace' => $namespace, 'pt_title' => $title
+ , 'pt_create_perm' => $create_perm
+ , 'pt_timestamp' => Block::encodeExpiry(wfTimestampNow(), $dbw)
+ , 'pt_expiry' => $encodedExpiry
+ , 'pt_user' => $wgUser->getId(), 'pt_reason' => $reason ), __METHOD__ );
+ } else {
+ $dbw->delete( 'protected_titles', array( 'pt_namespace' => $namespace,
+ 'pt_title' => $title ), __METHOD__ );
+ }
+ # Update the protection log
+ $log = new LogPage( 'protect' );
+
+ if( $create_perm ) {
+ $log->addEntry( $this->mRestrictions['create'] ? 'modify' : 'protect', $this, trim( $reason . " [create=$create_perm] $expiry_description" ) );
+ } else {
+ $log->addEntry( 'unprotect', $this, $reason );
+ }
+
+ return true;
+ }
+
+ /**
+ * Remove any title protection (due to page existing
+ */
+ public function deleteTitleProtection() {
+ $dbw = wfGetDB( DB_MASTER );
+
+ $dbw->delete( 'protected_titles',
+ array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()), __METHOD__ );
+ }
+