r73338 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73337‎ | r73338 | r73339 >
Date:19:08, 19 September 2010
Author:thomasv
Status:resolved (Comments)
Tags:brion 
Comment:
special page to list texts without scans
Modified paths:
  • /trunk/extensions/ProofreadPage/ProofreadPage.i18n.php (modified) (history)
  • /trunk/extensions/ProofreadPage/ProofreadPage.php (modified) (history)
  • /trunk/extensions/ProofreadPage/SpecialNakedPages.php (added) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/ProofreadPage.i18n.php
@@ -10,6 +10,7 @@
1111
1212 $messages['en'] = array(
1313 'indexpages' => 'List of index pages',
 14+ 'nakedpages' => 'Naked pages',
1415 'proofreadpage_desc' => 'Allow easy comparison of text to the original scan',
1516 'proofreadpage_namespace' => 'Page',
1617 'proofreadpage_index_namespace' => 'Index',
Index: trunk/extensions/ProofreadPage/SpecialNakedPages.php
@@ -0,0 +1,110 @@
 2+<?php
 3+/**
 4+ *
 5+ * This program is free software; you can redistribute it and/or modify
 6+ * it under the terms of the GNU General Public License as published by
 7+ * the Free Software Foundation; either version 2 of the License, or
 8+ * (at your option) any later version.
 9+ *
 10+ * This program is distributed in the hope that it will be useful,
 11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 13+ * GNU General Public License for more details.
 14+ *
 15+ * You should have received a copy of the GNU General Public License along
 16+ * with this program; if not, write to the Free Software Foundation, Inc.,
 17+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 18+ * http://www.gnu.org/copyleft/gpl.html
 19+ */
 20+
 21+ /*
 22+ * Special page that lists the texts that have no transclusions
 23+ * Pages in MediaWiki:Proofreadpage_notnaked_category are excluded.
 24+ *
 25+ */
 26+
 27+class NakedPages extends SpecialPage {
 28+
 29+ function __construct() {
 30+ parent::__construct( 'NakedPages' );
 31+ }
 32+
 33+ function execute( $parameters ) {
 34+ global $wgOut, $wgRequest, $wgDisableTextSearch;
 35+ $this->setHeaders();
 36+ list( $limit, $offset ) = wfCheckLimits();
 37+ $cnl = new NakedPagesQuery( );
 38+ $cnl->doQuery( $offset, $limit );
 39+ }
 40+}
 41+
 42+
 43+class NakedPagesQuery extends QueryPage {
 44+
 45+ function __construct( ) {
 46+ wfLoadExtensionMessages( 'ProofreadPage' );
 47+ $this->page_namespace = preg_quote( wfMsgForContent( 'proofreadpage_namespace' ), '/' );
 48+ $this->cat = wfMsgForContent( 'proofreadpage_notnaked_category' );
 49+ }
 50+
 51+ function getName() {
 52+ return 'NakedPages';
 53+ }
 54+
 55+ function isExpensive() {
 56+ return true;
 57+ }
 58+
 59+ function isSyndicated() {
 60+ return false;
 61+ }
 62+
 63+ function getSQL() {
 64+ global $wgContentNamespaces;
 65+
 66+ $dbr = wfGetDB( DB_SLAVE );
 67+ $page = $dbr->tableName( 'page' );
 68+ $templatelinks = $dbr->tableName( 'templatelinks' );
 69+ $categorylinks = $dbr->tableName( 'categorylinks' );
 70+ $forceindex = $dbr->useIndexClause("page_len");
 71+ $page_ns_index = MWNamespace::getCanonicalIndex( strtolower( $this->page_namespace ) );
 72+ $cat = $dbr->strencode( str_replace( ' ' , '_' , $this->cat ) );
 73+ $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' )";
 74+
 75+ return
 76+ "SELECT page_namespace as namespace,
 77+ page_title as title,
 78+ page_len AS value
 79+ FROM $page $forceindex
 80+ WHERE $clause";
 81+ }
 82+
 83+ function sortDescending() {
 84+ return true;
 85+ }
 86+
 87+ function formatResult( $skin, $result ) {
 88+ global $wgLang, $wgContLang;
 89+ $dm = $wgContLang->getDirMark();
 90+
 91+ $title = Title::makeTitleSafe( $result->namespace, $result->title );
 92+ if ( !$title ) {
 93+ return '<!-- Invalid title ' . htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
 94+ }
 95+ $hlink = $skin->linkKnown(
 96+ $title,
 97+ wfMsgHtml( 'hist' ),
 98+ array(),
 99+ array( 'action' => 'history' )
 100+ );
 101+ $plink = $this->isCached()
 102+ ? $skin->link( $title )
 103+ : $skin->linkKnown( $title );
 104+ $size = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->value ) ) );
 105+
 106+ return $title->exists()
 107+ ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
 108+ : "<s>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</s>";
 109+ }
 110+}
 111+
