r73891 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73890‎ | r73891 | r73892 >
Date:14:43, 28 September 2010
Author:thomasv
Status:ok (Comments)
Tags:
Comment:
instead of defining a custom category, use disambiguation pages.
Modified paths:
  • /trunk/extensions/ProofreadPage/SpecialPagesWithoutScans.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/SpecialPagesWithoutScans.php
@@ -42,7 +42,6 @@
4343 function __construct() {
4444 wfLoadExtensionMessages( 'ProofreadPage' );
4545 $this->page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
46 - $this->cat = wfMsgForContent( 'proofreadpage_notnaked_category' );
4746 }
4847
4948 function getName() {
@@ -57,24 +56,69 @@
5857 return false;
5958 }
6059
 60+ /*
 61+ * return a clause with the list of disambiguation templates.
 62+ * this function was copied verbatim from specials/SpecialDisambiguations.php
 63+ */
 64+ function disambiguation_templates( $dbr ) {
 65+ $dMsgText = wfMsgForContent('disambiguationspage');
 66+
 67+ $linkBatch = new LinkBatch;
 68+
 69+ # If the text can be treated as a title, use it verbatim.
 70+ # Otherwise, pull the titles from the links table
 71+ $dp = Title::newFromText($dMsgText);
 72+ if( $dp ) {
 73+ if($dp->getNamespace() != NS_TEMPLATE) {
 74+ # FIXME we assume the disambiguation message is a template but
 75+ # the page can potentially be from another namespace :/
 76+ wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
 77+ }
 78+ $linkBatch->addObj( $dp );
 79+ } else {
 80+ # Get all the templates linked from the Mediawiki:Disambiguationspage
 81+ $disPageObj = Title::makeTitleSafe( NS_MEDIAWIKI, 'disambiguationspage' );
 82+ $res = $dbr->select(
 83+ array('pagelinks', 'page'),
 84+ 'pl_title',
 85+ array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE,
 86+ 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()),
 87+ __METHOD__ );
 88+
 89+ while ( $row = $dbr->fetchObject( $res ) ) {
 90+ $linkBatch->addObj( Title::makeTitle( NS_TEMPLATE, $row->pl_title ));
 91+ }
 92+
 93+ $dbr->freeResult( $res );
 94+ }
 95+ return $linkBatch->constructSet( 'tl', $dbr );
 96+ }
 97+
6198 function getSQL() {
6299 global $wgContentNamespaces;
63100
64101 $dbr = wfGetDB( DB_SLAVE );
65102 $page = $dbr->tableName( 'page' );
66103 $templatelinks = $dbr->tableName( 'templatelinks' );
67 - $categorylinks = $dbr->tableName( 'categorylinks' );
68104 $forceindex = $dbr->useIndexClause( 'page_len' );
69105 $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $this->page_namespace ) );
70 - $cat = $dbr->strencode( str_replace( ' ' , '_' , $this->cat ) );
71 - $clause = "page_namespace=" . NS_MAIN . " AND page_is_redirect=0 AND page_id NOT IN ( SELECT DISTINCT tl_from FROM $templatelinks LEFT JOIN $page ON page_id=tl_from WHERE tl_namespace=$page_ns_index AND page_namespace=" . NS_MAIN . " ) AND page_id NOT IN ( SELECT DISTINCT cl_from FROM $categorylinks WHERE cl_to='$cat' )";
72106
73 - return
74 - "SELECT page_namespace as namespace,
75 - page_title as title,
76 - page_len AS value
 107+ /* SQL clause to exclude pages with scans */
 108+ $pages_with_scans = "( SELECT DISTINCT tl_from FROM $templatelinks LEFT JOIN $page ON page_id=tl_from WHERE tl_namespace=$page_ns_index AND page_namespace=" . NS_MAIN . " ) ";
 109+
 110+ /* Exclude disambiguation pages too */
 111+ $dt = $this->disambiguation_templates( $dbr );
 112+ $disambiguation_pages = "( SELECT page_id FROM $page LEFT JOIN $templatelinks ON page_id=tl_from WHERE page_namespace=" . NS_MAIN . " AND " . $dt . " )";
 113+
 114+ $sql = "SELECT page_namespace as namespace,
 115+ page_title as title,
 116+ page_len AS value
77117 FROM $page $forceindex
78 - WHERE $clause";
 118+ WHERE page_namespace=" . NS_MAIN . " AND page_is_redirect=0
 119+ AND page_id NOT IN $pages_with_scans
 120+ AND page_id NOT IN $disambiguation_pages";
 121+
 122+ return $sql;
79123 }
80124
81125 function sortDescending() {

Comments

#Comment by 😂 (talk | contribs)   01:48, 8 February 2011

Have I mentioned I really don't like subquries? *shudder*

Should be ok for now, all the wikisources are running at least 5.1. However, the overall design here should really be looked at eventually.

#Comment by Reedy (talk | contribs)   01:49, 8 February 2011

Yay, raw SQL :(

Status & tagging log