Page MenuHomePhabricator

[DPLforum]: Fixup raw SQL building
Open, LowPublic

Description

The SQL query building is very scary

		// build the SQL query
		$dbr = wfGetDB( DB_SLAVE );
		$sPageTable = $dbr->tableName( 'page' );
		$sRevTable = $dbr->tableName( 'revision' );
		$categorylinks = $dbr->tableName( 'categorylinks' );
		$sSqlSelectFrom = "SELECT page_namespace, page_title,"
			. " r.rev_user_text, r.rev_timestamp";
		$arg = " FROM $sPageTable INNER JOIN $sRevTable"
			. " AS r ON page_latest = r.rev_id";

		if ( $bCountMode ) {
			$sSqlSelectFrom = "SELECT COUNT(*) AS num_rows FROM $sPageTable";
		} elseif ( ( $this->bAddAuthor || $this->bAddCreationDate ||
		( $sOrder == 'first_time' ) ) && ( ( !$this->restrictNamespace ) ||
		( $iNamespace >= 0 && !in_array( $iNamespace, $this->restrictNamespace ) ) ) ) {
			$sSqlSelectFrom .= ", o.rev_user_text AS first_user, o.rev_timestamp AS"
			. " first_time" . $arg . " INNER JOIN $sRevTable AS o"
			. " ON o.rev_id =( SELECT MIN(q.rev_id) FROM $sRevTable"
			. " AS q WHERE q.rev_page = page_id )";
		} else {
			if ( $sOrder == 'first_time' ) {
				$sOrder = 'page_id';
			}
			$sSqlSelectFrom .= $arg;
		}

		$sSqlWhere = ' WHERE 1=1';
		if ( $iNamespace >= 0 ) {
			$sSqlWhere = ' WHERE page_namespace=' . $iNamespace;
		}

		if ( $sPrefix !== '' ) {
			// Escape SQL special characters
			$sPrefix = strtr( $sPrefix, array( '\\' => '\\\\\\\\',
			' ' => '\\_', '_' => '\\_', '%' => '\\%', '\'' => '\\\'' ) );
			$sSqlWhere .= " AND page_title LIKE BINARY '" . $sPrefix . "%'";
		}

		switch( $this->get( 'redirects' ) ) {
			case 'only':
				$sSqlWhere .= ' AND page_is_redirect = 1';
			case 'include':
				break;
			case 'exclude':
			default:
				$sSqlWhere .= ' AND page_is_redirect = 0';
			break;
		}

		$n = 1;
		for ( $i = 0; $i < $cats; $i++ ) {
			$sSqlSelectFrom .= " INNER JOIN $categorylinks AS" .
			" c{$n} ON page_id = c{$n}.cl_from AND c{$n}.cl_to=" .
			$dbr->addQuotes( $aCategories[$i]->getDBkey() );
			$n++;
		}
		for ( $i = 0; $i < $nocats; $i++ ) {
			$sSqlSelectFrom .= " LEFT OUTER JOIN $categorylinks AS" .
			" c{$n} ON page_id = c{$n}.cl_from AND c{$n}.cl_to=" .
			$dbr->addQuotes( $aExcludeCategories[$i]->getDBkey() );
			$sSqlWhere .= " AND c{$n}.cl_to IS NULL";
			$n++;
		}

		if ( !$bCountMode ) {
			$sSqlWhere .= " ORDER BY $sOrder ";

			if ( $this->get( 'order' ) == 'ascending' ) {
				$sSqlWhere .= 'ASC';
			} else {
				$sSqlWhere .= 'DESC';
			}
		}
		$sSqlWhere .= " LIMIT $start, $count";

Version: unspecified
Severity: normal

Details

Reference
bz44610

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:30 AM
bzimport set Reference to bz44610.
bzimport added a subscriber: Unknown Object (MLST).
Reedy created this task.Feb 3 2013, 1:06 AM

Wikia has a newer set of central forums that are also based on individual threads that can be watchlisted. I don't know if it is based on a fork of DplForum or not. It may have better software.

The 2 sets of Wikia central forums:
*[[wikia:community:Admin Central:Forum]] - based on DplForum.
*[[wikia:community:Special:Forum]] - newer forums.

The newer forums may be based on "Forum" listed here:
*[[wikia:community:Special:Version]]

It lists its editors as "Hyun Lim, Kyle Florence, Saipetch Kongkatong and Tomasz Odrobny".

The newer forums can be sorted by most recent reply, or by most replies. It is probably possible to adapt it to allow sorting by thread start date too.

Krinkle set Security to None.
Krinkle removed a subscriber: Unknown Object (MLST).
Liuxinyu970226 renamed this task from DplForum: Fixup raw SQL building to [DPLforum]: Fixup raw SQL building.Feb 19 2019, 10:36 AM
Liuxinyu970226 added a subscriber: Liuxinyu970226.

Five months ago, I asked him to register a Phab account to focus this, and others, then no reply. Maybe archive extension can be considered?

Maybe archive extension can be considered?

I have conflicting feelings about this; on the one hand, the extension hasn't received significant updates for some time (its repository documentation still lists the latest release as 3.4, even though the current version is 3.6.1!) and the author hasn't edited on MW.org for almost a decade; on the other, though, my primary wiki uses this extension and there's no obvious migration path to replace this extension with some other system (I have no idea if the base DPL extension has the functionality needed to be a drop-in replacement).