Index: trunk/extensions/ProofreadPage/ProofreadPage.php
@@ -43,6 +43,11 @@
4444 $wgSpecialPages['IndexPages'] = 'ProofreadPages';
4545 $wgSpecialPageGroups['IndexPages'] = 'pages';
4646
 47+# special page
 48+$wgAutoloadClasses['NakedPages'] = dirname( __FILE__ ) . '/SpecialNakedPages.php';
 49+$wgSpecialPages['NakedPages'] = 'NakedPages';
 50+$wgSpecialPageGroups['NakedPages'] = 'maintenance';
 51+
4752 # Bump the version number every time you change proofread.js
4853 $wgProofreadPageVersion = 27;
4954

Follow-up revisions

RevisionCommit summaryAuthorDate
r73368renaming special page, follow-up to r73338thomasv09:34, 20 September 2010
r73369renaming special page, follow-up to r73338thomasv09:36, 20 September 2010

Comments

#Comment by Nikerabbit (talk | contribs)   20:05, 19 September 2010
+$size = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->value ) ) );

$result->value is escaped twice.

#Comment by Nikerabbit (talk | contribs)   20:07, 19 September 2010

I'm not sure where the special page title comes, the meaning doesn't open to me, and probably not for all translators either.

#Comment by Siebrand (talk | contribs)   22:20, 19 September 2010

Just came here to say the same as Niklas. Please choose a more descriptive and less ambiguous special page name.

#Comment by ThomasV (talk | contribs)   08:47, 20 September 2010

Indeed, this was Wikisourcer slang. Message updated in r73366.

#Comment by Siebrand (talk | contribs)   08:57, 20 September 2010

Maybe also update the special page name? That's still Special:NakedPages.

Tip: If you put 'rxxxxx' in your commit message, it will be linked to the given revision here in Code Review.

#Comment by ThomasV (talk | contribs)   09:40, 20 September 2010

@Nikerabbit : $result->value's double escaping was copied from specials/SpecialShortPages.php. Is it wrong to do so ?

#Comment by Nikerabbit (talk | contribs)   12:51, 20 September 2010

In this case there is no effect, but generally it's a bad thing to escape twice because the output can become garbled.

#Comment by 😂 (talk | contribs)   13:05, 20 September 2010

The following:

+		global $wgOut, $wgRequest, $wgDisableTextSearch;
+		global $wgContentNamespaces;

Don't seem to be used.

Also, this WHERE clause:

+		$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' )";

The two subqueries make me feel icky. This extension gets used on WMF sites, and I know Domas doesn't like some of the new 5.x features in MySQL :)

#Comment by ThomasV (talk | contribs)   06:41, 28 September 2010

Is there a way to do this without subqueries ? ( btw, I think subqueries are a 4.1 feature.)

#Comment by Catrope (talk | contribs)   18:20, 23 October 2010

Yes, but part of the cluster still runs 4.0.40

#Comment by ThomasV (talk | contribs)   09:27, 8 November 2010

in that case I do not see how to do it ; my sql knowledge is not sufficient. if there is no other way, feel free to revert this commit

#Comment by MarkAHershberger (talk | contribs)   18:54, 1 February 2011

when you fix a FIXME, please change it back to "NEW"

#Comment by Brion VIBBER (talk | contribs)   02:55, 4 February 2011

The subqueries are ugly, but the query that it's trying to do is just plain awful and I don't think there's a better way to do it other than reconceiving it entirely. :)

Live servers seem to be MySQL 5.1, and ProofreadPage is only used on relatively smaller wikis. I don't think this should be a particular problem or holdup at this time. I'm going to go ahead and mark this as RESOLVED for the immediate problems listed above that things have been variously cleaned up; if there are still 4.0s hiding in the slave servers or something, then we can disable the special page.

[Note that all sorts of awful little bugs with general breakage may still remain in this extension, but they shouldn't be considered release blockers. That ain't new and they can be fixed piecemeal. :)]

Status & tagging log