Add support for Number grouping(commafy) based on CLDR number grouping patterns like...
[lhc/web/wiklou.git] / includes / Article.php
index db7faac..a91ad26 100644 (file)
@@ -23,7 +23,7 @@ class Article extends Page {
         */
 
        /**
-        * @var RequestContext
+        * @var IContextSource
         */
        protected $mContext;
 
@@ -88,10 +88,10 @@ class Article extends Page {
         * Create an Article object of the appropriate class for the given page.
         *
         * @param $title Title
-        * @param $context RequestContext
+        * @param $context IContextSource
         * @return Article object
         */
-       public static function newFromTitle( $title, RequestContext $context ) {
+       public static function newFromTitle( $title, IContextSource $context ) {
                if ( NS_MEDIA == $title->getNamespace() ) {
                        // FIXME: where should this go?
                        $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
@@ -510,6 +510,9 @@ class Article extends Page {
                                                wfDebug( __METHOD__ . ": showing CSS/JS source\n" );
                                                $this->showCssOrJsPage();
                                                $outputDone = true;
+                                       } elseif( !wfRunHooks( 'ArticleViewCustom', array( $this->mContent, $this->getTitle(), $wgOut ) ) ) {
+                                               # Allow extensions do their own custom view for certain pages
+                                               $outputDone = true;
                                        } else {
                                                $rt = Title::newFromRedirectArray( $text );
                                                if ( $rt ) {
@@ -558,7 +561,7 @@ class Article extends Page {
                # tents of 'pagetitle-view-mainpage' instead of the default (if
                # that's not empty).
                # This message always exists because it is in the i18n files
-               if ( $this->getTitle()->equals( Title::newMainPage() ) ) {
+               if ( $this->getTitle()->isMainPage() ) {
                        $msg = wfMessage( 'pagetitle-view-mainpage' )->inContentLanguage();
                        if ( !$msg->isDisabled() ) {
                                $wgOut->setHTMLTitle( $msg->title( $this->getTitle() )->text() );
@@ -1047,13 +1050,14 @@ class Article extends Page {
         * @return string containing HMTL with redirect link
         */
        public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
-               global $wgOut, $wgLang, $wgStylePath;
+               global $wgOut, $wgStylePath;
 
                if ( !is_array( $target ) ) {
                        $target = array( $target );
                }
 
-               $imageDir = $wgLang->getDir();
+               $lang = $this->getTitle()->getPageLanguage();
+               $imageDir = $lang->getDir();
 
                if ( $appendSubtitle ) {
                        $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
@@ -1069,7 +1073,7 @@ class Article extends Page {
                }
 
                $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
-               $alt = $wgLang->isRTL() ? '←' : '→';
+               $alt = $lang->isRTL() ? '←' : '→';
                // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
                foreach ( $target as $rt ) {
                        $link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );
@@ -1263,101 +1267,6 @@ class Article extends Page {
                $wgOut->redirect( $this->getTitle()->getFullURL( $query ) . $sectionAnchor );
        }
 
-       /**
-        * Auto-generates a deletion reason
-        *
-        * @param &$hasHistory Boolean: whether the page has a history
-        * @return mixed String containing deletion reason or empty string, or boolean false
-        *    if no revision occurred
-        */
-       public function generateReason( &$hasHistory ) {
-               global $wgContLang;
-
-               $dbw = wfGetDB( DB_MASTER );
-               // Get the last revision
-               $rev = Revision::newFromTitle( $this->getTitle() );
-
-               if ( is_null( $rev ) ) {
-                       return false;
-               }
-
-               // Get the article's contents
-               $contents = $rev->getText();
-               $blank = false;
-
-               // If the page is blank, use the text from the previous revision,
-               // which can only be blank if there's a move/import/protect dummy revision involved
-               if ( $contents == '' ) {
-                       $prev = $rev->getPrevious();
-
-                       if ( $prev )    {
-                               $contents = $prev->getText();
-                               $blank = true;
-                       }
-               }
-
-               // Find out if there was only one contributor
-               // Only scan the last 20 revisions
-               $res = $dbw->select( 'revision', 'rev_user_text',
-                       array( 'rev_page' => $this->mPage->getID(), $dbw->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' ),
-                       __METHOD__,
-                       array( 'LIMIT' => 20 )
-               );
-
-               if ( $res === false ) {
-                       // This page has no revisions, which is very weird
-                       return false;
-               }
-
-               $hasHistory = ( $res->numRows() > 1 );
-               $row = $dbw->fetchObject( $res );
-
-               if ( $row ) { // $row is false if the only contributor is hidden
-                       $onlyAuthor = $row->rev_user_text;
-                       // Try to find a second contributor
-                       foreach ( $res as $row ) {
-                               if ( $row->rev_user_text != $onlyAuthor ) { // Bug 22999
-                                       $onlyAuthor = false;
-                                       break;
-                               }
-                       }
-               } else {
-                       $onlyAuthor = false;
-               }
-
-               // Generate the summary with a '$1' placeholder
-               if ( $blank ) {
-                       // The current revision is blank and the one before is also
-                       // blank. It's just not our lucky day
-                       $reason = wfMsgForContent( 'exbeforeblank', '$1' );
-               } else {
-                       if ( $onlyAuthor ) {
-                               $reason = wfMsgForContent( 'excontentauthor', '$1', $onlyAuthor );
-                       } else {
-                               $reason = wfMsgForContent( 'excontent', '$1' );
-                       }
-               }
-
-               if ( $reason == '-' ) {
-                       // Allow these UI messages to be blanked out cleanly
-                       return '';
-               }
-
-               // Replace newlines with spaces to prevent uglyness
-               $contents = preg_replace( "/[\n\r]/", ' ', $contents );
-               // Calculate the maximum amount of chars to get
-               // Max content length = max comment length - length of the comment (excl. $1)
-               $maxLength = 255 - ( strlen( $reason ) - 2 );
-               $contents = $wgContLang->truncate( $contents, $maxLength );
-               // Remove possible unfinished links
-               $contents = preg_replace( '/\[\[([^\]]*)\]?$/', '$1', $contents );
-               // Now replace the '$1' placeholder
-               $reason = str_replace( '$1', $contents, $reason );
-
-               return $reason;
-       }
-
-
        /**
         * UI entry point for page deletion
         */
@@ -1887,13 +1796,15 @@ class Article extends Page {
                } else {
                        $rev = Revision::newFromTitle( $this->getTitle(), $oldid );
                        if ( $rev === null ) {
+                               wfProfileOut( __METHOD__ );
                                return false;
                        }
                        $text = $rev->getText();
                }
 
+               $output = $this->getOutputFromWikitext( $text, $useParserCache );
                wfProfileOut( __METHOD__ );
-               return $this->getOutputFromWikitext( $text, $useParserCache );
+               return $output;
        }
 
        /**
@@ -1946,7 +1857,7 @@ class Article extends Page {
        /**
         * Sets the context this Article is executed in
         *
-        * @param $context RequestContext
+        * @param $context IContextSource
         * @since 1.18
         */
        public function setContext( $context ) {
@@ -1956,11 +1867,11 @@ class Article extends Page {
        /**
         * Gets the context this Article is executed in
         *
-        * @return RequestContext
+        * @return IContextSource
         * @since 1.18
         */
        public function getContext() {
-               if ( $this->mContext instanceof RequestContext ) {
+               if ( $this->mContext instanceof IContextSource ) {
                        return $this->mContext;
                } else {
                        wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
@@ -1979,7 +1890,7 @@ class Article extends Page {
                        #wfWarn( "Access to raw $fname field " . __CLASS__ );
                        return $this->mPage->$fname;
                }
-        trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
+               trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
        }
 
        /**
@@ -1988,7 +1899,6 @@ class Article extends Page {
         *
         * @param $fname String Field name
         * @param $fvalue mixed New value
-        * @param $args Array Arguments to the method
         */
        public function __set( $fname, $fvalue ) {
                if ( property_exists( $this->mPage, $fname ) ) {
@@ -1998,7 +1908,7 @@ class Article extends Page {
                } elseif ( !in_array( $fname, array( 'mContext', 'mPage' ) ) ) {
                        $this->mPage->$fname = $fvalue;
                } else {
-                       trigger_error( 'Inaccessible property via __get(): ' . $fname, E_USER_NOTICE );
+                       trigger_error( 'Inaccessible property via __set(): ' . $fname, E_USER_NOTICE );
                }
        }
 
@@ -2014,7 +1924,7 @@ class Article extends Page {
                        #wfWarn( "Call to " . __CLASS__ . "::$fname; please use WikiPage instead" );
                        return call_user_func_array( array( $this->mPage, $fname ), $args );
                }
-        trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR );
+               trigger_error( 'Inaccessible function via __call(): ' . $fname, E_USER_ERROR );
        }
 
        // ****** B/C functions to work-around PHP silliness with __call and references ****** //
@@ -2038,6 +1948,10 @@ class Article extends Page {
                return $this->mPage->commitRollback( $fromP, $summary, $bot, $resultDetails, $guser );
        }
 
+       public function generateReason( &$hasHistory ) {
+               return $this->mPage->getAutoDeleteReason( $hasHistory );
+       }
+
        // ****** B/C functions for static methods ( __callStatic is PHP>=5.3 ) ****** //
        public static function selectFields() {
                return WikiPage::selectFields();
@@ -2101,7 +2015,7 @@ class PoolWorkArticleView extends PoolCounterWork {
        }
 
        /**
-        * @param  $status Status
+        * @param $status Status
         */
        function error( $status ) {
                global $wgOut;