API: Standardize limits. Use ApiBase constants to avoid similar breakage and inconsis...
[lhc/web/wiklou.git] / includes / Article.php
index e4fcc33..0b1b869 100644 (file)
@@ -47,6 +47,7 @@ class Article {
        const BAD_TITLE = 5;            // $this is not a valid Article
        const ALREADY_ROLLED = 6;       // Someone else already rolled this back. $from and $summary will be set
        const ONLY_AUTHOR = 7;          // User is the only author of the page
+       const RATE_LIMITED = 8;
  
        /**
         * Constructor and clear the article
@@ -869,7 +870,7 @@ class Article {
 
                # If we have been passed an &rcid= parameter, we want to give the user a
                # chance to mark this new article as patrolled.
-               if (!is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) ) {
+               if( !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) && $this->mTitle->exists() ) {
                        $wgOut->addHTML(
                                "<div class='patrollink'>" .
                                        wfMsgHtml( 'markaspatrolledlink',
@@ -1708,7 +1709,7 @@ class Article {
                global $wgUser, $wgRestrictionTypes, $wgContLang;
 
                $id = $this->mTitle->getArticleID();
-               if( !$wgUser->isAllowed( 'protect' ) || wfReadOnly() || $id == 0 ) {
+               if( array() != $this->mTitle->getUserPermissionsErrors( 'protect', $wgUser ) || wfReadOnly() || $id == 0 ) {
                        return false;
                }
 
@@ -1842,9 +1843,9 @@ class Article {
        
        /**
         * Auto-generates a deletion reason
-        * @param bool &$hashistory Whether the page has a history
+        * @param bool &$hasHistory Whether the page has a history
         */
-       public function generateReason(&$hashistory)
+       public function generateReason(&$hasHistory)
        {
                global $wgContLang;
                $dbw = wfGetDB(DB_MASTER);
@@ -1922,9 +1923,21 @@ class Article {
         */
        function delete() {
                global $wgUser, $wgOut, $wgRequest;
+
                $confirm = $wgRequest->wasPosted() &&
-                       $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
-               $reason = $wgRequest->getText( 'wpReason' );
+                               $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
+               
+               $this->DeleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
+               $this->DeleteReason = $wgRequest->getText( 'wpReason' );
+               
+               $reason = $this->DeleteReasonList;
+               
+               if ( $reason != 'other' && $this->DeleteReason != '') {
+                       // Entry from drop down menu + additional comment
+                       $reason .= ': ' . $this->DeleteReason;
+               } elseif ( $reason == 'other' ) {
+                       $reason = $this->DeleteReason;
+               }
 
                # This code desperately needs to be totally rewritten
 
@@ -2033,16 +2046,61 @@ class Article {
                $formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
 
                $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
-               $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
+               $delcom = Xml::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' );
                $token = htmlspecialchars( $wgUser->editToken() );
                $watch = Xml::checkLabel( wfMsg( 'watchthis' ), 'wpWatch', 'wpWatch', $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching(), array( 'tabindex' => '2' ) );
-
+               
+               $mDeletereasonother = Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' );
+               $mDeletereasonotherlist = wfMsgHtml( 'deletereasonotherlist' );
+               $scDeleteReasonList = wfMsgForContent( 'deletereason-dropdown' );
+
+               $deleteReasonList = '';
+               if ( $scDeleteReasonList != '' && $scDeleteReasonList != '-' ) { 
+                       $deleteReasonList = "<option value=\"other\">$mDeletereasonotherlist</option>";
+                       $optgroup = "";
+                       foreach ( explode( "\n", $scDeleteReasonList ) as $option) {
+                               $value = trim( htmlspecialchars($option) );
+                               if ( $value == '' ) {
+                                       continue;
+                               } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) {
+                                       // A new group is starting ...
+                                       $value = trim( substr( $value, 1 ) );
+                                       $deleteReasonList .= "$optgroup<optgroup label=\"$value\">";
+                                       $optgroup = "</optgroup>";
+                               } elseif ( substr( $value, 0, 2) == '**' ) {
+                                       // groupmember
+                                       $selected = "";
+                                       $value = trim( substr( $value, 2 ) );
+                                       if ( $this->DeleteReasonList === $value)
+                                               $selected = ' selected="selected"';
+                                       $deleteReasonList .= "<option value=\"$value\"$selected>$value</option>";
+                               } else {
+                                       // groupless delete reason
+                                       $selected = "";
+                                       if ( $this->DeleteReasonList === $value)
+                                               $selected = ' selected="selected"';
+                                       $deleteReasonList .= "$optgroup<option value=\"$value\"$selected>$value</option>";
+                                       $optgroup = "";
+                               }
+                       }
+                       $deleteReasonList .= $optgroup;
+               }
                $wgOut->addHTML( "
 <form id='deleteconfirm' method='post' action=\"{$formaction}\">
        <table border='0'>
-               <tr>
+               <tr id=\"wpDeleteReasonListRow\" name=\"wpDeleteReasonListRow\">
                        <td align='right'>
-                               <label for='wpReason'>{$delcom}:</label>
+                               $delcom:
+                       </td>
+                       <td align='left'>
+                               <select tabindex='2' id='wpDeleteReasonList' name=\"wpDeleteReasonList\">
+                                       $deleteReasonList
+                               </select>
+                       </td>
+               </tr>
+               <tr id=\"wpDeleteReasonRow\" name=\"wpDeleteReasonRow\">
+                       <td>
+                               $mDeletereasonother
                        </td>
                        <td align='left'>
                                <input type='text' maxlength='255' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" tabindex=\"1\" />
@@ -2243,6 +2301,10 @@ class Article {
                if( !$wgUser->matchEditToken( $token, array( $this->mTitle->getPrefixedText(), $fromP ) ) )
                        return self::BAD_TOKEN;
 
+               if ( $wgUser->pingLimiter('rollback') || $wgUser->pingLimiter() ) {
+                       return self::RATE_LIMITED;
+               }
+
                $dbw = wfGetDB( DB_MASTER );
 
                # Get the last editor
@@ -2277,7 +2339,7 @@ class Article {
                }
        
                $set = array();
-               if ( $bot ) {
+               if ( $bot && $wgUser->isAllowed('markbotedits') ) {
                        # Mark all reverted edits as bot
                        $set['rc_bot'] = 1;
                }
@@ -2379,6 +2441,9 @@ class Article {
                                $wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
                                $wgOut->addHtml( wfMsg( 'cantrollback' ) );
                                break;
+                       case self::RATE_LIMITED:
+                               $wgOut->rateLimited();
+                               break;
                        case self::SUCCESS:
                                $current = $details['current'];
                                $target = $details['target'];
@@ -2435,6 +2500,7 @@ class Article {
                $edit->pst = $this->preSaveTransform( $text );
                $options = new ParserOptions;
                $options->setTidy( true );
+               $options->enableLimitReport();
                $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true, $revid );
                $edit->oldText = $this->getContent();
                $this->mPreparedEdit = $edit;
@@ -3085,9 +3151,11 @@ class Article {
 
                $popts = $wgOut->parserOptions();
                $popts->setTidy(true);
+               $popts->enableLimitReport();
                $parserOutput = $wgParser->parse( $text, $this->mTitle,
                        $popts, true, true, $this->getRevIdFetched() );
                $popts->setTidy(false);
+               $popts->enableLimitReport( false );
                if ( $cache && $this && $parserOutput->getCacheTime() != -1 ) {
                        $parserCache =& ParserCache::singleton();
                        $parserCache->save( $parserOutput, $this, $wgUser );