PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/extensions/ReaderFeedback/specialpages/RatedPages_body.php

https://github.com/ChuguluGames/mediawiki-svn
PHP | 169 lines | 145 code | 15 blank | 9 comment | 17 complexity | f3d1698cb1a998770a32063ebf67e23c MD5 | raw file
  1. <?php
  2. if ( !defined( 'MEDIAWIKI' ) ) {
  3. echo "ReaderFeedback extension\n";
  4. exit( 1 );
  5. }
  6. class RatedPages extends SpecialPage
  7. {
  8. public function __construct() {
  9. parent::__construct( 'RatedPages' );
  10. }
  11. public function execute( $par ) {
  12. global $wgRequest, $wgOut, $wgUser;
  13. $this->setHeaders();
  14. if( $wgUser->isAllowed( 'feedback' ) ) {
  15. if( $wgUser->isBlocked() ) {
  16. $wgOut->blockedPage();
  17. return;
  18. }
  19. } else {
  20. $wgOut->permissionRequired( 'feedback' );
  21. return;
  22. }
  23. if( wfReadOnly() ) {
  24. $wgOut->readOnlyPage();
  25. return;
  26. }
  27. // Purge expired entries on one in every 10 queries
  28. if( 0 == mt_rand( 0, 10 ) ) {
  29. ReaderFeedback::purgeExpiredAverages();
  30. }
  31. $this->skin = $wgUser->getSkin();
  32. # Check if there is a featured level
  33. $this->namespace = $wgRequest->getInt( 'namespace' );
  34. $this->tag = $wgRequest->getVal( 'ratingtag' );
  35. $this->tier = $wgRequest->getInt( 'ratingtier' );
  36. $this->showForm();
  37. $this->showPageList();
  38. }
  39. protected function showForm() {
  40. global $wgOut, $wgScript, $wgFeedbackNamespaces;
  41. $form = Xml::openElement( 'form',
  42. array( 'name' => 'reviewedpages', 'action' => $wgScript, 'method' => 'get' ) );
  43. $form .= Xml::fieldset( wfMsg( 'ratedpages-leg' ) );
  44. $form .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBKey() );
  45. $form .= ReaderFeedbackXML::getRatingTierMenu($this->tier) . '&#160;';
  46. if( count($wgFeedbackNamespaces) > 1 ) {
  47. $form .= ReaderFeedbackXML::getNamespaceMenu( $this->namespace ) . '&#160;';
  48. }
  49. if( count( ReaderFeedback::getFeedbackTags() ) > 0 ) {
  50. $form .= ReaderFeedbackXML::getTagMenu( $this->tag );
  51. }
  52. $form .= " " . Xml::submitButton( wfMsg( 'go' ) ) .
  53. Xml::closeElement( 'fieldset' ) .
  54. Xml::closeElement( 'form' ) . "\n";
  55. $wgOut->addHTML( $form );
  56. }
  57. protected function showPageList() {
  58. global $wgOut;
  59. $tags = ReaderFeedback::getFeedbackTags();
  60. $pager = new RatedPagesPager( $this, array(), $this->namespace, $this->tag, $this->tier );
  61. if( isset($tags[$this->tag]) && $pager->getNumRows() ) {
  62. $wgOut->addHTML( wfMsgExt('ratedpages-list', array('parse') ) );
  63. $wgOut->addHTML( $pager->getNavigationBar() );
  64. $wgOut->addHTML( $pager->getBody() );
  65. $wgOut->addHTML( $pager->getNavigationBar() );
  66. } elseif( $this->tag ) { // must select first...
  67. $wgOut->addHTML( wfMsgExt('ratedpages-none', array('parse') ) );
  68. }
  69. }
  70. public function formatRow( $row ) {
  71. global $wgLang;
  72. $title = Title::makeTitle( $row->page_namespace, $row->page_title );
  73. $link = $this->skin->makeKnownLinkObj( $title, $title->getPrefixedText() );
  74. $hist = $this->skin->makeKnownLinkObj( $title, wfMsgHtml('hist'), 'action=history' );
  75. $stxt = '';
  76. if( !is_null($size = $row->page_len) ) {
  77. if( $size == 0 )
  78. $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>';
  79. else
  80. $stxt = ' <small>' . wfMsgExt('historysize', array('parsemag'),
  81. $wgLang->formatNum( $size ) ) . '</small>';
  82. }
  83. $ratinghist = SpecialPage::getTitleFor( 'RatingHistory' );
  84. $graph = $this->skin->makeKnownLinkObj( $ratinghist, wfMsgHtml('ratedpages-graphs'),
  85. 'target='.$title->getPrefixedUrl().'&period=93' );
  86. $count = wfMsgExt( 'ratedpages-count', array( 'parsemag', 'escape' ), $wgLang->formatNum( $row->rfp_count ) );
  87. return "<li>$link $stxt ($hist) ($graph) ($count)</li>";
  88. }
  89. }
  90. /**
  91. * Query to list out well recieved pages
  92. */
  93. class RatedPagesPager extends AlphabeticPager {
  94. public $mForm, $mConds, $namespace, $tag;
  95. function __construct( $form, $conds = array(), $namespace=0, $tag, $tier ) {
  96. $this->mForm = $form;
  97. $this->mConds = $conds;
  98. # Must be a content page...
  99. global $wgFeedbackNamespaces;
  100. if( !is_null($namespace) ) {
  101. $namespace = intval($namespace);
  102. }
  103. if( is_null($namespace) || !in_array($namespace,$wgFeedbackNamespaces) ) {
  104. $namespace = empty($wgFeedbackNamespaces) ? -1 : $wgFeedbackNamespaces[0];
  105. }
  106. $this->namespace = $namespace;
  107. $this->tag = $tag;
  108. $this->tier = (int)$tier;
  109. parent::__construct();
  110. }
  111. function formatRow( $row ) {
  112. return $this->mForm->formatRow( $row );
  113. }
  114. function getQueryInfo() {
  115. $conds = $this->mConds;
  116. $conds[] = 'rfp_page_id = page_id';
  117. $conds['rfp_tag'] = $this->tag;
  118. $conds['page_namespace'] = $this->namespace;
  119. // Has to be good/crappy enough
  120. switch( $this->tier ) {
  121. case 3: $conds[] = "rfp_ave_val > 3"; break;
  122. case 1: $conds[] = "rfp_ave_val < 2"; break;
  123. default: $conds[] = "rfp_ave_val >= 2 AND rfp_ave_val <= 3"; break;
  124. }
  125. // Reasonable samples only
  126. $conds[] = 'rfp_count >= '.$this->mDb->addQuotes( ReaderFeedback::getFeedbackSize() );
  127. return array(
  128. 'tables' => array('reader_feedback_pages','page'),
  129. 'fields' => 'page_namespace,page_title,page_len,rfp_ave_val,rfp_count',
  130. 'conds' => $conds,
  131. 'options' => array( 'USE INDEX' => array('reader_feedback_pages' => 'rfp_tag_val_page') )
  132. );
  133. }
  134. function getDefaultDirections() {
  135. return false;
  136. }
  137. function getIndexField() {
  138. return 'rfp_ave_val';
  139. }
  140. function getStartBody() {
  141. wfProfileIn( __METHOD__ );
  142. # Do a link batch query...
  143. $lb = new LinkBatch();
  144. foreach ( $this->mResult as $row ) {
  145. $lb->add( $row->page_namespace, $row->page_title );
  146. }
  147. $lb->execute();
  148. wfProfileOut( __METHOD__ );
  149. return '<ul>';
  150. }
  151. function getEndBody() {
  152. return '</ul>';
  153. }
  154. }