Cleanup
[lhc/web/wiklou.git] / includes / Article.php
index ce3e402..68e561a 100644 (file)
@@ -41,7 +41,7 @@ class Article {
         * @param $title Reference to a Title object.
         * @param $oldId Integer revision ID, null to fetch from request, zero for current
         */
-       function __construct( &$title, $oldId = null ) {
+       function __construct( Title $title, $oldId = null ) {
                $this->mTitle =& $title;
                $this->mOldId = $oldId;
                $this->clear();
@@ -613,6 +613,7 @@ class Article {
                global $wgUser, $wgOut, $wgRequest, $wgContLang;
                global $wgEnableParserCache, $wgStylePath, $wgParser;
                global $wgUseTrackbacks, $wgNamespaceRobotPolicies, $wgArticleRobotPolicies;
+               global $wgDefaultRobotPolicy;
                $sk = $wgUser->getSkin();
 
                wfProfileIn( __METHOD__ );
@@ -647,8 +648,7 @@ class Article {
                        # Honour customised robot policies for this namespace
                        $policy = $wgNamespaceRobotPolicies[$ns];
                } else {
-                       # Default to encourage indexing and following links
-                       $policy = 'index,follow';
+                       $policy = $wgDefaultRobotPolicy;
                }
                $wgOut->setRobotPolicy( $policy );
 
@@ -770,11 +770,11 @@ class Article {
                                        $this->setOldSubtitle( isset($this->mOldId) ? $this->mOldId : $oldid );
                                        if( $this->mRevision->isDeleted( Revision::DELETED_TEXT ) ) {
                                                if( !$this->mRevision->userCan( Revision::DELETED_TEXT ) ) {
-                                                       $wgOut->addWikiText( wfMsg( 'rev-deleted-text-permission' ) );
+                                                       $wgOut->addWikiMsg( 'rev-deleted-text-permission' );
                                                        $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
                                                        return;
                                                } else {
-                                                       $wgOut->addWikiText( wfMsg( 'rev-deleted-text-view' ) );
+                                                       $wgOut->addWikiMsg( 'rev-deleted-text-view' );
                                                        // and we are allowed to see...
                                                }
                                        }
@@ -852,7 +852,7 @@ class Article {
                # check if we're displaying a [[User talk:x.x.x.x]] anonymous talk page
                if( $ns == NS_USER_TALK &&
                        User::isIP( $this->mTitle->getText() ) ) {
-                       $wgOut->addWikiText( wfMsg('anontalkpagetext') );
+                       $wgOut->addWikiMsg('anontalkpagetext');
                }
 
                # If we have been passed an &rcid= parameter, we want to give the user a
@@ -904,14 +904,14 @@ class Article {
                                        $o->tb_name,
                                        $rmvtxt);
                }
-               $wgOut->addWikitext(wfMsg('trackbackbox', $tbtext));
+               $wgOut->addWikiMsg( 'trackbackbox', $tbtext );
        }
 
        function deletetrackback() {
                global $wgUser, $wgRequest, $wgOut, $wgTitle;
 
                if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
-                       $wgOut->addWikitext(wfMsg('sessionfailure'));
+                       $wgOut->addWikiMsg( 'sessionfailure' );
                        return;
                }
 
@@ -926,7 +926,7 @@ class Article {
                $db = wfGetDB(DB_MASTER);
                $db->delete('trackbacks', array('tb_id' => $wgRequest->getInt('tbid')));
                $wgTitle->invalidateCache();
-               $wgOut->addWikiText(wfMsg('trackbackdeleteok'));
+               $wgOut->addWikiMsg('trackbackdeleteok');
        }
 
        function render() {
@@ -978,6 +978,15 @@ class Article {
                        $update = SquidUpdate::newSimplePurge( $this->mTitle );
                        $update->doUpdate();
                }
+               if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
+                       global $wgMessageCache;
+                       if ( $this->getID() == 0 ) {
+                               $text = false;
+                       } else {
+                               $text = $this->getContent();
+                       }
+                       $wgMessageCache->replace( $this->mTitle->getDBkey(), $text );
+               }
                $this->view();
        }
 
@@ -1560,7 +1569,7 @@ class Article {
                                # The user made this edit, and can't patrol it
                                # Tell them so, and then back off
                                $wgOut->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
-                               $wgOut->addWikiText( wfMsgNoTrans( 'markedaspatrollederror-noautopatrol' ) );
+                               $wgOut->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
                                $wgOut->returnToMain( false, $return );
                                return;
                        }
@@ -1573,7 +1582,7 @@ class Article {
 
                # Inform the user
                $wgOut->setPageTitle( wfMsg( 'markedaspatrolled' ) );
-               $wgOut->addWikiText( wfMsgNoTrans( 'markedaspatrolledtext' ) );
+               $wgOut->addWikiMsg( 'markedaspatrolledtext' );
                $wgOut->returnToMain( false, $return );
        }
 
@@ -1598,9 +1607,7 @@ class Article {
                        $wgOut->setPagetitle( wfMsg( 'addedwatch' ) );
                        $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
-                       $link = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
-                       $text = wfMsg( 'addedwatchtext', $link );
-                       $wgOut->addWikiText( $text );
+                       $wgOut->addWikiMsg( 'addedwatchtext', $this->mTitle->getPrefixedText() );
                }
 
                $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
@@ -1645,9 +1652,7 @@ class Article {
                        $wgOut->setPagetitle( wfMsg( 'removedwatch' ) );
                        $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
-                       $link = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
-                       $text = wfMsg( 'removedwatchtext', $link );
-                       $wgOut->addWikiText( $text );
+                       $wgOut->addWikiMsg( 'removedwatchtext', $this->mTitle->getPrefixedText() );
                }
 
                $wgOut->returnToMain( true, $this->mTitle->getPrefixedText() );
@@ -1734,7 +1739,7 @@ class Article {
 
                                $expiry_description = '';
                                if ( $encodedExpiry != 'infinity' ) {
-                                       $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry ) ).')';
+                                       $expiry_description = ' (' . wfMsgForContent( 'protect-expiring', $wgContLang->timeanddate( $expiry, false, false ) ).')';
                                }
 
                                # Prepare a null revision to be added to the history
@@ -1765,7 +1770,7 @@ class Article {
                                        $comment .= "$expiry_description";
                                if ( $cascade )
                                        $comment .= "$cascade_description";
-
+                               
                                # Update restrictions table
                                foreach( $limit as $action => $restrictions ) {
                                        if ($restrictions != '' ) {
@@ -1778,9 +1783,6 @@ class Article {
                                                        'pr_type' => $action ), __METHOD__ );
                                        }
                                }
-                               if($dbw->affectedRows() == 0)
-                                       // No change
-                                       return true;
 
                                # Insert a null revision
                                $nullRevision = Revision::newNullRevision( $dbw, $id, $comment, true );
@@ -1800,6 +1802,8 @@ class Article {
 
                                # Update the protection log
                                $log = new LogPage( 'protect' );
+                               
+                               
 
                                if( $protect ) {
                                        $log->addEntry( $modified ? 'modify' : 'protect', $this->mTitle, trim( $reason . " [$updated]$cascade_description$expiry_description" ) );
@@ -1947,8 +1951,8 @@ class Article {
                        return;
                }
 
-               $wgOut->setPagetitle( wfMsg( 'confirmdelete' ) );
-               
+               $wgOut->setPagetitle( wfMsg( 'delete-confirm', $this->mTitle->getPrefixedText() ) );
+
                # Better double-check that it hasn't been deleted yet!
                $dbw = wfGetDB( DB_MASTER );
                $conds = $this->mTitle->pageCond();
@@ -1962,10 +1966,8 @@ class Article {
                $bigHistory = $this->isBigDeletion();
                if( $bigHistory && !$this->mTitle->userCan( 'bigdelete' ) ) {
                        global $wgLang, $wgDeleteRevisionsLimit;
-                       $wgOut->addWikiText( "<div class='error'>\n" .
-                               wfMsg( 'delete-toobig',
-                                       $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) .
-                               "</div>\n" );
+                       $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>\n",
+                               array( 'delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
                        return;
                }
 
@@ -1989,10 +1991,8 @@ class Article {
                        $wgOut->addHTML( '<strong>' . wfMsg( 'historywarning' ) . ' ' . $skin->historyLink() . '</strong>' );
                        if( $bigHistory ) {
                                global $wgLang, $wgDeleteRevisionsLimit;
-                               $wgOut->addWikiText( "<div class='error'>\n" .
-                                       wfMsg( 'delete-warning-toobig',
-                                               $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) .
-                                       "</div>\n" );
+                               $wgOut->wrapWikiMsg( "<div class='error'>\n$1</div>\n",
+                                       array( 'delete-warning-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
                        }
                }
                
@@ -2071,96 +2071,59 @@ class Article {
 
        /**
         * Output deletion confirmation dialog
+        * @param $par string FIXME: do we need this parameter? One Call from Article::delete with '' only.
+        * @param $reason string Prefilled reason
         */
        function confirmDelete( $par, $reason ) {
-               global $wgOut, $wgUser;
+               global $wgOut, $wgUser, $wgContLang;
+               $align = $wgContLang->isRtl() ? 'left' : 'right';
 
                wfDebug( "Article::confirmDelete\n" );
 
-               $sub = htmlspecialchars( $this->mTitle->getPrefixedText() );
-               $wgOut->setSubtitle( wfMsg( 'deletesub', $sub ) );
+               $wgOut->setSubtitle( wfMsg( 'delete-backlink', $wgUser->getSkin()->makeKnownLinkObj( $this->mTitle ) ) );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
-               $wgOut->addWikiText( wfMsg( 'confirmdeletetext' ) );
-
-               $formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
-
-               $confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
-               $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 id=\"wpDeleteReasonListRow\" name=\"wpDeleteReasonListRow\">
-                       <td align='right'>
-                               $delcom:
-                       </td>
-                       <td align='left'>
-                               <select tabindex='1' 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=\"2\" />
-                       </td>
-               </tr>
-               <tr>
-                       <td>&nbsp;</td>
-                       <td>$watch</td>
-               </tr>
-               <tr>
-                       <td>&nbsp;</td>
-                       <td>
-                               <input type='submit' name='wpConfirmB' id='wpConfirmB' value=\"{$confirm}\" tabindex=\"3\" />
-                       </td>
-               </tr>
-       </table>
-       <input type='hidden' name='wpEditToken' value=\"{$token}\" />
-</form>\n" );
-
-               $wgOut->returnToMain( false, $this->mTitle );
-
+               $wgOut->addWikiMsg( 'confirmdeletetext' );
+
+               $form = Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->mTitle->getLocalURL( 'action=delete' . $par ), 'id' => 'deleteconfirm' ) ) .
+                       Xml::openElement( 'fieldset' ) .
+                       Xml::element( 'legend', array(), wfMsg( 'delete-legend' ) ) .
+                       Xml::openElement( 'table' ) .
+                       "<tr id=\"wpDeleteReasonListRow\">
+                               <td align='$align'>" .
+                                       Xml::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' ) .
+                               "</td>
+                               <td>" .
+                                       Xml::listDropDown( 'wpDeleteReasonList',
+                                               wfMsgForContent( 'deletereason-dropdown' ), 
+                                               wfMsgForContent( 'deletereasonotherlist' ), '', 'wpReasonDropDown', 1 ) .
+                               "</td>
+                       </tr>
+                       <tr id=\"wpDeleteReasonRow\">
+                               <td align='$align'>" .
+                                       Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' ) .
+                               "</td>
+                               <td>" .
+                                       Xml::input( 'wpReason', 60, $reason, array( 'type' => 'text', 'maxlength' => '255', 'tabindex' => '2', 'id' => 'wpReason' ) ) .
+                               "</td>
+                       </tr>
+                       <tr>
+                               <td></td>
+                               <td>" .
+                                       Xml::checkLabel( wfMsg( 'watchthis' ), 'wpWatch', 'wpWatch', $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching(), array( 'tabindex' => '3' ) ) .
+                               "</td>
+                       </tr>
+                       <tr>
+                               <td></td>
+                               <td>" .
+                                       Xml::submitButton( wfMsg( 'deletepage' ), array( 'name' => 'wpConfirmB', 'id' => 'wpConfirmB', 'tabindex' => '4' ) ) .
+                               "</td>
+                       </tr>" .
+                       Xml::closeElement( 'table' ) .
+                       Xml::closeElement( 'fieldset' ) .
+                       Xml::hidden( 'wpEditToken', $wgUser->editToken() ) .
+                       Xml::closeElement( 'form' );
+
+               $wgOut->addHTML( $form );
                $this->showLogExtract( $wgOut );
        }
 
@@ -2188,15 +2151,14 @@ class Article {
 
                if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
                        if ( $this->doDeleteArticle( $reason ) ) {
-                               $deleted = wfEscapeWikiText( $this->mTitle->getPrefixedText() );
+                               $deleted = $this->mTitle->getPrefixedText();
 
                                $wgOut->setPagetitle( wfMsg( 'actioncomplete' ) );
                                $wgOut->setRobotpolicy( 'noindex,nofollow' );
 
-                               $loglink = '[[Special:Log/delete|' . wfMsg( 'deletionlog' ) . ']]';
-                               $text = wfMsg( 'deletedtext', $deleted, $loglink );
+                               $loglink = '[[Special:Log/delete|' . wfMsgNoTrans( 'deletionlog' ) . ']]';
 
-                               $wgOut->addWikiText( $text );
+                               $wgOut->addWikiMsg( 'deletedtext', $deleted, $loglink );
                                $wgOut->returnToMain( false );
                                wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason));
                        } else {
@@ -2953,6 +2915,10 @@ class Article {
                if( $title->getNamespace() == NS_MEDIAWIKI) {
                        $wgMessageCache->replace( $title->getDBkey(), false );
                }
+               if( $title->getNamespace() == NS_IMAGE ) {
+                       $update = new HTMLCacheUpdate( $title, 'imagelinks' );
+                       $update->doUpdate();
+               }
        }
 
        /**
@@ -3105,6 +3071,36 @@ class Article {
                return $result;
        }
 
+       /**
+        * Returns a list of hidden categories this page is a member of.
+        * Uses the page_props and categorylinks tables.
+        *
+        * @return array Array of Title objects
+        */
+       function getHiddenCategories() {
+               $result = array();
+               $id = $this->mTitle->getArticleID();
+               if( $id == 0 ) {
+                       return array();
+               }
+
+               $dbr = wfGetDB( DB_SLAVE );
+               $res = $dbr->select( array( 'categorylinks', 'page_props', 'page' ),
+                       array( 'cl_to' ),
+                       array( 'cl_from' => $id, 'pp_page=page_id', 'pp_propname' => 'hiddencat', 
+                               'page_namespace' => NS_CATEGORY, 'page_title=cl_to'),
+                       'Article:getHiddenCategories' );
+               if ( false !== $res ) {
+                       if ( $dbr->numRows( $res ) ) {
+                               while ( $row = $dbr->fetchObject( $res ) ) {
+                                       $result[] = Title::makeTitle( NS_CATEGORY, $row->cl_to );
+                               }
+                       }
+               }
+               $dbr->freeResult( $res );
+               return $result;
+       }
+
        /**
         * Return an auto-generated summary if the text provided is a redirect.
         *